blob: 0095b3f7121c1b02c6b412caaeae12e88a2213d3 [file] [log] [blame]
Junxiao Shi316ea712015-01-08 20:46:47 -07001#!/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
8CXX=${CXX:-g++}
9
10STD=
11if $CXX -xc++ /dev/null -o /dev/null -c -std=c++11 &>/dev/null; then
12 STD=-std=c++11
13elif $CXX -xc++ /dev/null -o /dev/null -c -std=c++0x &>/dev/null; then
14 STD=-std=c++0x
15fi
16
17STDLIB=
18if $CXX -xc++ /dev/null -o /dev/null -c $STD -stdlib=libc++ &>/dev/null; then
19 STDLIB=-stdlib=libc++
20fi
21
22echo 'Compiler flags:' $CXX $STD $STDLIB
23
24INCLUDEDIR=/usr/local/include/ndn-cxx
25NCHECKED=0
26NERRORS=0
27while 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++))
32done < <(cd "$INCLUDEDIR" && find * -name '*.hpp' -type f -print0 2>/dev/null)
33
34if [[ $NCHECKED -eq 0 ]]; then
35 echo 'No header found. Is ndn-cxx installed?'
36 exit 1
37fi
38
39if [[ $NERRORS -gt 0 ]]; then
40 echo $NERRORS 'headers cannot compile on its own'
41 exit 1
42fi