]> granicus.if.org Git - postgresql/blob - src/tools/pginclude/pgnoinclude
37ef46c85af34507f2e90877887969fcb7c44bb4
[postgresql] / src / tools / pginclude / pgnoinclude
1 :
2 trap "rm -f /tmp/$$.c /tmp/$$.o /tmp/$$ /tmp/$$a /tmp/$$b" 0 1 2 3 15
3 find . \( -name CVS -a -prune \) -o -type f -print | grep -v '\./postgres.h' |
4 while read FILE
5 do
6         if [ "`echo $FILE | sed -n 's/^.*\.\([^\.]*\)$/\1/p'`" = "h" ]
7         then    IS_INCLUDE="Y"
8         else    IS_INCLUDE="N"
9         fi
10
11         if [ "$IS_INCLUDE" = "Y" ]
12         then    cat "$FILE" | grep -v "^#if" | grep -v "^#else" | 
13                 grep -v "^#endif" | sed 's/->[a-zA-Z0-9_\.]*//g' >/tmp/$$a
14         else    cat "$FILE" >/tmp/$$a
15         fi
16         cat /tmp/$$a | grep "^#include" |
17         sed 's/#include[        ]*[<"]\([^>"]*\).*$/\1/g' |
18         while read INCLUDE
19         do
20                 [ -s /usr/include/$INCLUDE ] && continue
21                 [ "$INCLUDE" = postgres.h ] && continue
22                 cat /tmp/$$a |
23                 grep -v '^#include[     ]*[<"]'"$INCLUDE"'[>"]' >/tmp/$$b
24                 if [ "$IS_INCLUDE" = "Y" ]
25                 then    echo "#include \"postgres.h\"" >/tmp/$$.c
26                 else    >/tmp/$$.c
27                 fi
28                 echo "#include \"/tmp/$$b\"" >>/tmp/$$.c
29                 echo "void include_test(void);" >>/tmp/$$.c
30                 echo "void include_test() {" >>/tmp/$$.c
31                 if [ "$IS_INCLUDE" = "Y" ]
32                 then    pgdefine "$FILE" >>/tmp/$$.c
33                 fi
34                 echo "}" >>/tmp/$$.c
35                 cc -fsyntax-only -Werror -Wall -Wmissing-prototypes -Wmissing-declarations -I/pg/include -I/pg/backend -c /tmp/$$.c -o /tmp/$$.o >/tmp/$$ 2>&1
36                 if [ "$?" -eq 0 ]
37                 then    echo "$FILE $INCLUDE"
38                         if [ "$IS_INCLUDE" = "N" ]
39                         then    grep -v '#include[      ]*[<"]$INCLUDE[>"]' $FILE >/tmp/$$b
40                                 mv /tmp/$$b "$FILE"
41                         fi
42                         if [ "$1" = "-v" ]
43                         then    cat /tmp/$$
44                                 cat /tmp/$$.c
45                         fi
46                 fi
47         done
48 done