| 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-2025, PostgreSQL Global Development Group |
| 17 |
|
| 18 |
# option to check for C++ compatibility |
| 19 |
if [ "$1" = "--cplusplus" ]; then |
| 20 |
cplusplus=true |
| 21 |
shift |
| 22 |
else |
| 23 |
cplusplus=false |
| 24 |
fi |
| 25 |
|
| 26 |
if [ -z "$1" ]; then |
| 27 |
srcdir="." |
| 28 |
else |
| 29 |
srcdir="$1" |
| 30 |
fi |
| 31 |
|
| 32 |
if [ -z "$2" ]; then |
| 33 |
builddir="." |
| 34 |
else |
| 35 |
builddir="$2" |
| 36 |
fi |
| 37 |
|
| 38 |
me=`basename $0` |
| 39 |
|
| 40 |
# These switches are g++ specific, you may override if necessary. |
| 41 |
CXXFLAGS=${CXXFLAGS:- -fsyntax-only -Wall} |
| 42 |
|
| 43 |
# Pull some info from configure's results. |
| 44 |
MGLOB="$builddir/src/Makefile.global" |
| 45 |
CPPFLAGS=`sed -n 's/^CPPFLAGS[ ]*=[ ]*//p' "$MGLOB"` |
| 46 |
CFLAGS=`sed -n 's/^CFLAGS[ ]*=[ ]*//p' "$MGLOB"` |
| 47 |
CC=`sed -n 's/^CC[ ]*=[ ]*//p' "$MGLOB"` |
| 48 |
CXX=`sed -n 's/^CXX[ ]*=[ ]*//p' "$MGLOB"` |
| 49 |
PG_SYSROOT=`sed -n 's/^PG_SYSROOT[ ]*=[ ]*//p' "$MGLOB"` |
| 50 |
perl_includespec=`sed -n 's/^perl_includespec[ ]*=[ ]*//p' "$MGLOB"` |
| 51 |
python_includespec=`sed -n 's/^python_includespec[ ]*=[ ]*//p' "$MGLOB"` |
| 52 |
|
| 53 |
# needed on Darwin |
| 54 |
CPPFLAGS=`echo "$CPPFLAGS" | sed "s|\\\$(PG_SYSROOT)|$PG_SYSROOT|g"` |
| 55 |
|
| 56 |
# (EXTRAFLAGS is not set here, but user can pass it in if need be.) |
| 57 |
|
| 58 |
if $cplusplus; then |
| 59 |
ext=cpp |
| 60 |
COMPILER=${CXX:-g++} |
| 61 |
# Extract any -I and -D switches from CPPFLAGS. |
| 62 |
for flag in $CPPFLAGS; do |
| 63 |
case $flag in |
| 64 |
-I*|-D*) CXXPPFLAGS="$CXXPPFLAGS $flag";; |
| 65 |
esac |
| 66 |
done |
| 67 |
COMPILER_FLAGS="$CXXPPFLAGS $CXXFLAGS" |
| 68 |
else |
| 69 |
ext=c |
| 70 |
COMPILER=${CC:-gcc} |
| 71 |
COMPILER_FLAGS="$CPPFLAGS $CFLAGS" |
| 72 |
fi |
| 73 |
|
| 74 |
# Create temp directory. |
| 75 |
tmp=`mktemp -d /tmp/$me.XXXXXX` |
| 76 |
|
| 77 |
trap "ret=$?; rm -rf $tmp; exit $ret" 0 1 2 3 15 |
| 78 |
|
| 79 |
exit_status=0 |
| 80 |
|
| 81 |
# Scan all of src/ and contrib/ for header files. |
| 82 |
for f in `cd "$srcdir" && find src contrib -name '*.h' -print` |
| 83 |
do |
| 84 |
# Ignore files that are unportable or intentionally not standalone. |
| 85 |
|
| 86 |
# These files are platform-specific, and c.h will include the |
| 87 |
# one that's relevant for our current platform anyway. |
| 88 |
test "$f" = src/include/port/cygwin.h && continue |
| 89 |
test "$f" = src/include/port/darwin.h && continue |
| 90 |
test "$f" = src/include/port/freebsd.h && continue |
| 91 |
test "$f" = src/include/port/linux.h && continue |
| 92 |
test "$f" = src/include/port/netbsd.h && continue |
| 93 |
test "$f" = src/include/port/openbsd.h && continue |
| 94 |
test "$f" = src/include/port/solaris.h && continue |
| 95 |
test "$f" = src/include/port/win32.h && continue |
| 96 |
|
| 97 |
# Additional Windows-specific headers. |
| 98 |
test "$f" = src/include/port/win32_port.h && continue |
| 99 |
test "$f" = src/include/port/win32/netdb.h && continue |
| 100 |
$cplusplus && test "$f" = src/include/port/win32/sys/resource.h && continue |
| 101 |
test "$f" = src/include/port/win32/sys/socket.h && continue |
| 102 |
test "$f" = src/include/port/win32_msvc/dirent.h && continue |
| 103 |
test "$f" = src/include/port/win32_msvc/utime.h && continue |
| 104 |
test "$f" = src/include/port/win32ntdll.h && continue |
| 105 |
test "$f" = src/port/pthread-win32.h && continue |
| 106 |
|
| 107 |
# Likewise, these files are platform-specific, and the one |
| 108 |
# relevant to our platform will be included by atomics.h. |
| 109 |
test "$f" = src/include/port/atomics/arch-arm.h && continue |
| 110 |
test "$f" = src/include/port/atomics/arch-ppc.h && continue |
| 111 |
test "$f" = src/include/port/atomics/arch-x86.h && continue |
| 112 |
test "$f" = src/include/port/atomics/fallback.h && continue |
| 113 |
test "$f" = src/include/port/atomics/generic.h && continue |
| 114 |
test "$f" = src/include/port/atomics/generic-gcc.h && continue |
| 115 |
test "$f" = src/include/port/atomics/generic-msvc.h && continue |
| 116 |
test "$f" = src/include/port/atomics/generic-sunpro.h && continue |
| 117 |
|
| 118 |
# sepgsql.h depends on headers that aren't there on most platforms. |
| 119 |
test "$f" = contrib/sepgsql/sepgsql.h && continue |
| 120 |
|
| 121 |
# nodetags.h cannot be included standalone: it's just a code fragment. |
| 122 |
test "$f" = src/include/nodes/nodetags.h && continue |
| 123 |
test "$f" = src/backend/nodes/nodetags.h && continue |
| 124 |
|
| 125 |
# These files are not meant to be included standalone, because |
| 126 |
# they contain lists that might have multiple use-cases. |
| 127 |
test "$f" = src/include/access/rmgrlist.h && continue |
| 128 |
test "$f" = src/include/parser/kwlist.h && continue |
| 129 |
test "$f" = src/pl/plpgsql/src/pl_reserved_kwlist.h && continue |
| 130 |
test "$f" = src/pl/plpgsql/src/pl_unreserved_kwlist.h && continue |
| 131 |
test "$f" = src/interfaces/ecpg/preproc/c_kwlist.h && continue |
| 132 |
test "$f" = src/interfaces/ecpg/preproc/ecpg_kwlist.h && continue |
| 133 |
test "$f" = src/include/regex/regerrs.h && continue |
| 134 |
test "$f" = src/include/storage/lwlocklist.h && continue |
| 135 |
test "$f" = src/include/tcop/cmdtaglist.h && continue |
| 136 |
test "$f" = src/pl/plpgsql/src/plerrcodes.h && continue |
| 137 |
test "$f" = src/pl/plpython/spiexceptions.h && continue |
| 138 |
test "$f" = src/pl/tcl/pltclerrcodes.h && continue |
| 139 |
|
| 140 |
# Also not meant to be included standalone. |
| 141 |
test "$f" = contrib/isn/EAN13.h && continue |
| 142 |
test "$f" = contrib/isn/ISBN.h && continue |
| 143 |
test "$f" = contrib/isn/ISMN.h && continue |
| 144 |
test "$f" = contrib/isn/ISSN.h && continue |
| 145 |
test "$f" = contrib/isn/UPC.h && continue |
| 146 |
|
| 147 |
test "$f" = src/include/common/unicode_nonspacing_table.h && continue |
| 148 |
test "$f" = src/include/common/unicode_east_asian_fw_table.h && continue |
| 149 |
|
| 150 |
test "$f" = src/include/catalog/syscache_ids.h && continue |
| 151 |
test "$f" = src/include/catalog/syscache_info.h && continue |
| 152 |
|
| 153 |
# We can't make these Bison output files compilable standalone |
| 154 |
# without using "%code require", which old Bison versions lack. |
| 155 |
# parser/gram.h will be included by parser/gramparse.h anyway. |
| 156 |
test "$f" = contrib/cube/cubeparse.h && continue |
| 157 |
test "$f" = contrib/seg/segparse.h && continue |
| 158 |
test "$f" = src/backend/bootstrap/bootparse.h && continue |
| 159 |
test "$f" = src/backend/parser/gram.h && continue |
| 160 |
test "$f" = src/backend/replication/repl_gram.h && continue |
| 161 |
test "$f" = src/backend/replication/syncrep_gram.h && continue |
| 162 |
test "$f" = src/backend/utils/adt/jsonpath_gram.h && continue |
| 163 |
test "$f" = src/bin/pgbench/exprparse.h && continue |
| 164 |
test "$f" = src/pl/plpgsql/src/pl_gram.h && continue |
| 165 |
test "$f" = src/interfaces/ecpg/preproc/preproc.h && continue |
| 166 |
test "$f" = src/test/isolation/specparse.h && continue |
| 167 |
|
| 168 |
# This produces a "no previous prototype" warning. |
| 169 |
! $cplusplus && test "$f" = src/include/storage/checksum_impl.h && continue |
| 170 |
|
| 171 |
# SectionMemoryManager.h is C++ |
| 172 |
test "$f" = src/include/jit/SectionMemoryManager.h && continue |
| 173 |
|
| 174 |
# ppport.h is not under our control, so we can't make it standalone. |
| 175 |
test "$f" = src/pl/plperl/ppport.h && continue |
| 176 |
|
| 177 |
# regression.h is not actually C, but ECPG code. |
| 178 |
test "$f" = src/interfaces/ecpg/test/regression.h && continue |
| 179 |
# printf_hack.h produces "unused function" warnings. |
| 180 |
test "$f" = src/interfaces/ecpg/test/printf_hack.h && continue |
| 181 |
|
| 182 |
if $cplusplus; then |
| 183 |
# pg_trace.h and utils/probes.h can include sys/sdt.h from SystemTap, |
| 184 |
# which itself contains C++ code and so won't compile with a C++ |
| 185 |
# compiler under extern "C" linkage. |
| 186 |
test "$f" = src/include/pg_trace.h && continue |
| 187 |
test "$f" = src/include/utils/probes.h && continue |
| 188 |
|
| 189 |
# pg_dump is not C++-clean because it uses "public" and "namespace" |
| 190 |
# as field names, which is unfortunate but we won't change it now. |
| 191 |
test "$f" = src/bin/pg_dump/compress_gzip.h && continue |
| 192 |
test "$f" = src/bin/pg_dump/compress_io.h && continue |
| 193 |
test "$f" = src/bin/pg_dump/compress_lz4.h && continue |
| 194 |
test "$f" = src/bin/pg_dump/compress_none.h && continue |
| 195 |
test "$f" = src/bin/pg_dump/compress_zstd.h && continue |
| 196 |
test "$f" = src/bin/pg_dump/parallel.h && continue |
| 197 |
test "$f" = src/bin/pg_dump/pg_backup_archiver.h && continue |
| 198 |
test "$f" = src/bin/pg_dump/pg_dump.h && continue |
| 199 |
fi |
| 200 |
|
| 201 |
# OK, create .c file to include this .h file. |
| 202 |
{ |
| 203 |
$cplusplus && echo 'extern "C" {' |
| 204 |
# Ideally we'd pre-include only the appropriate one of |
| 205 |
# postgres.h, postgres_fe.h, or c.h. We don't always have enough |
| 206 |
# info to guess which, but in some subdirectories there's a |
| 207 |
# reasonable choice to make, and otherwise we use postgres.h. |
| 208 |
# Also, those three files should compile with no pre-include, as |
| 209 |
# should src/interfaces headers meant to be exposed to clients. |
| 210 |
case "$f" in |
| 211 |
src/include/postgres.h) ;; |
| 212 |
src/include/postgres_fe.h) ;; |
| 213 |
src/include/c.h) ;; |
| 214 |
src/interfaces/libpq/libpq-fe.h) ;; |
| 215 |
src/interfaces/libpq/libpq-events.h) ;; |
| 216 |
src/interfaces/ecpg/ecpglib/ecpglib_extern.h) |
| 217 |
echo '#include "postgres_fe.h"' ;; |
| 218 |
src/interfaces/ecpg/ecpglib/*) ;; |
| 219 |
src/interfaces/*) |
| 220 |
echo '#include "postgres_fe.h"' ;; |
| 221 |
src/bin/*) |
| 222 |
echo '#include "postgres_fe.h"' ;; |
| 223 |
src/fe_utils/*) |
| 224 |
echo '#include "postgres_fe.h"' ;; |
| 225 |
src/port/*) ;; |
| 226 |
src/common/*) |
| 227 |
echo '#include "c.h"' ;; |
| 228 |
*) |
| 229 |
echo '#include "postgres.h"' ;; |
| 230 |
esac |
| 231 |
echo "#include \"$f\"" |
| 232 |
$cplusplus && echo '};' |
| 233 |
} >$tmp/test.$ext |
| 234 |
|
| 235 |
# Some subdirectories need extra -I switches. |
| 236 |
case "$f" in |
| 237 |
src/pl/plperl/*) |
| 238 |
EXTRAINCLUDES="$perl_includespec" ;; |
| 239 |
src/pl/plpython/*) |
| 240 |
EXTRAINCLUDES="$python_includespec" ;; |
| 241 |
src/interfaces/ecpg/*) |
| 242 |
EXTRAINCLUDES="-I $builddir/src/interfaces/ecpg/include -I $srcdir/src/interfaces/ecpg/include" ;; |
| 243 |
src/backend/parser/*) |
| 244 |
EXTRAINCLUDES="-I $builddir/src/backend/parser/" ;; |
| 245 |
src/backend/utils/adt/*) |
| 246 |
EXTRAINCLUDES="-I $builddir/src/backend/utils/adt/" ;; |
| 247 |
*) |
| 248 |
EXTRAINCLUDES="" ;; |
| 249 |
esac |
| 250 |
|
| 251 |
# Run the test. |
| 252 |
if ! $COMPILER $COMPILER_FLAGS -I $builddir -I $srcdir \ |
| 253 |
-I $builddir/src/include -I $srcdir/src/include \ |
| 254 |
-I $builddir/src/interfaces/libpq -I $srcdir/src/interfaces/libpq \ |
| 255 |
$EXTRAINCLUDES $EXTRAFLAGS -c $tmp/test.$ext -o $tmp/test.o |
| 256 |
then |
| 257 |
exit_status=1 |
| 258 |
fi |
| 259 |
done |
| 260 |
|
| 261 |
exit $exit_status |