Commit 94db6664 authored by Bruce Momjian's avatar Bruce Momjian

Modify pgrminclude -v to report include files that can't be compiled on

their own.

Avoid compile problems with defines being redefined after the removal of
the #if blocks.

Change script to use shell functions for simplicity.
parent a49fbaaf
...@@ -7,21 +7,22 @@ then echo "pgdefine must be in your PATH" 1>&2 ...@@ -7,21 +7,22 @@ then echo "pgdefine must be in your PATH" 1>&2
fi fi
trap "rm -f /tmp/$$.c /tmp/$$.o /tmp/$$ /tmp/$$a /tmp/$$b" 0 1 2 3 15 trap "rm -f /tmp/$$.c /tmp/$$.o /tmp/$$ /tmp/$$a /tmp/$$b" 0 1 2 3 15
# do include files first
(find . \( -name .git -a -prune \) -o -type f -name '*.h' -print; if [ "$1" = "-v" ]
find . \( -name .git -a -prune \) -o -type f -name '*.c' -print ) | then VERBOSE="Y"
grep -v '\./postgres.h' | else VERBOSE=""
grep -v '\./postgres_fe.h' | fi
grep -v '\./pg_config.h' |
grep -v '\./c.h' | verbose_output() {
while read FILE if [ "$VERBOSE" ]
do then cat /tmp/$$
if [ `expr $FILE : '.*\.h$'` -ne 0 ] cat /tmp/$$b
then IS_INCLUDE="Y" nl /tmp/$$.c
else IS_INCLUDE="N"
fi fi
}
# loop through all includes process_includes_in_file() {
# loop through all includes mentioned in the file
cat "$FILE" | cat "$FILE" |
grep "^#include\>" | grep "^#include\>" |
grep -v '/\* *pgrminclude *ignore *\*/' | grep -v '/\* *pgrminclude *ignore *\*/' |
...@@ -29,65 +30,97 @@ do ...@@ -29,65 +30,97 @@ do
grep -v 'parser/kwlist\.h' | grep -v 'parser/kwlist\.h' |
grep -v '\.c$' | grep -v '\.c$' |
while read INCLUDE while read INCLUDE
do do if [ "$VERBOSE" ]
if [ "$1" = "-v" ]
then echo "checking $FILE $INCLUDE" then echo "checking $FILE $INCLUDE"
fi fi
compile_file
done
}
[ -s /usr/include/$INCLUDE ] && continue compile_file() {
[ "$INCLUDE" = postgres.h ] && continue [ "$INCLUDE" -a -s /usr/include/"$INCLUDE" ] && continue
[ "$INCLUDE" = postgres_fe.h ] && continue [ "$INCLUDE" = "postgres.h" ] && continue
[ "$INCLUDE" = pg_config.h ] && continue [ "$INCLUDE" = "postgres_fe.h" ] && continue
[ "$INCLUDE" = c.h ] && continue [ "$INCLUDE" = "pg_config.h" ] && continue
[ "$INCLUDE" = "c.h" ] && continue
# preserve configure-specific includes # preserve configure-specific includes
# these includes are surrounded by #ifdef's # these includes are surrounded by #ifdef's
grep -B1 '^#include[ ][ ]*[<"]'"$INCLUDE"'[>"]' "$FILE" | grep -B1 '^#include[ ][ ]*[<"]'"$INCLUDE"'[>"]' "$FILE" |
egrep -q '^#if|^#else|^#elif' && continue egrep -q '^#if|^#else|^#elif' && continue
grep -A1 '^#include[ ][ ]*[<"]'"$INCLUDE"'[>"]' "$FILE" | grep -A1 '^#include[ ][ ]*[<"]'"$INCLUDE"'[>"]' "$FILE" |
egrep -q '^#else|^#elif|^#endif' && continue egrep -q '^#else|^#elif|^#endif' && continue
# Remove all #if and #ifdef blocks because the blocks # Remove all #if and #ifdef blocks because the blocks
# might contain code that is not compiled on this platform. # might contain code that is not compiled on this platform.
cat "$FILE" | cat "$FILE" |
grep -v "^#if" | grep -v "^#if" |
grep -v "^#else" | grep -v "^#else" |
grep -v "^#elif" | grep -v "^#elif" |
grep -v "^#endif" >/tmp/$$a grep -v "^#endif" |
# with #if blocks gone, now undef #defines to avoid redefine
# warning and failure
sed 's/#define[ ][ ]*\([A-Za-z0-9_]*\).*$/#undef \1\n&/' >/tmp/$$a
# set up initial file contents # set up initial file contents
grep -v '^#include[ ][ ]*[<"]'"$INCLUDE"'[>"]' \ grep -v '^#include[ ][ ]*[<"]'"$INCLUDE"'[>"]' \
/tmp/$$a >/tmp/$$b /tmp/$$a >/tmp/$$b
if [ "$IS_INCLUDE" = "Y" ] if [ "$IS_INCLUDE" = "Y" ]
then echo "#include \"postgres.h\"" >/tmp/$$.c then echo "#include \"postgres.h\"" >/tmp/$$.c
else >/tmp/$$.c else >/tmp/$$.c
fi fi
echo "#include \"/tmp/$$b\"" >>/tmp/$$.c echo "#include \"/tmp/$$b\"" >>/tmp/$$.c
echo "void include_test(void);" >>/tmp/$$.c # supress fcinfo errors
echo "void include_test() {" >>/tmp/$$.c echo "#undef PG_GETARG_DATUM" >>/tmp/$$.c
if [ "$IS_INCLUDE" = "Y" ] echo "#define PG_GETARG_DATUM(n)" >>/tmp/$$.c
then pgdefine "$FILE" >>/tmp/$$.c echo "void include_test(void);" >>/tmp/$$.c
fi echo "void include_test() {" >>/tmp/$$.c
echo "}" >>/tmp/$$.c if [ "$IS_INCLUDE" = "Y" ]
then pgdefine "$FILE" >>/tmp/$$.c
fi
echo "}" >>/tmp/$$.c
# Use -O1 to get warnings only generated by optimization, # Use -O1 to get warnings only generated by optimization,
# but -O2 is too slow. # but -O2 is too slow.
cc -fsyntax-only -Werror -Wall -Wmissing-prototypes \ cc -fsyntax-only -Werror -Wall -Wmissing-prototypes \
-Wmissing-declarations -I/pg/include -I/pg/backend \ -Wmissing-declarations -I/pg/include -I/pg/backend \
-I/pg/interfaces/libpq -I`dirname $FILE` $CFLAGS -O1 -c /tmp/$$.c \ -I/pg/interfaces/libpq -I`dirname $FILE` $CFLAGS -O1 -c /tmp/$$.c \
-o /tmp/$$.o >/tmp/$$ 2>&1 -o /tmp/$$.o >/tmp/$$ 2>&1
if [ "$?" -eq 0 ] if [ "$?" -eq 0 ]
then echo "$FILE $INCLUDE" then [ "$INCLUDE" -o "$VERBOSE" ] && echo "$FILE $INCLUDE"
if [ "$1" = "-v" ] grep -v '^#include[ ][ ]*[<"]'"$INCLUDE"'[>"]' \
then cat /tmp/$$ "$FILE" >/tmp/$$b
cat /tmp/$$b mv /tmp/$$b "$FILE"
cat /tmp/$$.c return 0
fi else return 1
grep -v '^#include[ ][ ]*[<"]'"$INCLUDE"'[>"]' \ fi
"$FILE" >/tmp/$$b }
mv /tmp/$$b "$FILE"
fi # Process include files first because they can affect the compilation
done # of *.c files.
(find . \( -name .git -a -prune \) -o -type f -name '*.h' -print;
find . \( -name .git -a -prune \) -o -type f -name '*.c' -print ) |
grep -v '/postgres.h$' |
grep -v '/postgres_fe.h$' |
grep -v '/pg_config.h$' |
grep -v '\./c.h$' |
while read FILE
do
if [ `expr $FILE : '.*\.h$'` -ne 0 ]
then IS_INCLUDE="Y"
else IS_INCLUDE="N"
fi
# Can we compile the file with all existing includes?
INCLUDE=""
compile_file
# If the file can't be compiled on its own, there is no sense
# trying to remove the include files.
if [ "$?" -ne 0 ]
then echo "cannot compile $FILE with existing includes"
verbose_output
else process_includes_in_file
fi
done done
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment