1 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
26 if host_system == 'windows'
27 pgport_sources += files(
45 elif host_system == 'cygwin'
46 pgport_sources += files(
51 if cc.get_id() == 'msvc'
52 pgport_sources += files(
54 'win32gettimeofday.c',
58 # Replacement functionality to be built if corresponding configure symbol
67 ['preadv', 'HAVE_DECL_PREADV'],
68 ['pwritev', 'HAVE_DECL_PWRITEV'],
74 if host_system != 'windows'
75 replace_funcs_neg += [['pthread_barrier_wait']]
78 # Replacement functionality to be built if corresponding configure symbol
82 ['pg_crc32c_sse42', 'USE_SSE42_CRC32C'],
83 ['pg_crc32c_sse42', 'USE_SSE42_CRC32C_WITH_RUNTIME_CHECK', 'crc'],
84 ['pg_crc32c_sse42_choose', 'USE_SSE42_CRC32C_WITH_RUNTIME_CHECK'],
85 ['pg_crc32c_sb8', 'USE_SSE42_CRC32C_WITH_RUNTIME_CHECK'],
88 ['pg_crc32c_armv8', 'USE_ARMV8_CRC32C'],
89 ['pg_crc32c_armv8', 'USE_ARMV8_CRC32C_WITH_RUNTIME_CHECK', 'crc'],
90 ['pg_crc32c_armv8_choose', 'USE_ARMV8_CRC32C_WITH_RUNTIME_CHECK'],
91 ['pg_crc32c_sb8', 'USE_ARMV8_CRC32C_WITH_RUNTIME_CHECK'],
94 ['pg_crc32c_sb8', 'USE_SLICING_BY_8_CRC32C'],
97 pgport_cflags = {'crc': cflags_crc}
98 pgport_sources_cflags = {'crc': []}
100 foreach f : replace_funcs_neg
102 varname = f.get(1, 'HAVE_@0@'.format(func.to_upper()))
103 filename = '@0@.c'.format(func)
105 val = '@0@'.format(cdata.get(varname, 'false'))
106 if val == 'false' or val == '0'
107 pgport_sources += files(filename)
111 foreach f : replace_funcs_pos
113 varname = f.get(1, 'HAVE_@0@'.format(func.to_upper()))
114 filename = '@0@.c'.format(func)
116 val = '@0@'.format(cdata.get(varname, 'false'))
117 if val == 'true' or val == '1'
118 src = files(filename)
120 pgport_sources_cflags += {f[2]: pgport_sources_cflags[f[2]] + src}
122 pgport_sources += src
128 if (host_system == 'windows' or host_system == 'cygwin') and \
129 (cc.get_id() != 'msvc' or cc.version().version_compare('<14.0'))
131 # Cygwin and (apparently, based on test results) Mingw both
132 # have a broken strtof(), so substitute its implementation.
133 # That's not a perfect fix, since it doesn't avoid double-rounding,
134 # but we have no better options.
135 pgport_sources += files('strtof.c')
136 message('On @0@ with compiler @1@ @2@ we will use our strtof wrapper.'.format(
137 host_system, cc.get_id(), cc.version()))
142 # Build pgport once for backend, once for use in frontend binaries, and once
143 # for use in shared libraries
146 '_srv': internal_lib_args + {
147 'dependencies': [backend_port_code],
149 '': default_lib_args + {
150 'dependencies': [frontend_port_code],
152 '_shlib': default_lib_args + {
154 'dependencies': [frontend_port_code],
158 foreach name, opts : pgport_variants
160 # Build internal static libraries for sets of files that need to be built
161 # with different cflags
163 foreach cflagname, sources : pgport_sources_cflags
164 if sources.length() == 0
167 c_args = opts.get('c_args', []) + pgport_cflags[cflagname]
168 cflag_libs += static_library('libpgport@0@_@1@'.format(name, cflagname),
173 'build_by_default': false,
179 lib = static_library('libpgport@0@'.format(name),
181 link_with: cflag_libs,
184 'dependencies': opts['dependencies'] + [ssl],
187 pgport += {name: lib}
190 pgport_srv = pgport['_srv']
191 pgport_static = pgport['']
192 pgport_shlib = pgport['_shlib']