1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
pgport_sources = [
'bsearch_arg.c',
'chklocale.c',
'inet_net_ntop.c',
'noblock.c',
'path.c',
'pg_bitutils.c',
'pg_strong_random.c',
'pgcheckdir.c',
'pgmkdirp.c',
'pgsleep.c',
'pgstrcasecmp.c',
'pgstrsignal.c',
'pqsignal.c',
'qsort.c',
'qsort_arg.c',
'quotes.c',
'snprintf.c',
'strerror.c',
'tar.c',
'thread.c',
]
if host_system == 'windows'
pgport_sources += files(
'dirmod.c',
'kill.c',
'open.c',
'system.c',
'win32common.c',
'win32dlopen.c',
'win32env.c',
'win32error.c',
'win32fdatasync.c',
'win32fseek.c',
'win32gai_strerror.c',
'win32getrusage.c',
'win32link.c',
'win32ntdll.c',
'win32pread.c',
'win32pwrite.c',
'win32security.c',
'win32setlocale.c',
'win32stat.c',
)
elif host_system == 'cygwin'
pgport_sources += files(
'dirmod.c',
)
endif
if cc.get_id() == 'msvc'
pgport_sources += files(
'dirent.c',
'win32gettimeofday.c',
)
endif
# Replacement functionality to be built if corresponding configure symbol
# is false
replace_funcs_neg = [
['explicit_bzero'],
['getopt'],
['getopt_long'],
['getpeereid'],
['inet_aton'],
['mkdtemp'],
['preadv', 'HAVE_DECL_PREADV'],
['pwritev', 'HAVE_DECL_PWRITEV'],
['strlcat'],
['strlcpy'],
['strnlen'],
]
if host_system != 'windows'
replace_funcs_neg += [['pthread_barrier_wait']]
endif
# Replacement functionality to be built if corresponding configure symbol
# is true
replace_funcs_pos = [
# x86/x64
['pg_crc32c_sse42', 'USE_SSE42_CRC32C'],
['pg_crc32c_sse42', 'USE_SSE42_CRC32C_WITH_RUNTIME_CHECK', 'crc'],
['pg_crc32c_sse42_choose', 'USE_SSE42_CRC32C_WITH_RUNTIME_CHECK'],
['pg_crc32c_sb8', 'USE_SSE42_CRC32C_WITH_RUNTIME_CHECK'],
# arm / aarch64
['pg_crc32c_armv8', 'USE_ARMV8_CRC32C'],
['pg_crc32c_armv8', 'USE_ARMV8_CRC32C_WITH_RUNTIME_CHECK', 'crc'],
['pg_crc32c_armv8_choose', 'USE_ARMV8_CRC32C_WITH_RUNTIME_CHECK'],
['pg_crc32c_sb8', 'USE_ARMV8_CRC32C_WITH_RUNTIME_CHECK'],
# generic fallback
['pg_crc32c_sb8', 'USE_SLICING_BY_8_CRC32C'],
]
pgport_cflags = {'crc': cflags_crc}
pgport_sources_cflags = {'crc': []}
foreach f : replace_funcs_neg
func = f.get(0)
varname = f.get(1, 'HAVE_@0@'.format(func.to_upper()))
filename = '@0@.c'.format(func)
val = '@0@'.format(cdata.get(varname, 'false'))
if val == 'false' or val == '0'
pgport_sources += files(filename)
endif
endforeach
foreach f : replace_funcs_pos
func = f.get(0)
varname = f.get(1, 'HAVE_@0@'.format(func.to_upper()))
filename = '@0@.c'.format(func)
val = '@0@'.format(cdata.get(varname, 'false'))
if val == 'true' or val == '1'
src = files(filename)
if f.length() > 2
pgport_sources_cflags += {f[2]: pgport_sources_cflags[f[2]] + src}
else
pgport_sources += src
endif
endif
endforeach
if (host_system == 'windows' or host_system == 'cygwin') and \
(cc.get_id() != 'msvc' or cc.version().version_compare('<14.0'))
# Cygwin and (apparently, based on test results) Mingw both
# have a broken strtof(), so substitute its implementation.
# That's not a perfect fix, since it doesn't avoid double-rounding,
# but we have no better options.
pgport_sources += files('strtof.c')
message('On @0@ with compiler @1@ @2@ we will use our strtof wrapper.'.format(
host_system, cc.get_id(), cc.version()))
endif
# Build pgport once for backend, once for use in frontend binaries, and once
# for use in shared libraries
pgport = {}
pgport_variants = {
'_srv': internal_lib_args + {
'dependencies': [backend_port_code],
},
'': default_lib_args + {
'dependencies': [frontend_port_code],
},
'_shlib': default_lib_args + {
'pic': true,
'dependencies': [frontend_port_code],
},
}
foreach name, opts : pgport_variants
# Build internal static libraries for sets of files that need to be built
# with different cflags
cflag_libs = []
foreach cflagname, sources : pgport_sources_cflags
if sources.length() == 0
continue
endif
c_args = opts.get('c_args', []) + pgport_cflags[cflagname]
cflag_libs += static_library('libpgport@0@_@1@'.format(name, cflagname),
sources,
c_pch: pch_c_h,
kwargs: opts + {
'c_args': c_args,
'build_by_default': false,
'install': false,
},
)
endforeach
lib = static_library('libpgport@0@'.format(name),
pgport_sources,
link_with: cflag_libs,
c_pch: pch_c_h,
kwargs: opts + {
'dependencies': opts['dependencies'] + [ssl],
}
)
pgport += {name: lib}
endforeach
pgport_srv = pgport['_srv']
pgport_static = pgport['']
pgport_shlib = pgport['_shlib']
# autoconf generates the file there, ensure we get a conflict
generated_sources_ac += {'src/port': ['pg_config_paths.h']}
|