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, CXX, CXXFLAGS are taken into account.
22 # PEDANTIC_CFLAGS, PEDANTIC_CXXFLAGS and PEDANTIC_CPPFLAGS provide strict
23 # C/C++ compilation flags.
25 # IGNORE contains a list of globbing patterns matching files (relative to the
26 # include directory) to avoid. It is set by default to known DPDK headers
27 # which must not be included on their own.
29 # IGNORE_CXX provides additional files for C++.
31 while getopts hqvs arg; do
35 usage: $0 [-h] [-q] [-v] [-s] [DIR]
37 This script checks that header files in a given directory do not miss
38 dependencies when included on their own, do not conflict and accept being
39 compiled with the strictest possible flags.
41 -h display this help and exit
42 -q quiet mode, disable normal output
43 -v show command lines being executed
46 With no DIR, default to build/include.
48 Any failed header check yields a nonzero exit status.
67 shift $(($OPTIND - 1))
69 include_dir=${1:-build/include}
71 : ${PEDANTIC_CFLAGS=-std=c99 -pedantic -Wall -Wextra -Werror}
72 : ${PEDANTIC_CXXFLAGS=}
73 : ${PEDANTIC_CPPFLAGS=-D_XOPEN_SOURCE=600}
79 'rte_byteorder_32.h' \
80 'rte_byteorder_64.h' \
84 'rte_eal_interrupts.h' \
91 temp_cc=$(mktemp -t dpdk.${0##*/}.XXX.c)
95 temp_cxx=$(mktemp -t dpdk.${0##*/}.XXX.cc)
99 # Process output parameters.
104 [ "$VERBOSE" = 1 ] &&
113 CC="echo $CC" CXX="echo $CXX" "$@"
127 trap 'rm -f "$temp_cc" "$temp_cxx"' EXIT
131 ${CC} -I"$include_dir" \
132 ${PEDANTIC_CPPFLAGS} ${CPPFLAGS} \
133 ${PEDANTIC_CFLAGS} ${CFLAGS} \
134 -c -o /dev/null "${temp_cc}"
139 ${CXX} -I"$include_dir" \
140 ${PEDANTIC_CPPFLAGS} ${CPPFLAGS} \
141 ${PEDANTIC_CXXFLAGS} ${CXXFLAGS} \
142 -c -o /dev/null "${temp_cxx}"
149 while [ $# -ne 0 ]; do
160 # Check C/C++ compilation for each header file.
164 file=${path#$include_dir}
166 if ignore "$file" $IGNORE; then
167 output "SKIP $file" :
177 " "$file" > "$temp_cc" &&
178 output "CC $file" compile_cc
180 pass_cc="$pass_cc $file"
182 failures_cc=$(($failures_cc + 1))
184 if ignore "$file" $IGNORE_CXX; then
185 output "SKIP CXX $file" :
194 " "$file" > "$temp_cxx" &&
195 output "CXX $file" compile_cxx
197 pass_cxx="$pass_cxx $file"
199 failures_cxx=$(($failures_cxx + 1))
202 $(find "$include_dir" -name '*.h')
205 # Check C compilation with all includes.
208 for file in $pass_cc; do
211 " "$file" >> $temp_cc
219 output "CC (all includes that did not fail)" compile_cc
223 failures_cc=$(($failures_cc + 1))
226 # Check C++ compilation with all includes.
229 for file in $pass_cxx; do
232 " "$file" >> $temp_cxx
239 output "CXX (all includes that did not fail)" compile_cxx
243 failures_cxx=$(($failures_cxx + 1))
248 if [ "$SUMMARY" = 1 ]; then
251 %u failure(s) for C using '%s'.
252 %u failure(s) for C++ using '%s'.
253 " $failures_cc "$CC" $failures_cxx "$CXX" 1>&2
256 # Exit with nonzero status if there are failures.
258 [ $failures_cc -eq 0 ] &&
259 [ $failures_cxx -eq 0 ]