2 # remove extra #include's
4 # $PostgreSQL: pgsql/src/tools/pginclude/pgrminclude,v 1.12 2006/07/11 20:51:25 momjian Exp $
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' |
13 if [ `expr $FILE : '.*\.h$'` -ne 0 ]
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
25 # loop through all includes
26 cat /tmp/$$a | grep "^#include" |
27 sed 's/^#include[ ]*[<"]\([^>"]*\).*$/\1/g' |
30 [ -s /usr/include/$INCLUDE ] && continue
31 [ "$INCLUDE" = postgres.h ] && continue
32 [ "$INCLUDE" = config.h ] && continue
33 [ "$INCLUDE" = c.h ] && continue
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
42 # set up initial file contents
44 grep -v '^#include[ ]*[<"]'"$INCLUDE"'[>"]' >/tmp/$$b
45 if [ "$IS_INCLUDE" = "Y" ]
46 then echo "#include \"postgres.h\"" >/tmp/$$.c
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
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
63 then echo "$FILE $INCLUDE"
69 grep -v '^#include[ ][ ]*[<"]'"$INCLUDE"'[>"]' "$FILE" >/tmp/$$b