5 # Copyright 2016 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 # This script checks that header files in a given directory do not miss
34 # dependencies when included on their own, do not conflict and accept being
35 # compiled with the strictest possible flags.
37 # Files are looked up in the directory provided as the first argument,
38 # otherwise build/include by default.
40 # Recognized environment variables:
42 # VERBOSE=1 is the same as -v.
44 # QUIET=1 is the same as -q.
46 # SUMMARY=1 is the same as -s.
48 # CC, CPPFLAGS, CFLAGS, EXTRA_CPPFLAGS, EXTRA_CFLAGS, CXX, CXXFLAGS and
49 # EXTRA_CXXFLAGS are taken into account.
51 # PEDANTIC_CFLAGS, PEDANTIC_CXXFLAGS and PEDANTIC_CPPFLAGS provide strict
52 # C/C++ compilation flags.
54 # IGNORE contains a list of shell patterns matching files (relative to the
55 # include directory) to avoid. It is set by default to known DPDK headers
56 # which must not be included on their own.
58 # IGNORE_CXX provides additional files for C++.
60 while getopts hqvs arg; do
64 usage: $0 [-h] [-q] [-v] [-s] [DIR]
66 This script checks that header files in a given directory do not miss
67 dependencies when included on their own, do not conflict and accept being
68 compiled with the strictest possible flags.
70 -h display this help and exit
71 -q quiet mode, disable normal output
72 -v show command lines being executed
75 With no DIR, default to build/include.
77 Any failed header check yields a nonzero exit status.
96 shift $(($OPTIND - 1))
98 include_dir=${1:-build/include}
100 : ${PEDANTIC_CFLAGS=-std=c99 -pedantic -Wall -Wextra -Werror}
101 : ${PEDANTIC_CXXFLAGS=}
102 : ${PEDANTIC_CPPFLAGS=-D_XOPEN_SOURCE=600}
108 'rte_byteorder_32.h' \
109 'rte_byteorder_64.h' \
114 'rte_eal_interrupts.h' \
121 temp_cc=/tmp/${0##*/}.$$.c
125 temp_cxx=/tmp/${0##*/}.$$.cc
129 # Process output parameters.
134 [ "$VERBOSE" = 1 ] &&
143 CC="echo $CC" CXX="echo $CXX" "$@"
157 trap 'rm -f "$temp_cc" "$temp_cxx"' EXIT
161 ${CC} -I"$include_dir" \
162 ${PEDANTIC_CPPFLAGS} ${CPPFLAGS} ${EXTRA_CPPFLAGS} \
163 ${PEDANTIC_CFLAGS} ${CFLAGS} ${EXTRA_CFLAGS} \
164 -c -o /dev/null "${temp_cc}"
169 ${CXX} -I"$include_dir" \
170 ${PEDANTIC_CPPFLAGS} ${CPPFLAGS} ${EXTRA_CPPFLAGS} \
171 ${PEDANTIC_CXXFLAGS} ${CXXFLAGS} ${EXTRA_CXXFLAGS} \
172 -c -o /dev/null "${temp_cxx}"
179 while [ $# -ne 0 ]; do
190 # Check C/C++ compilation for each header file.
194 file=${path#$include_dir}
196 if ignore "$file" $IGNORE; then
197 output "SKIP $file" :
207 " "$file" > "$temp_cc" &&
208 output "CC $file" compile_cc
210 pass_cc="$pass_cc $file"
212 failures_cc=$(($failures_cc + 1))
214 if ignore "$file" $IGNORE_CXX; then
215 output "SKIP CXX $file" :
224 " "$file" > "$temp_cxx" &&
225 output "CXX $file" compile_cxx
227 pass_cxx="$pass_cxx $file"
229 failures_cxx=$(($failures_cxx + 1))
232 $(find "$include_dir" -name '*.h')
235 # Check C compilation with all includes.
238 for file in $pass_cc; do
241 " "$file" >> $temp_cc
249 output "CC (all includes that did not fail)" compile_cc
253 failures_cc=$(($failures_cc + 1))
256 # Check C++ compilation with all includes.
259 for file in $pass_cxx; do
262 " "$file" >> $temp_cxx
269 output "CXX (all includes that did not fail)" compile_cxx
273 failures_cxx=$(($failures_cxx + 1))
278 if [ "$SUMMARY" = 1 ]; then
281 %u failure(s) for C using '%s'.
282 %u failure(s) for C++ using '%s'.
283 " $failures_cc "$CC" $failures_cxx "$CXX" 1>&2
286 # Exit with nonzero status if there are failures.
288 [ $failures_cc -eq 0 ] &&
289 [ $failures_cxx -eq 0 ]