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 | |
| 8 | CXX=${CXX:-g++} |
| 9 | |
| 10 | STD= |
| 11 | if $CXX -xc++ /dev/null -o /dev/null -c -std=c++11 &>/dev/null; then |
| 12 | STD=-std=c++11 |
| 13 | elif $CXX -xc++ /dev/null -o /dev/null -c -std=c++0x &>/dev/null; then |
| 14 | STD=-std=c++0x |
| 15 | fi |
| 16 | |
| 17 | STDLIB= |
| 18 | if $CXX -xc++ /dev/null -o /dev/null -c $STD -stdlib=libc++ &>/dev/null; then |
| 19 | STDLIB=-stdlib=libc++ |
| 20 | fi |
| 21 | |
| 22 | echo 'Compiler flags:' $CXX $STD $STDLIB |
| 23 | |
| 24 | INCLUDEDIR=/usr/local/include/ndn-cxx |
| 25 | NCHECKED=0 |
| 26 | NERRORS=0 |
| 27 | while IFS= read -r -d '' H; do |
| 28 | echo 'Verifying standalone header compilation for' $H |
| 29 | $CXX -xc++ "$INCLUDEDIR/$H" -o /dev/null -c $STD $STDLIB $(pkg-config --cflags libndn-cxx) |
| 30 | [[ $? -eq 0 ]] || ((NERRORS++)) |
| 31 | ((NCHECKED++)) |
| 32 | done < <(cd "$INCLUDEDIR" && find * -name '*.hpp' -type f -print0 2>/dev/null) |
| 33 | |
| 34 | if [[ $NCHECKED -eq 0 ]]; then |
| 35 | echo 'No header found. Is ndn-cxx installed?' |
| 36 | exit 1 |
| 37 | fi |
| 38 | |
| 39 | if [[ $NERRORS -gt 0 ]]; then |
| 40 | echo $NERRORS 'headers cannot compile on its own' |
| 41 | exit 1 |
| 42 | fi |