Debian Codegraph @

src/port/meson.build

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