15
15
# src/tools/pginclude/headerscheck
16
16
# Copyright (c) 2009-2024, PostgreSQL Global Development Group
17
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
+
18
26
if [ -z " $1 " ]; then
19
27
srcdir=" ."
20
28
else
29
37
30
38
me=` basename $0 `
31
39
40
+ # These switches are g++ specific, you may override if necessary.
41
+ CXXFLAGS=${CXXFLAGS:- -fsyntax-only -Wall}
42
+
32
43
# Pull some info from configure's results.
33
44
MGLOB=" $builddir /src/Makefile.global"
34
45
CPPFLAGS=` sed -n ' s/^CPPFLAGS[ ]*=[ ]*//p' " $MGLOB " `
35
46
CFLAGS=` sed -n ' s/^CFLAGS[ ]*=[ ]*//p' " $MGLOB " `
36
47
CC=` sed -n ' s/^CC[ ]*=[ ]*//p' " $MGLOB " `
48
+ CXX=` sed -n ' s/^CXX[ ]*=[ ]*//p' " $MGLOB " `
37
49
PG_SYSROOT=` sed -n ' s/^PG_SYSROOT[ ]*=[ ]*//p' " $MGLOB " `
38
50
perl_includespec=` sed -n ' s/^perl_includespec[ ]*=[ ]*//p' " $MGLOB " `
39
51
python_includespec=` sed -n ' s/^python_includespec[ ]*=[ ]*//p' " $MGLOB " `
@@ -43,6 +55,22 @@ CPPFLAGS=`echo "$CPPFLAGS" | sed "s|\\\$(PG_SYSROOT)|$PG_SYSROOT|g"`
43
55
44
56
# (EXTRAFLAGS is not set here, but user can pass it in if need be.)
45
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
+
46
74
# Create temp directory.
47
75
tmp=` mktemp -d /tmp/$me .XXXXXX`
48
76
69
97
# Additional Windows-specific headers.
70
98
test " $f " = src/include/port/win32_port.h && continue
71
99
test " $f " = src/include/port/win32/netdb.h && continue
100
+ $cplusplus && test " $f " = src/include/port/win32/sys/resource.h && continue
72
101
test " $f " = src/include/port/win32/sys/socket.h && continue
73
102
test " $f " = src/include/port/win32_msvc/dirent.h && continue
74
103
test " $f " = src/include/port/win32_msvc/utime.h && continue
134
163
test " $f " = src/test/isolation/specparse.h && continue
135
164
136
165
# This produces a "no previous prototype" warning.
137
- test " $f " = src/include/storage/checksum_impl.h && continue
166
+ ! $cplusplus && test " $f " = src/include/storage/checksum_impl.h && continue
138
167
139
168
# ppport.h is not under our control, so we can't make it standalone.
140
169
test " $f " = src/pl/plperl/ppport.h && continue
144
173
# printf_hack.h produces "unused function" warnings.
145
174
test " $f " = src/interfaces/ecpg/test/printf_hack.h && continue
146
175
176
+ if $cplusplus ; then
177
+ # pg_trace.h and utils/probes.h can include sys/sdt.h from SystemTap,
178
+ # which itself contains C++ code and so won't compile with a C++
179
+ # compiler under extern "C" linkage.
180
+ test " $f " = src/include/pg_trace.h && continue
181
+ test " $f " = src/include/utils/probes.h && continue
182
+
183
+ # pg_dump is not C++-clean because it uses "public" and "namespace"
184
+ # as field names, which is unfortunate but we won't change it now.
185
+ test " $f " = src/bin/pg_dump/compress_gzip.h && continue
186
+ test " $f " = src/bin/pg_dump/compress_io.h && continue
187
+ test " $f " = src/bin/pg_dump/compress_lz4.h && continue
188
+ test " $f " = src/bin/pg_dump/compress_none.h && continue
189
+ test " $f " = src/bin/pg_dump/compress_zstd.h && continue
190
+ test " $f " = src/bin/pg_dump/parallel.h && continue
191
+ test " $f " = src/bin/pg_dump/pg_backup_archiver.h && continue
192
+ test " $f " = src/bin/pg_dump/pg_dump.h && continue
193
+ fi
194
+
147
195
# OK, create .c file to include this .h file.
148
196
{
197
+ $cplusplus && echo ' extern "C" {'
149
198
# Ideally we'd pre-include only the appropriate one of
150
199
# postgres.h, postgres_fe.h, or c.h. We don't always have enough
151
200
# info to guess which, but in some subdirectories there's a
174
223
echo ' #include "postgres.h"' ;;
175
224
esac
176
225
echo " #include \" $f \" "
177
- } > $tmp /test.c
226
+ $cplusplus && echo ' };'
227
+ } > $tmp /test.$ext
178
228
179
229
# Some subdirectories need extra -I switches.
180
230
case " $f " in
193
243
esac
194
244
195
245
# Run the test.
196
- if ! ${CC :- gcc} $CPPFLAGS $CFLAGS -I $builddir -I $srcdir \
246
+ if ! $COMPILER $COMPILER_FLAGS -I $builddir -I $srcdir \
197
247
-I $builddir /src/include -I $srcdir /src/include \
198
248
-I $builddir /src/interfaces/libpq -I $srcdir /src/interfaces/libpq \
199
- $EXTRAINCLUDES $EXTRAFLAGS -c $tmp /test.c -o $tmp /test.o
249
+ $EXTRAINCLUDES $EXTRAFLAGS -c $tmp /test.$ext -o $tmp /test.o
200
250
then
201
251
exit_status=1
202
252
fi
0 commit comments