blob: 1258646aeed51699572541253ccb24f58ea948ad [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
Junxiao Shi316ea712015-01-08 20:46:47 -070013CXX=${CXX:-g++}
Davide Pesavento1fd00242018-05-20 00:11:01 -040014STD=-std=c++14
Davide Pesavento5ee8ec02018-09-01 19:06:12 -040015CXXFLAGS="-O2 -Wall -Wno-unused-const-variable -Wno-unused-local-typedef $(pkg-config --cflags libndn-cxx)"
Davide Pesavento20639522017-06-08 19:34:14 -040016INCLUDEDIR="$(pkg-config --variable=includedir libndn-cxx)"/ndn-cxx
Junxiao Shi316ea712015-01-08 20:46:47 -070017
Davide Pesavento20639522017-06-08 19:34:14 -040018echo "Using: $CXX $STD $CXXFLAGS"
Junxiao Shi316ea712015-01-08 20:46:47 -070019
Junxiao Shi316ea712015-01-08 20:46:47 -070020NCHECKED=0
21NERRORS=0
22while IFS= read -r -d '' H; do
Davide Pesavento97242f72020-02-29 14:28:15 -050023 echo "Checking header ${H#${INCLUDEDIR}/}"
Davide Pesavento20639522017-06-08 19:34:14 -040024 "$CXX" -xc++ $STD $CXXFLAGS -c -o /dev/null "$H"
Junxiao Shi316ea712015-01-08 20:46:47 -070025 [[ $? -eq 0 ]] || ((NERRORS++))
26 ((NCHECKED++))
Davide Pesavento20639522017-06-08 19:34:14 -040027done < <(find "$INCLUDEDIR" -name '*.hpp' -type f -print0 2>/dev/null)
Junxiao Shi316ea712015-01-08 20:46:47 -070028
29if [[ $NCHECKED -eq 0 ]]; then
Davide Pesavento97242f72020-02-29 14:28:15 -050030 echo 'No headers found. Is ndn-cxx installed?'
Junxiao Shi316ea712015-01-08 20:46:47 -070031 exit 1
Davide Pesavento20639522017-06-08 19:34:14 -040032else
33 echo "$NCHECKED headers checked."
Junxiao Shi316ea712015-01-08 20:46:47 -070034fi
35
36if [[ $NERRORS -gt 0 ]]; then
Davide Pesavento20639522017-06-08 19:34:14 -040037 echo "$NERRORS headers could not be compiled."
Junxiao Shi316ea712015-01-08 20:46:47 -070038 exit 1
39fi