s6_addr32 compatibility for OpenSolaris
[darkstat] / test_headers.sh
1 #!/bin/sh
2 # copyright (c) 2011 Emil Mikulic.
3
4 a="\033[33;1m"
5 z="\033[m"
6
7 check_deps() {
8 echo checking header dependencies...
9 # Except for the c-ify output, every header should bring in all of its
10 # dependencies, and be able to be included multiple times.
11 src=_test_hdr.c
12 obj=_test_hdr.o
13 files=`ls *.h | fgrep -v -e graphjs.h -e stylecss.h`
14
15 for f in $files; do
16 cat >$src <<EOF
17 #include "$f"
18 void test_hdr_do_nothing(void) { }
19 EOF
20 if ! gcc -c $src 2>/dev/null; then
21 echo "${a}===> $f can't be included by itself${z}"
22 gcc -c $src
23 else
24 cat >$src <<EOF
25 #include "$f"
26 #include "$f"
27 void test_hdr_do_nothing(void) { }
28 EOF
29 if ! gcc -c $src 2>/dev/null; then
30 echo "${a}===> $f can't be included twice${z}"
31 gcc -c $src
32 fi
33 fi
34 done
35
36 rm $src $obj
37 }
38
39 check_defines() {
40 header=$1
41 defines=$2
42 files=$3
43
44 echo checking $header users...
45
46 # Check that files expecting defines include it.
47 for file in `egrep -l "$defines" $files`; do
48 if ! fgrep -q '#include "'$header'"' $file; then
49 echo "${a}===> $file should include $header${z}"
50 egrep --color=always "$defines" $file
51 fi
52 done
53
54 # And that others don't.
55 for file in `fgrep -l '#include "'$header'"' *.[ch]`; do
56 if ! egrep -q "$defines" $file; then
57 echo "${a}===> $file should not include $header${z}"
58 fi
59 done
60 }
61
62 # -=-
63
64 check_deps
65
66 defines=`grep \# config.h | cut -d# -f2 | cut -d' ' -f2 | tr '\n' '|' |
67 sed -e 's/|$//'`
68 files=`ls *.[ch] | fgrep -v config.h`
69 check_defines config.h "$defines" "$files"
70
71 defines=`sed -e 's/# \+/#/;' < cdefs.h | grep '#define' | cut -d' ' -f2 |
72 sed -e 's/(.\+/\\\\(/' | tr '\n' '|' | sed -e 's/|$//'`
73 files=`ls *.[ch] | fgrep -v -e cdefs.h -e graphjs.h -e stylecss.h`
74 check_defines cdefs.h "$defines" "$files"
75
76 # vim:set ts=2 sw=2 et: