]> granicus.if.org Git - postgresql/blob - src/tools/pginclude/pgrminclude
Improve pginclude tests.
[postgresql] / src / tools / pginclude / pgrminclude
1 :
2 # remove extra #include's
3
4 # $PostgreSQL: pgsql/src/tools/pginclude/pgrminclude,v 1.12 2006/07/11 20:51:25 momjian Exp $
5
6 trap "rm -f /tmp/$$.c /tmp/$$.o /tmp/$$ /tmp/$$a /tmp/$$b" 0 1 2 3 15
7 find . \( -name CVS -a -prune \) -o -type f -name '*.[ch]' -print | 
8 grep -v '\./postgres.h' |
9 grep -v '\./pg_config.h' |
10 grep -v '\./c.h' |
11 while read FILE
12 do
13         if [ `expr $FILE : '.*\.h$'` -ne 0 ]
14         then    IS_INCLUDE="Y"
15         else    IS_INCLUDE="N"
16         fi
17         
18         # remove defines
19         if [ "$IS_INCLUDE" = "Y" ]
20         then    cat "$FILE" | grep -v "^#if" | grep -v "^#else" | 
21                 grep -v "^#endif" | sed 's/->[a-zA-Z0-9_\.]*//g' >/tmp/$$a
22         else    cat "$FILE" >/tmp/$$a
23         fi
24
25         # loop through all includes
26         cat /tmp/$$a | grep "^#include" |
27         sed 's/^#include[       ]*[<"]\([^>"]*\).*$/\1/g' |
28         while read INCLUDE
29         do
30                 [ -s /usr/include/$INCLUDE ] && continue
31                 [ "$INCLUDE" = postgres.h ] && continue
32                 [ "$INCLUDE" = config.h ] && continue
33                 [ "$INCLUDE" = c.h ] && continue
34
35                 # preserve configure-specific includes
36                 # these includes are surrounded by #ifdef's
37                 grep -B1 '^#include[    ][      ]*[<"]'"$INCLUDE"'[>"]' "$FILE" |
38                      egrep -q '^#if|^#else' && continue
39                 grep -A1 '^#include[    ][      ]*[<"]'"$INCLUDE"'[>"]' "$FILE" |
40                      egrep -q '^#else|^#endif' && continue
41
42                 # set up initial file contents
43                 cat /tmp/$$a |
44                 grep -v '^#include[     ]*[<"]'"$INCLUDE"'[>"]' >/tmp/$$b
45                 if [ "$IS_INCLUDE" = "Y" ]
46                 then    echo "#include \"postgres.h\"" >/tmp/$$.c
47                 else    >/tmp/$$.c
48                 fi
49
50                 echo "#include \"/tmp/$$b\"" >>/tmp/$$.c
51                 echo "void include_test(void);" >>/tmp/$$.c
52                 echo "void include_test() {" >>/tmp/$$.c
53                 if [ "$IS_INCLUDE" = "Y" ]
54                 then    pgdefine "$FILE" >>/tmp/$$.c
55                 fi
56                 echo "}" >>/tmp/$$.c
57
58                 cc $CFLAGS -fsyntax-only -Werror -Wall -Wmissing-prototypes \
59                         -Wmissing-declarations -I/pg/include -I/pg/backend \
60                         -I/pg/interfaces/libpq -I`dirname $FILE` -c /tmp/$$.c \
61                         -o /tmp/$$.o >/tmp/$$ 2>&1
62                 if [ "$?" -eq 0 ]
63                 then    echo "$FILE $INCLUDE"
64                         if [ "$1" = "-v" ]
65                         then    cat /tmp/$$
66                                 cat /tmp/$$b
67                                 cat /tmp/$$.c
68                         fi
69                         grep -v '^#include[     ][      ]*[<"]'"$INCLUDE"'[>"]' "$FILE" >/tmp/$$b
70                         mv /tmp/$$b "$FILE"
71                 elif [ "$1" = "-v" ]
72                 then    echo "$FILE"
73                 fi
74
75         done
76 done