5 # Copyright 2014-2015 6WIND S.A.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
11 # * Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in
15 # the documentation and/or other materials provided with the
17 # * Neither the name of 6WIND S.A. nor the names of its
18 # contributors may be used to endorse or promote products derived
19 # from this software without specific prior written permission.
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 # Crude script to detect whether particular types, macros and functions are
34 # defined by trying to compile a file with a given header. Can be used to
35 # perform cross-platform checks since the resulting object file is not
38 # Set VERBOSE=1 in the environment to display compiler output and errors.
40 # CC, CPPFLAGS, CFLAGS, EXTRA_CPPFLAGS and EXTRA_CFLAGS are taken from the
43 # AUTO_CONFIG_CFLAGS may append additional CFLAGS without modifying the
46 file=${1:?output file name required (config.h)}
47 macro=${2:?output macro name required (HAVE_*)}
48 include=${3:?include name required (foo.h)}
49 type=${4:?object type required (define, enum, type, field, func)}
50 name=${5:?define/type/function name required}
54 temp=/tmp/${0##*/}.$$.c
60 #error $name not defined
66 long test____ = $name;
78 ${name%%.*} test_____;
80 (void)test_____.${name#*.};
86 void (*test____)() = (void (*)())$name;
91 : ${error:?unknown object type \"$type\"}
95 if [ "${VERBOSE}" = 1 ]
108 printf 'Looking for %s %s in %s.%s' \
109 "${name}" "${type}" "${include}" "${eol}" &&
114 " "$include" "$code" > "${temp}" &&
115 if ${CC} ${CPPFLAGS} ${EXTRA_CPPFLAGS} ${CFLAGS} ${EXTRA_CFLAGS} \
116 ${AUTO_CONFIG_CFLAGS} \
117 -c -o /dev/null "${temp}" 1>&${out} 2>&${err}
125 " "${macro}" "${macro}" "${macro}" >> "${file}" &&
126 printf 'Defining %s.\n' "${macro}"
130 /* %s is not defined. */
132 " "${macro}" >> "${file}" &&
133 printf 'Not defining %s.\n' "${macro}"