2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright 2014-2015 6WIND S.A.
5 # Crude script to detect whether particular types, macros and functions are
6 # defined by trying to compile a file with a given header. Can be used to
7 # perform cross-platform checks since the resulting object file is not
10 # Set VERBOSE=1 in the environment to display compiler output and errors.
12 # CC, CPPFLAGS, CFLAGS, EXTRA_CPPFLAGS and EXTRA_CFLAGS are taken from the
15 # AUTO_CONFIG_CFLAGS may append additional CFLAGS without modifying the
18 file=${1:?output file name required (config.h)}
19 macro=${2:?output macro name required (HAVE_*)}
20 include=${3:?include name required (foo.h)}
21 type=${4:?object type required (define, enum, type, field, func)}
22 name=${5:?define/type/function name required}
26 temp=$(mktemp -t dpdk.${0##*/}.c.XXXXXX)
32 #error $name not defined
38 long test____ = $name;
50 ${name%%.*} test_____;
52 (void)test_____.${name#*.};
58 void (*test____)() = (void (*)())$name;
63 : ${error:?unknown object type \"$type\"}
67 if [ "${VERBOSE}" = 1 ]
80 printf 'Looking for %s %s in %s.%s' \
81 "${name}" "${type}" "${include}" "${eol}" &&
86 " "$include" "$code" > "${temp}" &&
87 if ${CC} ${CPPFLAGS} ${EXTRA_CPPFLAGS} ${CFLAGS} ${EXTRA_CFLAGS} \
88 ${AUTO_CONFIG_CFLAGS} \
89 -xc -c -o ${temp}.o "${temp}" 1>&${out} 2>&${err}
91 rm -f "${temp}" "${temp}.o"
97 " "${macro}" "${macro}" "${macro}" >> "${file}" &&
98 printf 'Defining %s.\n' "${macro}"
100 rm -f "${temp}" "${temp}.o"
102 /* %s is not defined. */
104 " "${macro}" >> "${file}" &&
105 printf 'Not defining %s.\n' "${macro}"