Junxiao Shi | 316ea71 | 2015-01-08 20:46:47 -0700 | [diff] [blame] | 1 | #!/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 Pesavento | 97242f7 | 2020-02-29 14:28:15 -0500 | [diff] [blame^] | 8 | if [[ -n $DISABLE_HEADERS_CHECK ]]; then |
| 9 | echo 'Skipping headers check.' |
| 10 | exit 0 |
| 11 | fi |
| 12 | |
Junxiao Shi | 316ea71 | 2015-01-08 20:46:47 -0700 | [diff] [blame] | 13 | CXX=${CXX:-g++} |
Davide Pesavento | 1fd0024 | 2018-05-20 00:11:01 -0400 | [diff] [blame] | 14 | STD=-std=c++14 |
Davide Pesavento | 5ee8ec0 | 2018-09-01 19:06:12 -0400 | [diff] [blame] | 15 | CXXFLAGS="-O2 -Wall -Wno-unused-const-variable -Wno-unused-local-typedef $(pkg-config --cflags libndn-cxx)" |
Davide Pesavento | 2063952 | 2017-06-08 19:34:14 -0400 | [diff] [blame] | 16 | INCLUDEDIR="$(pkg-config --variable=includedir libndn-cxx)"/ndn-cxx |
Junxiao Shi | 316ea71 | 2015-01-08 20:46:47 -0700 | [diff] [blame] | 17 | |
Davide Pesavento | 2063952 | 2017-06-08 19:34:14 -0400 | [diff] [blame] | 18 | echo "Using: $CXX $STD $CXXFLAGS" |
Junxiao Shi | 316ea71 | 2015-01-08 20:46:47 -0700 | [diff] [blame] | 19 | |
Junxiao Shi | 316ea71 | 2015-01-08 20:46:47 -0700 | [diff] [blame] | 20 | NCHECKED=0 |
| 21 | NERRORS=0 |
| 22 | while IFS= read -r -d '' H; do |
Davide Pesavento | 97242f7 | 2020-02-29 14:28:15 -0500 | [diff] [blame^] | 23 | echo "Checking header ${H#${INCLUDEDIR}/}" |
Davide Pesavento | 2063952 | 2017-06-08 19:34:14 -0400 | [diff] [blame] | 24 | "$CXX" -xc++ $STD $CXXFLAGS -c -o /dev/null "$H" |
Junxiao Shi | 316ea71 | 2015-01-08 20:46:47 -0700 | [diff] [blame] | 25 | [[ $? -eq 0 ]] || ((NERRORS++)) |
| 26 | ((NCHECKED++)) |
Davide Pesavento | 2063952 | 2017-06-08 19:34:14 -0400 | [diff] [blame] | 27 | done < <(find "$INCLUDEDIR" -name '*.hpp' -type f -print0 2>/dev/null) |
Junxiao Shi | 316ea71 | 2015-01-08 20:46:47 -0700 | [diff] [blame] | 28 | |
| 29 | if [[ $NCHECKED -eq 0 ]]; then |
Davide Pesavento | 97242f7 | 2020-02-29 14:28:15 -0500 | [diff] [blame^] | 30 | echo 'No headers found. Is ndn-cxx installed?' |
Junxiao Shi | 316ea71 | 2015-01-08 20:46:47 -0700 | [diff] [blame] | 31 | exit 1 |
Davide Pesavento | 2063952 | 2017-06-08 19:34:14 -0400 | [diff] [blame] | 32 | else |
| 33 | echo "$NCHECKED headers checked." |
Junxiao Shi | 316ea71 | 2015-01-08 20:46:47 -0700 | [diff] [blame] | 34 | fi |
| 35 | |
| 36 | if [[ $NERRORS -gt 0 ]]; then |
Davide Pesavento | 2063952 | 2017-06-08 19:34:14 -0400 | [diff] [blame] | 37 | echo "$NERRORS headers could not be compiled." |
Junxiao Shi | 316ea71 | 2015-01-08 20:46:47 -0700 | [diff] [blame] | 38 | exit 1 |
| 39 | fi |