#!/bin/sh # SPDX-License-Identifier: GPL-2.0 # # probe.sh compiles each src/compat/probes/HAVE_*.c against the kernel build # directory KDIR and writes a header defining the HAVE_* macros whose probes # compiled. It only rewrites the output file when its contents change, so # that unchanged probe results don't force a rebuild. # # usage: probe.sh KDIR OUTPUT_HEADER set -eu if [ $# -ne 2 ]; then echo "usage: $0 KDIR OUTPUT_HEADER" >&2 exit 2 fi kdir=$1 out=$2 top=$(cd "$(dirname "$0")/.." && pwd) probes=$top/src/compat/probes tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT cp "$probes"/HAVE_*.c "$tmp"/ printf 'obj-m :=\nccflags-y := -Werror\n' > "$tmp/Kbuild" # Unset MAKEFLAGS so a parent make's jobserver and flags don't leak into the # per-probe builds. for c in "$tmp"/HAVE_*.c; do basename "$c" .c done | MAKEFLAGS= xargs -P "$(nproc)" -I{} sh -c \ 'make -s -C "$1" M="$2" "$3.o" >"$2/$3.log" 2>&1 || true' \ sh "$kdir" "$tmp" {} { echo "/* Generated by scripts/probe.sh for $kdir. Do not edit. */" for c in "$tmp"/HAVE_*.c; do name=$(basename "$c" .c) if [ -f "$tmp/$name.o" ]; then echo "#define $name 1" else echo "/* #undef $name */" fi done } > "$tmp/autoconf.h" mkdir -p "$(dirname "$out")" if ! cmp -s "$tmp/autoconf.h" "$out"; then cp "$tmp/autoconf.h" "$out" fi