|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# Check (almost) all PostgreSQL include files for standalone build. |
| 4 | +# |
| 5 | +# Argument 1 is the top-level source directory, argument 2 the |
| 6 | +# top-level build directory (they might be the same). If not set, they |
| 7 | +# default to the current directory. |
| 8 | +# |
| 9 | +# Needs to be run after configuring and creating all generated headers. |
| 10 | +# It's advisable to configure --with-perl --with-python, else you're |
| 11 | +# likely to get errors from associated headers. |
| 12 | +# |
| 13 | +# No output if everything is OK, else compiler errors. |
| 14 | +# |
| 15 | +# src/tools/pginclude/headerscheck |
| 16 | +# Copyright (c) 2009-2019, PostgreSQL Global Development Group |
| 17 | + |
| 18 | +if [ -z "$1" ]; then |
| 19 | + srcdir="." |
| 20 | +else |
| 21 | + srcdir="$1" |
| 22 | +fi |
| 23 | + |
| 24 | +if [ -z "$2" ]; then |
| 25 | + builddir="." |
| 26 | +else |
| 27 | + builddir="$2" |
| 28 | +fi |
| 29 | + |
| 30 | +me=`basename $0` |
| 31 | + |
| 32 | +# Pull some info from configure's results. |
| 33 | +MGLOB="$builddir/src/Makefile.global" |
| 34 | +CPPFLAGS=`sed -n 's/^CPPFLAGS[ ]*=[ ]*//p' "$MGLOB"` |
| 35 | +CFLAGS=`sed -n 's/^CFLAGS[ ]*=[ ]*//p' "$MGLOB"` |
| 36 | +CC=`sed -n 's/^CC[ ]*=[ ]*//p' "$MGLOB"` |
| 37 | +PG_SYSROOT=`sed -n 's/^PG_SYSROOT[ ]*=[ ]*//p' "$MGLOB"` |
| 38 | +perl_includespec=`sed -n 's/^perl_includespec[ ]*=[ ]*//p' "$MGLOB"` |
| 39 | +python_includespec=`sed -n 's/^python_includespec[ ]*=[ ]*//p' "$MGLOB"` |
| 40 | + |
| 41 | +# needed on Darwin |
| 42 | +CPPFLAGS=`echo "$CPPFLAGS" | sed "s|\\\$(PG_SYSROOT)|$PG_SYSROOT|g"` |
| 43 | + |
| 44 | +# (EXTRAFLAGS is not set here, but user can pass it in if need be.) |
| 45 | + |
| 46 | +# Create temp directory. |
| 47 | +tmp=`mktemp -d /tmp/$me.XXXXXX` |
| 48 | + |
| 49 | +trap 'rm -rf $tmp' 0 1 2 3 15 |
| 50 | + |
| 51 | +# Scan all of src/ and contrib/ for header files. |
| 52 | +for f in `cd "$srcdir" && find src contrib -name '*.h' -print` |
| 53 | +do |
| 54 | + # Ignore files that are unportable or intentionally not standalone. |
| 55 | + |
| 56 | + # These files are platform-specific, and c.h will include the |
| 57 | + # one that's relevant for our current platform anyway. |
| 58 | + test "$f" = src/include/port/aix.h && continue |
| 59 | + test "$f" = src/include/port/cygwin.h && continue |
| 60 | + test "$f" = src/include/port/darwin.h && continue |
| 61 | + test "$f" = src/include/port/freebsd.h && continue |
| 62 | + test "$f" = src/include/port/hpux.h && continue |
| 63 | + test "$f" = src/include/port/linux.h && continue |
| 64 | + test "$f" = src/include/port/netbsd.h && continue |
| 65 | + test "$f" = src/include/port/openbsd.h && continue |
| 66 | + test "$f" = src/include/port/solaris.h && continue |
| 67 | + test "$f" = src/include/port/win32.h && continue |
| 68 | + |
| 69 | + # Additional Windows-specific headers. |
| 70 | + test "$f" = src/include/port/win32_port.h && continue |
| 71 | + test "$f" = src/include/port/win32/sys/socket.h && continue |
| 72 | + test "$f" = src/include/port/win32_msvc/dirent.h && continue |
| 73 | + test "$f" = src/port/pthread-win32.h && continue |
| 74 | + |
| 75 | + # Likewise, these files are platform-specific, and the one |
| 76 | + # relevant to our platform will be included by atomics.h. |
| 77 | + test "$f" = src/include/port/atomics/arch-arm.h && continue |
| 78 | + test "$f" = src/include/port/atomics/arch-hppa.h && continue |
| 79 | + test "$f" = src/include/port/atomics/arch-ia64.h && continue |
| 80 | + test "$f" = src/include/port/atomics/arch-ppc.h && continue |
| 81 | + test "$f" = src/include/port/atomics/arch-x86.h && continue |
| 82 | + test "$f" = src/include/port/atomics/fallback.h && continue |
| 83 | + test "$f" = src/include/port/atomics/generic.h && continue |
| 84 | + test "$f" = src/include/port/atomics/generic-acc.h && continue |
| 85 | + test "$f" = src/include/port/atomics/generic-gcc.h && continue |
| 86 | + test "$f" = src/include/port/atomics/generic-msvc.h && continue |
| 87 | + test "$f" = src/include/port/atomics/generic-sunpro.h && continue |
| 88 | + test "$f" = src/include/port/atomics/generic-xlc.h && continue |
| 89 | + |
| 90 | + # rusagestub.h is also platform-specific, and will be included |
| 91 | + # by utils/pg_rusage.h if necessary. |
| 92 | + test "$f" = src/include/rusagestub.h && continue |
| 93 | + |
| 94 | + # sepgsql.h depends on headers that aren't there on most platforms. |
| 95 | + test "$f" = contrib/sepgsql/sepgsql.h && continue |
| 96 | + |
| 97 | + # These files are not meant to be included standalone, because |
| 98 | + # they contain lists that might have multiple use-cases. |
| 99 | + test "$f" = src/include/access/rmgrlist.h && continue |
| 100 | + test "$f" = src/include/parser/kwlist.h && continue |
| 101 | + test "$f" = src/pl/plpgsql/src/pl_reserved_kwlist.h && continue |
| 102 | + test "$f" = src/pl/plpgsql/src/pl_unreserved_kwlist.h && continue |
| 103 | + test "$f" = src/interfaces/ecpg/preproc/c_kwlist.h && continue |
| 104 | + test "$f" = src/interfaces/ecpg/preproc/ecpg_kwlist.h && continue |
| 105 | + test "$f" = src/include/regex/regerrs.h && continue |
| 106 | + test "$f" = src/pl/plpgsql/src/plerrcodes.h && continue |
| 107 | + test "$f" = src/pl/plpython/spiexceptions.h && continue |
| 108 | + test "$f" = src/pl/tcl/pltclerrcodes.h && continue |
| 109 | + |
| 110 | + # We can't make these Bison output files compilable standalone |
| 111 | + # without using "%code require", which old Bison versions lack. |
| 112 | + # parser/gram.h will be included by parser/gramparse.h anyway. |
| 113 | + test "$f" = src/include/parser/gram.h && continue |
| 114 | + test "$f" = src/backend/parser/gram.h && continue |
| 115 | + test "$f" = src/pl/plpgsql/src/pl_gram.h && continue |
| 116 | + test "$f" = src/interfaces/ecpg/preproc/preproc.h && continue |
| 117 | + |
| 118 | + # This produces a "no previous prototype" warning. |
| 119 | + test "$f" = src/include/storage/checksum_impl.h && continue |
| 120 | + |
| 121 | + # ppport.h is not under our control, so we can't make it standalone. |
| 122 | + test "$f" = src/pl/plperl/ppport.h && continue |
| 123 | + |
| 124 | + # regression.h is not actually C, but ECPG code. |
| 125 | + test "$f" = src/interfaces/ecpg/test/regression.h && continue |
| 126 | + # printf_hack.h produces "unused function" warnings. |
| 127 | + test "$f" = src/interfaces/ecpg/test/printf_hack.h && continue |
| 128 | + |
| 129 | + # OK, create .c file to include this .h file. |
| 130 | + { |
| 131 | + test "$f" != src/include/postgres_fe.h && echo '#include "postgres.h"' |
| 132 | + echo "#include \"$f\"" |
| 133 | + } >$tmp/test.c |
| 134 | + |
| 135 | + # Some subdirectories need extra -I switches. |
| 136 | + case "$f" in |
| 137 | + src/pl/plperl/*) |
| 138 | + EXTRAINCLUDES="$perl_includespec" ;; |
| 139 | + src/pl/plpython/*) |
| 140 | + EXTRAINCLUDES="$python_includespec" ;; |
| 141 | + src/interfaces/ecpg/*) |
| 142 | + EXTRAINCLUDES="-I $builddir/src/interfaces/ecpg/include -I $srcdir/src/interfaces/ecpg/include" ;; |
| 143 | + *) |
| 144 | + EXTRAINCLUDES="" ;; |
| 145 | + esac |
| 146 | + |
| 147 | + # Run the test. |
| 148 | + ${CC:-gcc} $CPPFLAGS $CFLAGS -I $builddir -I $srcdir \ |
| 149 | + -I $builddir/src/include -I $srcdir/src/include \ |
| 150 | + -I $builddir/src/interfaces/libpq -I $srcdir/src/interfaces/libpq \ |
| 151 | + $EXTRAINCLUDES $EXTRAFLAGS -c $tmp/test.c -o $tmp/test.o |
| 152 | + |
| 153 | +done |
0 commit comments