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