Davide Pesavento | 780e646 | 2021-02-08 20:58:12 -0500 | [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 | |
| 8 | PROJ=ChronoSync |
Davide Pesavento | 9c4bd6d | 2022-07-26 15:28:08 -0400 | [diff] [blame^] | 9 | PCFILE=ChronoSync |
Davide Pesavento | 780e646 | 2021-02-08 20:58:12 -0500 | [diff] [blame] | 10 | |
| 11 | if [[ -n $DISABLE_HEADERS_CHECK ]]; then |
| 12 | echo 'Skipping headers check.' |
| 13 | exit 0 |
| 14 | fi |
| 15 | |
Davide Pesavento | 9c4bd6d | 2022-07-26 15:28:08 -0400 | [diff] [blame^] | 16 | if has CentOS $NODE_LABELS; then |
Davide Pesavento | 780e646 | 2021-02-08 20:58:12 -0500 | [diff] [blame] | 17 | export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig |
| 18 | fi |
| 19 | |
| 20 | CXX=${CXX:-g++} |
Davide Pesavento | 8663ed1 | 2022-07-23 03:04:27 -0400 | [diff] [blame] | 21 | STD=-std=c++17 |
Davide Pesavento | 9c4bd6d | 2022-07-26 15:28:08 -0400 | [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 |
Davide Pesavento | 780e646 | 2021-02-08 20:58:12 -0500 | [diff] [blame] | 24 | |
| 25 | echo "Using: $CXX $STD $CXXFLAGS" |
| 26 | |
| 27 | NCHECKED=0 |
| 28 | NERRORS=0 |
| 29 | while IFS= read -r -d '' H; do |
| 30 | echo "Checking header ${H#${INCLUDEDIR}/}" |
| 31 | "$CXX" -xc++ $STD $CXXFLAGS -c -o /dev/null "$H" |
| 32 | [[ $? -eq 0 ]] || ((NERRORS++)) |
| 33 | ((NCHECKED++)) |
| 34 | done < <(find "$INCLUDEDIR" -name '*.hpp' -type f -print0 2>/dev/null) |
| 35 | |
| 36 | if [[ $NCHECKED -eq 0 ]]; then |
| 37 | echo "No headers found. Is $PROJ installed?" |
| 38 | exit 1 |
| 39 | else |
| 40 | echo "$NCHECKED headers checked." |
| 41 | fi |
| 42 | |
| 43 | if [[ $NERRORS -gt 0 ]]; then |
| 44 | echo "$NERRORS headers could not be compiled." |
| 45 | exit 1 |
| 46 | fi |