2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright 2016 6WIND S.A.
5 # This script checks that header files in a given directory do not miss
6 # dependencies when included on their own, do not conflict and accept being
7 # compiled with the strictest possible flags.
9 # Files are looked up in the directory provided as the first argument,
10 # otherwise build/include by default.
12 # Recognized environment variables:
14 # VERBOSE=1 is the same as -v.
16 # QUIET=1 is the same as -q.
18 # SUMMARY=1 is the same as -s.
20 # CC, CPPFLAGS, CFLAGS, EXTRA_CPPFLAGS, EXTRA_CFLAGS, CXX, CXXFLAGS and
21 # EXTRA_CXXFLAGS are taken into account.
23 # PEDANTIC_CFLAGS, PEDANTIC_CXXFLAGS and PEDANTIC_CPPFLAGS provide strict
24 # C/C++ compilation flags.
26 # IGNORE contains a list of shell patterns matching files (relative to the
27 # include directory) to avoid. It is set by default to known DPDK headers
28 # which must not be included on their own.
30 # IGNORE_CXX provides additional files for C++.
32 while getopts hqvs arg; do
36 usage: $0 [-h] [-q] [-v] [-s] [DIR]
38 This script checks that header files in a given directory do not miss
39 dependencies when included on their own, do not conflict and accept being
40 compiled with the strictest possible flags.
42 -h display this help and exit
43 -q quiet mode, disable normal output
44 -v show command lines being executed
47 With no DIR, default to build/include.
49 Any failed header check yields a nonzero exit status.
68 shift $(($OPTIND - 1))
70 include_dir=${1:-build/include}
72 : ${PEDANTIC_CFLAGS=-std=c99 -pedantic -Wall -Wextra -Werror}
73 : ${PEDANTIC_CXXFLAGS=}
74 : ${PEDANTIC_CPPFLAGS=-D_XOPEN_SOURCE=600}
80 'rte_byteorder_32.h' \
81 'rte_byteorder_64.h' \
86 'rte_eal_interrupts.h' \
93 temp_cc=$(mktemp -t dpdk.${0##*/}.XXX.c)
97 temp_cxx=$(mktemp -t dpdk.${0##*/}.XXX.cc)
101 # Process output parameters.
106 [ "$VERBOSE" = 1 ] &&
115 CC="echo $CC" CXX="echo $CXX" "$@"
129 trap 'rm -f "$temp_cc" "$temp_cxx"' EXIT
133 ${CC} -I"$include_dir" \
134 ${PEDANTIC_CPPFLAGS} ${CPPFLAGS} ${EXTRA_CPPFLAGS} \
135 ${PEDANTIC_CFLAGS} ${CFLAGS} ${EXTRA_CFLAGS} \
136 -c -o /dev/null "${temp_cc}"
141 ${CXX} -I"$include_dir" \
142 ${PEDANTIC_CPPFLAGS} ${CPPFLAGS} ${EXTRA_CPPFLAGS} \
143 ${PEDANTIC_CXXFLAGS} ${CXXFLAGS} ${EXTRA_CXXFLAGS} \
144 -c -o /dev/null "${temp_cxx}"
151 while [ $# -ne 0 ]; do
162 # Check C/C++ compilation for each header file.
166 file=${path#$include_dir}
168 if ignore "$file" $IGNORE; then
169 output "SKIP $file" :
179 " "$file" > "$temp_cc" &&
180 output "CC $file" compile_cc
182 pass_cc="$pass_cc $file"
184 failures_cc=$(($failures_cc + 1))
186 if ignore "$file" $IGNORE_CXX; then
187 output "SKIP CXX $file" :
196 " "$file" > "$temp_cxx" &&
197 output "CXX $file" compile_cxx
199 pass_cxx="$pass_cxx $file"
201 failures_cxx=$(($failures_cxx + 1))
204 $(find "$include_dir" -name '*.h')
207 # Check C compilation with all includes.
210 for file in $pass_cc; do
213 " "$file" >> $temp_cc
221 output "CC (all includes that did not fail)" compile_cc
225 failures_cc=$(($failures_cc + 1))
228 # Check C++ compilation with all includes.
231 for file in $pass_cxx; do
234 " "$file" >> $temp_cxx
241 output "CXX (all includes that did not fail)" compile_cxx
245 failures_cxx=$(($failures_cxx + 1))
250 if [ "$SUMMARY" = 1 ]; then
253 %u failure(s) for C using '%s'.
254 %u failure(s) for C++ using '%s'.
255 " $failures_cc "$CC" $failures_cxx "$CXX" 1>&2
258 # Exit with nonzero status if there are failures.
260 [ $failures_cc -eq 0 ] &&
261 [ $failures_cxx -eq 0 ]