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' \
118 temp_cc=/tmp/${0##*/}.$$.c
122 temp_cxx=/tmp/${0##*/}.$$.cc
126 # Process output parameters.
131 [ "$VERBOSE" = 1 ] &&
140 CC="echo $CC" CXX="echo $CXX" "$@"
154 trap 'rm -f "$temp_cc" "$temp_cxx"' EXIT
158 ${CC} -I"$include_dir" \
159 ${PEDANTIC_CPPFLAGS} ${CPPFLAGS} ${EXTRA_CPPFLAGS} \
160 ${PEDANTIC_CFLAGS} ${CFLAGS} ${EXTRA_CFLAGS} \
161 -c -o /dev/null "${temp_cc}"
166 ${CXX} -I"$include_dir" \
167 ${PEDANTIC_CPPFLAGS} ${CPPFLAGS} ${EXTRA_CPPFLAGS} \
168 ${PEDANTIC_CXXFLAGS} ${CXXFLAGS} ${EXTRA_CXXFLAGS} \
169 -c -o /dev/null "${temp_cxx}"
176 while [ $# -ne 0 ]; do
187 # Check C/C++ compilation for each header file.
191 file=${path#$include_dir}
193 if ignore "$file" $IGNORE; then
194 output "SKIP $file" :
204 " "$file" > "$temp_cc" &&
205 output "CC $file" compile_cc
207 pass_cc="$pass_cc $file"
209 failures_cc=$(($failures_cc + 1))
211 if ignore "$file" $IGNORE_CXX; then
212 output "SKIP CXX $file" :
221 " "$file" > "$temp_cxx" &&
222 output "CXX $file" compile_cxx
224 pass_cxx="$pass_cxx $file"
226 failures_cxx=$(($failures_cxx + 1))
229 $(find "$include_dir" -name '*.h')
232 # Check C compilation with all includes.
235 for file in $pass_cc; do
238 " "$file" >> $temp_cc
246 output "CC (all includes that did not fail)" compile_cc
250 failures_cc=$(($failures_cc + 1))
253 # Check C++ compilation with all includes.
256 for file in $pass_cxx; do
259 " "$file" >> $temp_cxx
266 output "CXX (all includes that did not fail)" compile_cxx
270 failures_cxx=$(($failures_cxx + 1))
275 if [ "$SUMMARY" = 1 ]; then
278 %u failure(s) for C using '%s'.
279 %u failure(s) for C++ using '%s'.
280 " $failures_cc "$CC" $failures_cxx "$CXX" 1>&2
283 # Exit with nonzero status if there are failures.
285 [ $failures_cc -eq 0 ] &&
286 [ $failures_cxx -eq 0 ]