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