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