Davide Pesavento | bb55add | 2021-02-09 15:12:35 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Davide Pesavento | da1a4d3 | 2022-08-19 19:03:24 -0400 | [diff] [blame] | 2 | set -eo pipefail |
Davide Pesavento | bb55add | 2021-02-09 15:12:35 -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 | bb55add | 2021-02-09 15:12:35 -0500 | [diff] [blame] | 5 | |
| 6 | PROJ=PSync |
Davide Pesavento | f278438 | 2022-07-09 19:58:53 -0400 | [diff] [blame] | 7 | PCFILE=PSync |
Davide Pesavento | bb55add | 2021-02-09 15:12:35 -0500 | [diff] [blame] | 8 | |
| 9 | if [[ -n $DISABLE_HEADERS_CHECK ]]; then |
| 10 | echo 'Skipping headers check.' |
| 11 | exit 0 |
| 12 | fi |
| 13 | |
Davide Pesavento | da1a4d3 | 2022-08-19 19:03:24 -0400 | [diff] [blame] | 14 | if [[ $ID_LIKE == *fedora* ]]; then |
Davide Pesavento | bb55add | 2021-02-09 15:12:35 -0500 | [diff] [blame] | 15 | export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig |
| 16 | fi |
| 17 | |
| 18 | CXX=${CXX:-g++} |
Davide Pesavento | c407dee | 2022-07-21 23:56:05 -0400 | [diff] [blame] | 19 | STD=-std=c++17 |
Davide Pesavento | f278438 | 2022-07-09 19:58:53 -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 | bb55add | 2021-02-09 15:12:35 -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 | da1a4d3 | 2022-08-19 19:03:24 -0400 | [diff] [blame] | 29 | "$CXX" -xc++ $STD $CXXFLAGS -c -o /dev/null "$H" || : $((NERRORS++)) |
| 30 | : $((NCHECKED++)) |
Davide Pesavento | bb55add | 2021-02-09 15:12:35 -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 |