Script to test if headers are self-sufficient.
[darkstat] / test_headers.sh
1 #!/bin/sh
2 # copyright (c) 2011 Emil Mikulic.
3 #
4 # The rule is that every header has to bring in all of its dependencies.
5 #
6 # This script tests to make sure it's true: for each header file,
7 # test-compile a C source file that includes just the header.
8 #
9 # Also test that it can be included twice without problems.
10 #
11 src=_test_hdr.c
12 obj=_test_hdr.o
13
14 if [ $# -eq 0 ]; then
15 echo "usage: $0 *.h" >&2
16 exit 1
17 fi
18
19 for f in $*; do
20 cat >$src <<EOF
21 #include "$f"
22 void test_hdr_do_nothing(void) { }
23 EOF
24 if gcc -c $src 2>/dev/null; then
25 true
26 else
27 echo "===> FAIL: $f <==="
28 gcc -c $src
29 fi
30
31 cat >$src <<EOF
32 #include "$f"
33 #include "$f"
34 void test_hdr_do_nothing(void) { }
35 EOF
36 if gcc -c $src 2>/dev/null; then
37 true
38 else
39 echo "===> FAIL DOUBLE: $f <==="
40 gcc -c $src
41 fi
42 done
43
44 rm $src $obj