Davide Pesavento | 780e646 | 2021-02-08 20:58:12 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Davide Pesavento | 15a7442 | 2022-08-19 15:48:45 -0400 | [diff] [blame^] | 2 | set -eo pipefail |
Davide Pesavento | 780e646 | 2021-02-08 20:58:12 -0500 | [diff] [blame] | 3 | # It's intentional not to use `set -x`, because this script explicitly prints useful information |
| 4 | # and should not run in trace mode. |
Davide Pesavento | 780e646 | 2021-02-08 20:58:12 -0500 | [diff] [blame] | 5 | |
| 6 | PROJ=ChronoSync |
Davide Pesavento | 9c4bd6d | 2022-07-26 15:28:08 -0400 | [diff] [blame] | 7 | PCFILE=ChronoSync |
Davide Pesavento | 780e646 | 2021-02-08 20:58:12 -0500 | [diff] [blame] | 8 | |
| 9 | if [[ -n $DISABLE_HEADERS_CHECK ]]; then |
| 10 | echo 'Skipping headers check.' |
| 11 | exit 0 |
| 12 | fi |
| 13 | |
Davide Pesavento | 15a7442 | 2022-08-19 15:48:45 -0400 | [diff] [blame^] | 14 | if [[ $ID_LIKE == *fedora* ]]; then |
Davide Pesavento | 780e646 | 2021-02-08 20:58:12 -0500 | [diff] [blame] | 15 | export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig |
| 16 | fi |
| 17 | |
| 18 | CXX=${CXX:-g++} |
Davide Pesavento | 8663ed1 | 2022-07-23 03:04:27 -0400 | [diff] [blame] | 19 | STD=-std=c++17 |
Davide Pesavento | 9c4bd6d | 2022-07-26 15:28:08 -0400 | [diff] [blame] | 20 | CXXFLAGS="-O2 -Wall -Wno-unneeded-internal-declaration -Wno-unused-const-variable $(pkg-config --cflags libndn-cxx $PCFILE)" |
| 21 | INCLUDEDIR="$(pkg-config --variable=includedir $PCFILE)"/$PROJ |
Davide Pesavento | 780e646 | 2021-02-08 20:58:12 -0500 | [diff] [blame] | 22 | |
| 23 | echo "Using: $CXX $STD $CXXFLAGS" |
| 24 | |
| 25 | NCHECKED=0 |
| 26 | NERRORS=0 |
| 27 | while IFS= read -r -d '' H; do |
| 28 | echo "Checking header ${H#${INCLUDEDIR}/}" |
Davide Pesavento | 15a7442 | 2022-08-19 15:48:45 -0400 | [diff] [blame^] | 29 | "$CXX" -xc++ $STD $CXXFLAGS -c -o /dev/null "$H" || : $((NERRORS++)) |
| 30 | : $((NCHECKED++)) |
Davide Pesavento | 780e646 | 2021-02-08 20:58:12 -0500 | [diff] [blame] | 31 | done < <(find "$INCLUDEDIR" -name '*.hpp' -type f -print0 2>/dev/null) |
| 32 | |
| 33 | if [[ $NCHECKED -eq 0 ]]; then |
| 34 | echo "No headers found. Is $PROJ installed?" |
| 35 | exit 1 |
| 36 | else |
| 37 | echo "$NCHECKED headers checked." |
| 38 | fi |
| 39 | |
| 40 | if [[ $NERRORS -gt 0 ]]; then |
| 41 | echo "$NERRORS headers could not be compiled." |
| 42 | exit 1 |
| 43 | fi |