Update portability notes.
[darkstat] / test_headers.sh
1 #!/bin/sh
2 # copyright (c) 2011-2012 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 echo " * $f"
18 cat >$src <<EOF
19 #include "$f"
20 void test_hdr_do_nothing(void) { }
21 EOF
22 if ! gcc -c $src 2>/dev/null; then
23 echo "${a}===> $f can't be included by itself${z}"
24 problem=1
25 gcc -c $src
26 else
27 cat >$src <<EOF
28 #include "$f"
29 #include "$f"
30 void test_hdr_do_nothing(void) { }
31 EOF
32 if ! gcc -c $src 2>/dev/null; then
33 echo "${a}===> $f can't be included twice${z}"
34 problem=1
35 gcc -c $src
36 fi
37 fi
38 done
39
40 rm $src $obj
41 }
42
43 check_defines() {
44 header=$1
45 defines="(^|[^a-zA-Z_])($2)"
46 files=$3
47
48 echo checking $header users...
49
50 # Check that files expecting defines include it.
51 for file in `egrep -l "$defines" $files`; do
52 if ! fgrep -q '#include "'$header'"' $file; then
53 echo "${a}===> $file should include $header${z}"
54 problem=1
55 egrep --color=always "$defines" $file
56 fi
57 done
58
59 # And that others don't.
60 for file in `fgrep -l '#include "'$header'"' *.[ch]`; do
61 if ! egrep -q "$defines" $file; then
62 echo "${a}===> $file should not include $header${z}"
63 problem=1
64 fi
65 done
66 }
67
68 # -=-
69
70 check_deps
71
72 # Check config.h: build a list of macros that are or could be defined.
73 defines=`egrep '#define|#undef' config.h | cut -d# -f2 | cut -d' ' -f2 |
74 sort -u | tr '\n' '|' | sed -e 's/|$//'`
75 # Check against all files except itself.
76 files=`ls *.[ch] | fgrep -v config.h`
77 #echo "config.h defines: ($defines)"
78 check_defines config.h "$defines" "$files"
79
80 defines=`sed -e 's/# \+/#/;' < cdefs.h | grep '#define' | cut -d' ' -f2 |
81 sed -e 's/(.\+/\\\\(/' | tr '\n' '|' | sed -e 's/|$//'`
82 files=`ls *.[ch] | fgrep -v -e cdefs.h -e graphjs.h -e stylecss.h`
83 check_defines cdefs.h "$defines" "$files"
84
85 exit $problem
86
87 # vim:set ts=2 sw=2 et: