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' \
85 'rte_eal_interrupts.h' \
92 temp_cc=$(mktemp -t dpdk.${0##*/}.XXX.c)
96 temp_cxx=$(mktemp -t dpdk.${0##*/}.XXX.cc)
100 # Process output parameters.
105 [ "$VERBOSE" = 1 ] &&
114 CC="echo $CC" CXX="echo $CXX" "$@"
128 trap 'rm -f "$temp_cc" "$temp_cxx"' EXIT
132 ${CC} -I"$include_dir" \
133 ${PEDANTIC_CPPFLAGS} ${CPPFLAGS} ${EXTRA_CPPFLAGS} \
134 ${PEDANTIC_CFLAGS} ${CFLAGS} ${EXTRA_CFLAGS} \
135 -c -o /dev/null "${temp_cc}"
140 ${CXX} -I"$include_dir" \
141 ${PEDANTIC_CPPFLAGS} ${CPPFLAGS} ${EXTRA_CPPFLAGS} \
142 ${PEDANTIC_CXXFLAGS} ${CXXFLAGS} ${EXTRA_CXXFLAGS} \
143 -c -o /dev/null "${temp_cxx}"
150 while [ $# -ne 0 ]; do
161 # Check C/C++ compilation for each header file.
165 file=${path#$include_dir}
167 if ignore "$file" $IGNORE; then
168 output "SKIP $file" :
178 " "$file" > "$temp_cc" &&
179 output "CC $file" compile_cc
181 pass_cc="$pass_cc $file"
183 failures_cc=$(($failures_cc + 1))
185 if ignore "$file" $IGNORE_CXX; then
186 output "SKIP CXX $file" :
195 " "$file" > "$temp_cxx" &&
196 output "CXX $file" compile_cxx
198 pass_cxx="$pass_cxx $file"
200 failures_cxx=$(($failures_cxx + 1))
203 $(find "$include_dir" -name '*.h')
206 # Check C compilation with all includes.
209 for file in $pass_cc; do
212 " "$file" >> $temp_cc
220 output "CC (all includes that did not fail)" compile_cc
224 failures_cc=$(($failures_cc + 1))
227 # Check C++ compilation with all includes.
230 for file in $pass_cxx; do
233 " "$file" >> $temp_cxx
240 output "CXX (all includes that did not fail)" compile_cxx
244 failures_cxx=$(($failures_cxx + 1))
249 if [ "$SUMMARY" = 1 ]; then
252 %u failure(s) for C using '%s'.
253 %u failure(s) for C++ using '%s'.
254 " $failures_cc "$CC" $failures_cxx "$CXX" 1>&2
257 # Exit with nonzero status if there are failures.
259 [ $failures_cc -eq 0 ] &&
260 [ $failures_cxx -eq 0 ]