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