blob: 486bb4eb2e691fa6ed1a151a18cd97549d42fc9d [file] [log] [blame]
Junxiao Shi316ea712015-01-08 20:46:47 -07001#!/usr/bin/env bash
2
3# It's intentional not to use `set -x`, because this script explicitly prints useful information
4# and should not run in trace mode.
5# It's intentional not to use `set -e`, because this script wants to check all headers
6# (similar to running all test cases), instead of failing at the first error.
7
Davide Pesavento97242f72020-02-29 14:28:15 -05008if [[ -n $DISABLE_HEADERS_CHECK ]]; then
9 echo 'Skipping headers check.'
10 exit 0
11fi
12
Davide Pesavento2349e282020-03-24 14:28:03 -040013if has CentOS-8 $NODE_LABELS; then
14 export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig
15fi
16
Junxiao Shi316ea712015-01-08 20:46:47 -070017CXX=${CXX:-g++}
Davide Pesavento1fd00242018-05-20 00:11:01 -040018STD=-std=c++14
Davide Pesavento2349e282020-03-24 14:28:03 -040019CXXFLAGS="-O2 -Wall -Wno-unneeded-internal-declaration -Wno-unused-const-variable $(pkg-config --cflags libndn-cxx)"
Davide Pesavento20639522017-06-08 19:34:14 -040020INCLUDEDIR="$(pkg-config --variable=includedir libndn-cxx)"/ndn-cxx
Junxiao Shi316ea712015-01-08 20:46:47 -070021
Davide Pesavento20639522017-06-08 19:34:14 -040022echo "Using: $CXX $STD $CXXFLAGS"
Junxiao Shi316ea712015-01-08 20:46:47 -070023
Junxiao Shi316ea712015-01-08 20:46:47 -070024NCHECKED=0
25NERRORS=0
26while IFS= read -r -d '' H; do
Davide Pesavento97242f72020-02-29 14:28:15 -050027 echo "Checking header ${H#${INCLUDEDIR}/}"
Davide Pesavento20639522017-06-08 19:34:14 -040028 "$CXX" -xc++ $STD $CXXFLAGS -c -o /dev/null "$H"
Junxiao Shi316ea712015-01-08 20:46:47 -070029 [[ $? -eq 0 ]] || ((NERRORS++))
30 ((NCHECKED++))
Davide Pesavento20639522017-06-08 19:34:14 -040031done < <(find "$INCLUDEDIR" -name '*.hpp' -type f -print0 2>/dev/null)
Junxiao Shi316ea712015-01-08 20:46:47 -070032
33if [[ $NCHECKED -eq 0 ]]; then
Davide Pesavento97242f72020-02-29 14:28:15 -050034 echo 'No headers found. Is ndn-cxx installed?'
Junxiao Shi316ea712015-01-08 20:46:47 -070035 exit 1
Davide Pesavento20639522017-06-08 19:34:14 -040036else
37 echo "$NCHECKED headers checked."
Junxiao Shi316ea712015-01-08 20:46:47 -070038fi
39
40if [[ $NERRORS -gt 0 ]]; then
Davide Pesavento20639522017-06-08 19:34:14 -040041 echo "$NERRORS headers could not be compiled."
Junxiao Shi316ea712015-01-08 20:46:47 -070042 exit 1
43fi