postgresql/src/tools/pginclude/pgnoinclude

55 lines
1.7 KiB
Plaintext
Raw Normal View History

:
trap "rm -f /tmp/$$.c /tmp/$$.o /tmp/$$ /tmp/$$a /tmp/$$b" 0 1 2 3 15
find . \( -name CVS -a -prune \) -o -type f -print | grep -v '\./postgres.h' |
1999-07-15 18:55:32 +02:00
while read FILE
do
1999-07-15 18:55:32 +02:00
if [ "`echo $FILE | sed -n 's/^.*\.\([^\.]*\)$/\1/p'`" = "h" ]
then IS_INCLUDE="Y"
else IS_INCLUDE="N"
fi
if [ "$IS_INCLUDE" = "Y" ]
then cat "$FILE" | grep -v "^#if" | grep -v "^#else" |
grep -v "^#endif" | sed 's/->[a-zA-Z0-9_\.]*//g' >/tmp/$$a
1999-07-15 18:55:32 +02:00
else cat "$FILE" >/tmp/$$a
fi
cat /tmp/$$a | grep "^#include" |
1999-07-15 22:32:30 +02:00
sed 's/^#include[ ]*[<"]\([^>"]*\).*$/\1/g' |
while read INCLUDE
do
[ -s /usr/include/$INCLUDE ] && continue
[ "$INCLUDE" = postgres.h ] && continue
cat /tmp/$$a |
grep -v '^#include[ ]*[<"]'"$INCLUDE"'[>"]' >/tmp/$$b
1999-07-15 18:55:32 +02:00
if [ "$IS_INCLUDE" = "Y" ]
then echo "#include \"postgres.h\"" >/tmp/$$.c
else >/tmp/$$.c
fi
echo "#include \"/tmp/$$b\"" >>/tmp/$$.c
echo "void include_test(void);" >>/tmp/$$.c
1999-07-15 18:55:32 +02:00
echo "void include_test() {" >>/tmp/$$.c
if [ "$IS_INCLUDE" = "Y" ]
then pgdefine "$FILE" >>/tmp/$$.c
fi
echo "}" >>/tmp/$$.c
cc -fsyntax-only -Werror -Wall -Wmissing-prototypes -Wmissing-declarations -I/pg/include -I/pg/backend -c /tmp/$$.c -o /tmp/$$.o >/tmp/$$ 2>&1
if [ "$?" -eq 0 ]
then echo "$FILE $INCLUDE"
1999-07-15 18:55:32 +02:00
if [ "$IS_INCLUDE" = "N" ]
1999-07-16 00:40:16 +02:00
then grep -v '^#include[ ][ ]*[<"]'"$INCLUDE"'[>"]' "$FILE" >/tmp/$$b
mv /tmp/$$b "$FILE"
1999-07-16 00:40:16 +02:00
# reload after #include removal
if [ "$IS_INCLUDE" = "Y" ]
then cat "$FILE" | grep -v "^#if" | grep -v "^#else" |
grep -v "^#endif" | sed 's/->[a-zA-Z0-9_\.]*//g' >/tmp/$$a
else cat "$FILE" >/tmp/$$a
fi
1999-07-15 18:55:32 +02:00
fi
if [ "$1" = "-v" ]
then cat /tmp/$$
cat /tmp/$$.c
fi
fi
done
done