doc: add required python versions
[dpdk.git] / scripts / auto-config-h.sh
1 #!/bin/sh
2 #
3 #   BSD LICENSE
4 #
5 #   Copyright 2014-2015 6WIND S.A.
6 #
7 #   Redistribution and use in source and binary forms, with or without
8 #   modification, are permitted provided that the following conditions
9 #   are met:
10 #
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
16 #       distribution.
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.
20 #
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.
32 #
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
36 # executed.
37 #
38 # Set VERBOSE=1 in the environment to display compiler output and errors.
39 #
40 # CC, CPPFLAGS, CFLAGS, EXTRA_CPPFLAGS and EXTRA_CFLAGS are taken from the
41 # environment.
42 #
43 # AUTO_CONFIG_CFLAGS may append additional CFLAGS without modifying the
44 # above variables.
45
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}
51
52 : ${CC:=cc}
53
54 temp=/tmp/${0##*/}.$$.c
55
56 case $type in
57 define)
58         code="\
59 #ifndef $name
60 #error $name not defined
61 #endif
62 "
63         ;;
64 enum)
65         code="\
66 long test____ = $name;
67 "
68         ;;
69 type)
70         code="\
71 $name test____;
72 "
73         ;;
74 field)
75         code="\
76 void test____(void)
77 {
78         ${name%%.*} test_____;
79
80         (void)test_____.${name#*.};
81 }
82 "
83         ;;
84 func)
85         code="\
86 void (*test____)() = (void (*)())$name;
87 "
88         ;;
89 *)
90         unset error
91         : ${error:?unknown object type \"$type\"}
92         exit
93 esac
94
95 if [ "${VERBOSE}" = 1 ]
96 then
97         err=2
98         out=1
99         eol='
100 '
101 else
102         exec 3> /dev/null ||
103         exit
104         err=3
105         out=3
106         eol=' '
107 fi &&
108 printf 'Looking for %s %s in %s.%s' \
109         "${name}" "${type}" "${include}" "${eol}" &&
110 printf "\
111 #include <%s>
112
113 %s
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}
118 then
119         rm -f "${temp}"
120         printf "\
121 #ifndef %s
122 #define %s 1
123 #endif /* %s */
124
125 " "${macro}" "${macro}" "${macro}" >> "${file}" &&
126         printf 'Defining %s.\n' "${macro}"
127 else
128         rm -f "${temp}"
129         printf "\
130 /* %s is not defined. */
131
132 " "${macro}" >> "${file}" &&
133         printf 'Not defining %s.\n' "${macro}"
134 fi
135
136 exit