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