Mention battery-backed cache under hardware selection options.
[PostgreSQL.git] / src / tools / pginclude / pgrminclude
blob70e9683ab406093be9926df3dcc376ef00a72cd1
2 # remove extra #include's
4 # $PostgreSQL$
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
13         if [ `expr $FILE : '.*\.h$'` -ne 0 ]
14         then    IS_INCLUDE="Y"
15         else    IS_INCLUDE="N"
16         fi
17         
18         # loop through all includes
19         cat "$FILE" | grep "^#include" |
20         sed 's/^#include[       ]*[<"]\([^>"]*\).*$/\1/g' |
21         while read INCLUDE
22         do
23                 if [ "$1" = "-v" ]
24                 then    echo "checking $FILE $INCLUDE"
25                 fi
27                 [ -s /usr/include/$INCLUDE ] && continue
28                 [ "$INCLUDE" = postgres.h ] && continue
29                 [ "$INCLUDE" = postgres_fe.h ] && continue
30                 [ "$INCLUDE" = config.h ] && continue
31                 [ "$INCLUDE" = c.h ] && continue
33                 # preserve configure-specific includes
34                 # these includes are surrounded by #ifdef's
35                 grep -B1 '^#include[    ][      ]*[<"]'"$INCLUDE"'[>"]' "$FILE" |
36                      egrep -q '^#if|^#else' && continue
37                 grep -A1 '^#include[    ][      ]*[<"]'"$INCLUDE"'[>"]' "$FILE" |
38                      egrep -q '^#else|^#endif' && continue
40                 # remove defines from include files
41                 if [ "$IS_INCLUDE" = "Y" ]
42                 then    cat "$FILE" | grep -v "^#if" | grep -v "^#else" | 
43                         grep -v "^#endif" | sed 's/->[a-zA-Z0-9_\.]*//g' >/tmp/$$a
44                 else    cat "$FILE" >/tmp/$$a
45                 fi
47                 # set up initial file contents
48                 grep -v '^#include[     ][      ]*[<"]'"$INCLUDE"'[>"]' \
49                         /tmp/$$a >/tmp/$$b
51                 if [ "$IS_INCLUDE" = "Y" ]
52                 then    echo "#include \"postgres.h\"" >/tmp/$$.c
53                 else    >/tmp/$$.c
54                 fi
56                 echo "#include \"/tmp/$$b\"" >>/tmp/$$.c
57                 echo "void include_test(void);" >>/tmp/$$.c
58                 echo "void include_test() {" >>/tmp/$$.c
59                 if [ "$IS_INCLUDE" = "Y" ]
60                 then    pgdefine "$FILE" >>/tmp/$$.c
61                 fi
62                 echo "}" >>/tmp/$$.c
64                 cc -fsyntax-only -Werror -Wall -Wmissing-prototypes \
65                         -Wmissing-declarations -I/pg/include -I/pg/backend \
66                         -I/pg/interfaces/libpq -I`dirname $FILE` $CFLAGS -c /tmp/$$.c \
67                         -o /tmp/$$.o >/tmp/$$ 2>&1
68                 if [ "$?" -eq 0 ]
69                 then    echo "$FILE $INCLUDE"
70                         if [ "$1" = "-v" ]
71                         then    cat /tmp/$$
72                                 cat /tmp/$$b
73                                 cat /tmp/$$.c
74                         fi
75                         grep -v '^#include[     ][      ]*[<"]'"$INCLUDE"'[>"]' \
76                                 "$FILE" >/tmp/$$b
77                         mv /tmp/$$b "$FILE"
78                 fi
79         done
80 done