1 # Copyright (c) 2022-2024, PostgreSQL Global Development Group
25 if host_system == 'windows'
26 pgport_sources += files(
37 'win32gai_strerror.c',
47 elif host_system == 'cygwin'
48 pgport_sources += files(
53 if cc.get_id() == 'msvc'
54 pgport_sources += files(
56 'win32gettimeofday.c',
60 # Replacement functionality to be built if corresponding configure symbol
75 if host_system != 'windows'
76 replace_funcs_neg += [['pthread_barrier_wait']]
79 # Replacement functionality to be built if corresponding configure symbol
83 ['pg_crc32c_sse42', 'USE_SSE42_CRC32C'],
84 ['pg_crc32c_sse42', 'USE_SSE42_CRC32C_WITH_RUNTIME_CHECK', 'crc'],
85 ['pg_crc32c_sse42_choose', 'USE_SSE42_CRC32C_WITH_RUNTIME_CHECK'],
86 ['pg_crc32c_sb8', 'USE_SSE42_CRC32C_WITH_RUNTIME_CHECK'],
87 ['pg_popcount_avx512', 'USE_AVX512_POPCNT_WITH_RUNTIME_CHECK', 'popcnt'],
88 ['pg_popcount_avx512_choose', 'USE_AVX512_POPCNT_WITH_RUNTIME_CHECK', 'xsave'],
91 ['pg_crc32c_armv8', 'USE_ARMV8_CRC32C'],
92 ['pg_crc32c_armv8', 'USE_ARMV8_CRC32C_WITH_RUNTIME_CHECK', 'crc'],
93 ['pg_crc32c_armv8_choose', 'USE_ARMV8_CRC32C_WITH_RUNTIME_CHECK'],
94 ['pg_crc32c_sb8', 'USE_ARMV8_CRC32C_WITH_RUNTIME_CHECK'],
97 ['pg_crc32c_loongarch', 'USE_LOONGARCH_CRC32C'],
100 ['pg_crc32c_sb8', 'USE_SLICING_BY_8_CRC32C'],
103 pgport_cflags = {'crc': cflags_crc, 'popcnt': cflags_popcnt, 'xsave': cflags_xsave}
104 pgport_sources_cflags = {'crc': [], 'popcnt': [], 'xsave': []}
106 foreach f : replace_funcs_neg
108 varname = f.get(1, 'HAVE_@0@'.format(func.to_upper()))
109 filename = '@0@.c'.format(func)
111 val = '@0@'.format(cdata.get(varname, 'false'))
112 if val == 'false' or val == '0'
113 pgport_sources += files(filename)
117 foreach f : replace_funcs_pos
119 varname = f.get(1, 'HAVE_@0@'.format(func.to_upper()))
120 filename = '@0@.c'.format(func)
122 val = '@0@'.format(cdata.get(varname, 'false'))
123 if val == 'true' or val == '1'
124 src = files(filename)
126 pgport_sources_cflags += {f[2]: pgport_sources_cflags[f[2]] + src}
128 pgport_sources += src
134 if (host_system == 'windows' or host_system == 'cygwin') and \
135 (cc.get_id() != 'msvc' or cc.version().version_compare('<14.0'))
137 # Cygwin and (apparently, based on test results) Mingw both
138 # have a broken strtof(), so substitute its implementation.
139 # That's not a perfect fix, since it doesn't avoid double-rounding,
140 # but we have no better options.
141 pgport_sources += files('strtof.c')
142 message('On @0@ with compiler @1@ @2@ we will use our strtof wrapper.'.format(
143 host_system, cc.get_id(), cc.version()))
148 # Build pgport once for backend, once for use in frontend binaries, and once
149 # for use in shared libraries
152 '_srv': internal_lib_args + {
153 'dependencies': [backend_port_code],
155 '': default_lib_args + {
156 'dependencies': [frontend_port_code],
158 '_shlib': default_lib_args + {
160 'dependencies': [frontend_port_code],
164 foreach name, opts : pgport_variants
166 # Build internal static libraries for sets of files that need to be built
167 # with different cflags
169 foreach cflagname, sources : pgport_sources_cflags
170 if sources.length() == 0
173 c_args = opts.get('c_args', []) + pgport_cflags[cflagname]
174 cflag_libs += static_library('libpgport@0@_@1@'.format(name, cflagname),
179 'build_by_default': false,
185 lib = static_library('libpgport@0@'.format(name),
187 link_with: cflag_libs,
190 'dependencies': opts['dependencies'] + [ssl],
193 pgport += {name: lib}
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']}