postgresql/src/tools/pginclude/cpluspluscheck

61 lines
1.9 KiB
Bash
Executable File

#!/bin/sh
# Check all exported PostgreSQL include files for C++ compatibility.
#
# Argument 1 is the top-level source directory, argument 2 the
# top-level build directory (they might be the same). If not set, they
# default to the current directory.
#
# Needs to be run after all generated headers are created.
#
# No output if everything is OK, else compiler errors.
if [ -z "$1" ];then
srcdir="."
else
srcdir="$1"
fi
if [ -z "$2" ];then
builddir="$."
else
builddir="$2"
fi
me=`basename $0`
tmp=`mktemp -d /tmp/$me.XXXXXX`
trap 'rm -rf $tmp' 0 1 2 3 15
# Omit src/include/port/, because it's platform specific, and c.h includes
# the relevant file anyway.
# rusagestub.h is also platform-specific, and will be included by
# utils/pg_rusage.h if necessary.
# access/rmgrlist.h is not meant to be included standalone.
# regex/regerrs.h is not meant to be included standalone.
# parser/gram.h will be included by parser/gramparse.h.
# parser/kwlist.h is not meant to be included standalone.
# pg_trace.h and utils/probes.h can include sys/sdt.h from SystemTap,
# which itself contains C++ code and so won't compile with a C++
# compiler under extern "C" linkage.
for f in `cd "$srcdir" && find src/include src/interfaces/libpq/libpq-fe.h src/interfaces/libpq/libpq-events.h -name '*.h' -print | \
grep -v -e ^src/include/port/ \
-e ^src/include/rusagestub.h -e ^src/include/regex/regerrs.h \
-e ^src/include/access/rmgrlist.h \
-e ^src/include/parser/gram.h -e ^src/include/parser/kwlist.h \
-e ^src/include/pg_trace.h -e ^src/include/utils/probes.h`
do
{
echo ' extern "C" {'
test $f != "src/include/postgres_fe.h" && echo '#include "postgres.h"'
echo "#include \"$f\""
echo '};'
} >$tmp/test.cpp
${CXX:-g++} -I $srcdir -I $srcdir/src/interfaces/libpq -I $srcdir/src/include \
-I $builddir -I $builddir/src/interfaces/libpq -I $builddir/src/include \
-fsyntax-only -Wall -c $tmp/test.cpp
done