Check for missing and extraneous config.h includes.
[darkstat] / test_headers.sh
1 #!/bin/sh
2 # copyright (c) 2011 Emil Mikulic.
3
4 a="\033[31;1m"
5 z="\033[m"
6
7 echo checking header dependencies...
8 # Except for the c-ify output, every header should bring in all of its
9 # dependencies, and be able to be included multiple times.
10 src=_test_hdr.c
11 obj=_test_hdr.o
12 files=`ls *.h | fgrep -v -e graphjs.h -e stylecss.h`
13
14 for f in $files; do
15 cat >$src <<EOF
16 #include "$f"
17 void test_hdr_do_nothing(void) { }
18 EOF
19 if ! gcc -c $src 2>/dev/null; then
20 echo "${a}===> $f can't be included by itself${z}"
21 gcc -c $src
22 else
23 cat >$src <<EOF
24 #include "$f"
25 #include "$f"
26 void test_hdr_do_nothing(void) { }
27 EOF
28 if ! gcc -c $src 2>/dev/null; then
29 echo "${a}===> $f can't be included twice${z}"
30 gcc -c $src
31 fi
32 fi
33 done
34
35 rm $src $obj
36
37 echo checking config.h users...
38 # Make list of possible defines from config.h
39 defines=`grep \# config.h | cut -d# -f2 | cut -d' ' -f2`
40 defines=`echo $defines | tr ' ' '|'`
41
42 files=`ls *.[ch] | fgrep -v config.h`
43
44 # Check that files expecting defines from config.h include it.
45 for file in `egrep -l $defines $files`; do
46 if ! fgrep -q '#include "config.h"' $file; then
47 echo "${a}===> $file should include config.h${z}"
48 egrep $defines $file
49 fi
50 done
51
52 # And that others don't.
53 for file in `fgrep -l '#include "config.h"' *.[ch]`; do
54 if ! egrep -q $defines $file; then
55 echo "${a}===> $file should not include config.h${z}"
56 fi
57 done