Imported Upstream version 2.73.3
[platform/upstream/glib.git] / meson.build
1 project('glib', 'c',
2   version : '2.73.3',
3   # NOTE: See the policy in docs/meson-version.md before changing the Meson dependency
4   meson_version : '>= 0.60.0',
5   default_options : [
6     'buildtype=debugoptimized',
7     'warning_level=3',
8     'c_std=gnu99'
9   ]
10 )
11
12 cc = meson.get_compiler('c')
13 have_cxx = add_languages('cpp', native: false, required: get_option('oss_fuzz').enabled())
14 if have_cxx
15   cxx = meson.get_compiler('cpp')
16 endif
17
18 cc_can_run = meson.can_run_host_binaries()
19
20 if cc.get_argument_syntax() == 'msvc'
21   # Ignore several spurious warnings for things glib does very commonly
22   # (also for clang-cl)
23   add_project_arguments('/FImsvc_recommended_pragmas.h',language : 'c')
24 endif
25
26 if cc.get_id() == 'msvc'
27   # Set the input and exec encoding to utf-8, like is the default with GCC
28   add_project_arguments(cc.get_supported_arguments(['/utf-8']), language: 'c')
29   # Disable SAFESEH with MSVC for plugins and libs that use external deps that
30   # are built with MinGW
31   noseh_link_args = ['/SAFESEH:NO']
32 else
33   noseh_link_args = []
34   # -mms-bitfields vs -fnative-struct ?
35 endif
36
37 host_system = host_machine.system()
38
39 if host_system == 'darwin'
40   ios_test_code = '''#include <TargetConditionals.h>
41   #if ! TARGET_OS_IPHONE
42   #error "Not iOS/tvOS/watchOS/iPhoneSimulator"
43   #endif'''
44   if cc.compiles(ios_test_code, name : 'building for iOS')
45     host_system = 'ios'
46   endif
47 endif
48
49 glib_version = meson.project_version()
50 glib_api_version = '2.0'
51 version_arr = glib_version.split('.')
52 major_version = version_arr[0].to_int()
53 minor_version = version_arr[1].to_int()
54 micro_version = version_arr[2].to_int()
55
56 interface_age = minor_version.is_odd() ? 0 : micro_version
57 binary_age = 100 * minor_version + micro_version
58
59 soversion = 0
60 # Maintain compatibility with previous libtool versioning
61 # current = minor * 100 + micro
62 current = binary_age - interface_age
63 library_version = '@0@.@1@.@2@'.format(soversion, current, interface_age)
64 darwin_versions = [current + 1, '@0@.@1@'.format(current + 1, interface_age)]
65
66 configinc = include_directories('.')
67 glibinc = include_directories('glib')
68 gobjectinc = include_directories('gobject')
69 gmoduleinc = include_directories('gmodule')
70 gioinc = include_directories('gio')
71
72 glib_prefix = get_option('prefix')
73 glib_bindir = join_paths(glib_prefix, get_option('bindir'))
74 glib_libdir = join_paths(glib_prefix, get_option('libdir'))
75 glib_libexecdir = join_paths(glib_prefix, get_option('libexecdir'))
76 glib_datadir = join_paths(glib_prefix, get_option('datadir'))
77 glib_pkgdatadir = join_paths(glib_datadir, 'glib-2.0')
78 glib_includedir = join_paths(glib_prefix, get_option('includedir'))
79 if get_option('gio_module_dir') != ''
80   glib_giomodulesdir = join_paths(glib_prefix, get_option('gio_module_dir'))
81 else
82   glib_giomodulesdir = join_paths(glib_libdir, 'gio', 'modules')
83 endif
84
85 if get_option('multiarch')
86   # For multiarch/multilib distributions, install each architecture's
87   # build of executables used in packaging triggers (like gio-querymodules)
88   # to an architecture-dependent location, with a compatibility symlink
89   # in the PATH.
90   multiarch_bindir = get_option('libdir') / 'glib-2.0'
91   multiarch_libexecdir = multiarch_bindir
92   pkgconfig_multiarch_bindir = '${libdir}/glib-2.0'
93 else
94   # For single-architecture distributions, just install them into the PATH
95   # as was traditionally done.
96   multiarch_bindir = get_option('bindir')
97   multiarch_libexecdir = get_option('libexecdir')
98   pkgconfig_multiarch_bindir = '${bindir}'
99 endif
100
101 glib_pkgconfigreldir = join_paths(glib_libdir, 'pkgconfig')
102
103 if get_option('charsetalias_dir') != ''
104   glib_charsetaliasdir = join_paths(glib_prefix, get_option('charsetalias_dir'))
105 else
106   glib_charsetaliasdir = glib_libdir
107 endif
108
109 glib_localstatedir = get_option('localstatedir')
110 if not glib_localstatedir.startswith('/')
111   # See https://mesonbuild.com/Builtin-options.html#directories
112   glib_localstatedir = join_paths(glib_prefix, glib_localstatedir)
113 endif
114
115 installed_tests_metadir = join_paths(glib_datadir, 'installed-tests', meson.project_name())
116 installed_tests_execdir = join_paths(glib_libexecdir, 'installed-tests', meson.project_name())
117 installed_tests_enabled = get_option('installed_tests')
118 installed_tests_template = files('tests/template.test.in')
119 installed_tests_template_tap = files('tests/template-tap.test.in')
120
121 # Don’t build the tests unless we can run them (either natively, in an exe wrapper, or by installing them for later use)
122 build_tests = get_option('tests') and (meson.can_run_host_binaries() or installed_tests_enabled)
123
124 # Allow the tests to be easily run under valgrind using --setup=valgrind
125 valgrind = find_program('valgrind', required: false)
126 if valgrind.found()
127   suppression_file = files('tools' / 'glib.supp')
128
129   add_test_setup('valgrind',
130     exclude_suites: [ 'no-valgrind' ],
131     exe_wrapper: [
132       valgrind,
133       '--tool=memcheck',
134       '--error-exitcode=1',
135       '--track-origins=yes',
136       '--leak-check=full',
137       '--leak-resolution=high',
138       '--num-callers=50',
139       '--show-leak-kinds=definite,possible',
140       '--show-error-list=yes',
141       '--suppressions=@0@'.format(meson.project_source_root() /
142         '@0@'.format(suppression_file[0])),
143     ],
144     timeout_multiplier: 10,
145   )
146 endif
147
148 add_project_arguments('-D_GNU_SOURCE', language: 'c')
149
150 if host_system == 'qnx'
151   add_project_arguments('-D_QNX_SOURCE', language: 'c')
152 endif
153
154 # Disable strict aliasing;
155 # see https://bugzilla.gnome.org/show_bug.cgi?id=791622
156 if cc.has_argument('-fno-strict-aliasing')
157   add_project_arguments('-fno-strict-aliasing', language: 'c')
158 endif
159
160 # dummy/empty dependency() object to declare fallbacks and simpler dependencies
161 not_found = dependency('', required: false)
162
163 ########################
164 # Configuration begins #
165 ########################
166 glib_conf = configuration_data()
167 glibconfig_conf = configuration_data()
168
169 # accumulated list of defines as we check for them, so we can easily
170 # use them later in test programs (autoconf does this automatically)
171 glib_conf_prefix = ''
172
173 glib_conf.set('GLIB_MAJOR_VERSION', major_version)
174 glib_conf.set('GLIB_MINOR_VERSION', minor_version)
175 glib_conf.set('GLIB_MICRO_VERSION', micro_version)
176 glib_conf.set('GLIB_INTERFACE_AGE', interface_age)
177 glib_conf.set('GLIB_BINARY_AGE', binary_age)
178 glib_conf.set_quoted('GETTEXT_PACKAGE', 'glib20')
179 glib_conf.set_quoted('PACKAGE_BUGREPORT', 'https://gitlab.gnome.org/GNOME/glib/issues/new')
180 glib_conf.set_quoted('PACKAGE_NAME', 'glib')
181 glib_conf.set_quoted('PACKAGE_STRING', 'glib @0@'.format(meson.project_version()))
182 glib_conf.set_quoted('PACKAGE_TARNAME', 'glib')
183 glib_conf.set_quoted('PACKAGE_URL', '')
184 glib_conf.set_quoted('PACKAGE_VERSION', meson.project_version())
185 glib_conf.set('ENABLE_NLS', 1)
186
187 # used by the .rc.in files
188 glibconfig_conf.set('LT_CURRENT_MINUS_AGE', soversion)
189
190 glib_conf.set('_GNU_SOURCE', 1)
191
192 if host_system in ['windows', 'darwin']
193   # Poll doesn't work on devices on Windows, and macOS's poll() implementation is known to be broken
194   glib_conf.set('BROKEN_POLL', true)
195 endif
196
197 if host_system == 'windows' and cc.get_id() != 'msvc' and cc.get_id() != 'clang-cl'
198   # FIXME: Ideally we shouldn't depend on this on Windows and should use
199   # 64 bit capable Windows API that also works with MSVC.
200   # The autotools build did set this for mingw and while meson sets it
201   # for gcc/clang by default, it doesn't do so on Windows.
202   glib_conf.set('_FILE_OFFSET_BITS', 64)
203 endif
204
205 # Check for GNU visibility attributes
206 g_have_gnuc_visibility = cc.compiles('''
207   void
208   __attribute__ ((visibility ("hidden")))
209        f_hidden (void)
210   {
211   }
212   void
213   __attribute__ ((visibility ("internal")))
214        f_internal (void)
215   {
216   }
217   void
218   __attribute__ ((visibility ("default")))
219        f_default (void)
220   {
221   }
222   int main (void)
223   {
224     f_hidden();
225     f_internal();
226     f_default();
227     return 0;
228   }
229   ''',
230   # Not supported by MSVC, but MSVC also won't support visibility,
231   # so it's OK to pass -Werror explicitly. Replace with
232   # override_options : 'werror=true' once that is supported
233   args: ['-Werror'],
234   name : 'GNU C visibility attributes test')
235
236 if g_have_gnuc_visibility
237   glibconfig_conf.set('G_HAVE_GNUC_VISIBILITY', '1')
238 endif
239
240 # Detect and set symbol visibility
241 glib_hidden_visibility_args = []
242 if get_option('default_library') != 'static'
243   if host_system == 'windows' or host_system == 'cygwin'
244     if get_option('default_library') != 'shared'
245       error('On Windows default_library must be "shared" or "static" but not "both"')
246     endif
247     glib_conf.set('DLL_EXPORT', true)
248     if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
249       glib_conf.set('_GLIB_EXTERN', '__declspec(dllexport) extern')
250     elif cc.has_argument('-fvisibility=hidden')
251       glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) __declspec(dllexport) extern')
252       glib_hidden_visibility_args = ['-fvisibility=hidden']
253     endif
254   elif cc.has_argument('-fvisibility=hidden')
255     glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) extern')
256     glib_hidden_visibility_args = ['-fvisibility=hidden']
257   endif
258 endif
259
260 if get_option('default_library') == 'static'
261   glibconfig_conf.set('GLIB_STATIC_COMPILATION', '1')
262   glibconfig_conf.set('GOBJECT_STATIC_COMPILATION', '1')
263   glibconfig_conf.set('G_INTL_STATIC_COMPILATION', '1')
264   glibconfig_conf.set('FFI_STATIC_BUILD', '1')
265 endif
266
267 # Cygwin glib port maintainers made it clear
268 # (via the patches they apply) that they want no
269 # part of glib W32 code, therefore we do not define
270 # G_PLATFORM_WIN32 for host_system == 'cygwin'.
271 # This makes G_PLATFORM_WIN32 a synonym for
272 # G_OS_WIN32.
273 if host_system == 'windows'
274   glib_os = '''#define G_OS_WIN32
275 #define G_PLATFORM_WIN32'''
276 elif host_system == 'cygwin'
277   glib_os = '''#define G_OS_UNIX
278 #define G_WITH_CYGWIN'''
279 else
280   glib_os = '#define G_OS_UNIX'
281 endif
282 glibconfig_conf.set('glib_os', glib_os)
283
284 # We need to know the CRT being used to determine what .lib files we need on
285 # Visual Studio for dependencies that don't normally come with pkg-config files
286 vs_crt = 'release'
287 vs_crt_opt = get_option('b_vscrt')
288 if vs_crt_opt in ['mdd', 'mtd']
289   vs_crt = 'debug'
290 elif vs_crt_opt == 'from_buildtype'
291   if get_option('buildtype') == 'debug'
292     vs_crt = 'debug'
293   endif
294 endif
295
296 # Use debug/optimization flags to determine whether to enable debug or disable
297 # cast checks. We have a non-production (debug) build if debug is true and if
298 # optimization is 0 or g; otherwise, we have a production build.
299 glib_debug_cflags = []
300 glib_debug = get_option('glib_debug')
301 optimized_build = get_option('optimization') not in [ '0', 'g' ]
302 if glib_debug.enabled() or (glib_debug.auto() and get_option('debug') and not optimized_build)
303   glib_debug_cflags += ['-DG_ENABLE_DEBUG']
304   message('Enabling various debug infrastructure')
305 elif optimized_build
306   glib_debug_cflags += ['-DG_DISABLE_CAST_CHECKS']
307   message('Disabling cast checks')
308 endif
309
310 if not get_option('glib_assert')
311   glib_debug_cflags += ['-DG_DISABLE_ASSERT']
312   message('Disabling GLib asserts')
313 endif
314
315 if not get_option('glib_checks')
316   glib_debug_cflags += ['-DG_DISABLE_CHECKS']
317   message('Disabling GLib checks')
318 endif
319
320 add_project_arguments(glib_debug_cflags, language: 'c')
321
322 # check for header files
323
324 headers = [
325   'alloca.h',
326   'afunix.h',
327   'crt_externs.h',
328   'dirent.h', # MSC does not come with this by default
329   'float.h',
330   'fstab.h',
331   'grp.h',
332   'inttypes.h',
333   'limits.h',
334   'locale.h',
335   'mach/mach_time.h',
336   'memory.h',
337   'mntent.h',
338   'poll.h',
339   'pwd.h',
340   'sched.h',
341   'spawn.h',
342   'stdatomic.h',
343   'stdint.h',
344   'stdlib.h',
345   'string.h',
346   'strings.h',
347   'sys/auxv.h',
348   'sys/event.h',
349   'sys/filio.h',
350   'sys/inotify.h',
351   'sys/mkdev.h',
352   'sys/mntctl.h',
353   'sys/mnttab.h',
354   'sys/mount.h',
355   'sys/param.h',
356   'sys/resource.h',
357   'sys/select.h',
358   'sys/statfs.h',
359   'sys/stat.h',
360   'sys/statvfs.h',
361   'sys/sysctl.h',
362   'sys/time.h', # MSC does not come with this by default
363   'sys/times.h',
364   'sys/types.h',
365   'sys/uio.h',
366   'sys/vfs.h',
367   'sys/vfstab.h',
368   'sys/vmount.h',
369   'sys/wait.h',
370   'termios.h',
371   'unistd.h',
372   'values.h',
373   'wchar.h',
374   'xlocale.h',
375 ]
376
377 foreach h : headers
378   if cc.has_header(h)
379     define = 'HAVE_' + h.underscorify().to_upper()
380     glib_conf.set(define, 1)
381     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
382   endif
383 endforeach
384
385 # FreeBSD includes a malloc.h which always throws compilation error, so we have
386 # to use check_header() rather than has_header().
387 if cc.check_header('malloc.h')
388   glib_conf.set('HAVE_MALLOC_H', 1)
389   glib_conf_prefix = glib_conf_prefix + '#define HAVE_MALLOC_H 1\n'
390 endif
391
392 if cc.has_header('linux/netlink.h')
393   glib_conf.set('HAVE_NETLINK', 1)
394 endif
395
396 # Is statx() supported? Android systems don’t reliably support it as of August 2020.
397 statx_code = '''
398   #ifndef _GNU_SOURCE
399   #define _GNU_SOURCE
400   #endif
401   #include <sys/stat.h>
402   #include <fcntl.h>
403   int main (void)
404   {
405     struct statx stat_buf;
406     return statx (AT_FDCWD, "/", AT_SYMLINK_NOFOLLOW, STATX_BASIC_STATS | STATX_BTIME, &stat_buf);
407   }
408   '''
409 if host_system != 'android' and cc.compiles(statx_code, name : 'statx() test')
410   glib_conf.set('HAVE_STATX', 1)
411 endif
412
413 if glib_conf.has('HAVE_LOCALE_H')
414   if cc.has_header_symbol('locale.h', 'LC_MESSAGES')
415     glib_conf.set('HAVE_LC_MESSAGES', 1)
416   endif
417 endif
418
419 struct_stat_blkprefix = '''
420 #include <sys/types.h>
421 #include <sys/stat.h>
422 #ifdef HAVE_UNISTD_H
423 #include <unistd.h>
424 #endif
425 #ifdef HAVE_SYS_STATFS_H
426 #include <sys/statfs.h>
427 #endif
428 #ifdef HAVE_SYS_PARAM_H
429 #include <sys/param.h>
430 #endif
431 #ifdef HAVE_SYS_MOUNT_H
432 #include <sys/mount.h>
433 #endif
434 '''
435
436 struct_members = [
437   [ 'stat', 'st_mtimensec' ],
438   [ 'stat', 'st_mtim.tv_nsec' ],
439   [ 'stat', 'st_atimensec' ],
440   [ 'stat', 'st_atim.tv_nsec' ],
441   [ 'stat', 'st_ctimensec' ],
442   [ 'stat', 'st_ctim.tv_nsec' ],
443   [ 'stat', 'st_birthtime' ],
444   [ 'stat', 'st_birthtimensec' ],
445   [ 'stat', 'st_birthtim' ],
446   [ 'stat', 'st_birthtim.tv_nsec' ],
447   [ 'stat', 'st_blksize', struct_stat_blkprefix ],
448   [ 'stat', 'st_blocks', struct_stat_blkprefix ],
449   [ 'statfs', 'f_fstypename', struct_stat_blkprefix ],
450   [ 'statfs', 'f_bavail', struct_stat_blkprefix ],
451   [ 'dirent', 'd_type', '''#include <sys/types.h>
452                            #include <dirent.h>''' ],
453   [ 'statvfs', 'f_basetype', '#include <sys/statvfs.h>' ],
454   [ 'statvfs', 'f_fstypename', '#include <sys/statvfs.h>' ],
455   [ 'tm', 'tm_gmtoff', '#include <time.h>' ],
456   [ 'tm', '__tm_gmtoff', '#include <time.h>' ],
457 ]
458
459 foreach m : struct_members
460   header_check_prefix = glib_conf_prefix
461   if m.length() == 3
462     header_check_prefix = header_check_prefix + m[2]
463   else
464     header_check_prefix = header_check_prefix + '#include <sys/stat.h>'
465   endif
466   if cc.has_member('struct ' + m[0], m[1], prefix : header_check_prefix)
467     define = 'HAVE_STRUCT_@0@_@1@'.format(m[0].to_upper(), m[1].underscorify().to_upper())
468     glib_conf.set(define, 1)
469     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
470   else
471   endif
472 endforeach
473
474 # Compiler flags
475 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
476   warning_common_args = [
477     '-Wduplicated-branches',
478     '-Wimplicit-fallthrough',
479     '-Wmisleading-indentation',
480     '-Wunused',
481     # Due to maintained deprecated code, we do not want to see unused parameters
482     '-Wno-unused-parameter',
483     # Due to pervasive use of things like GPOINTER_TO_UINT(), we do not support
484     # building with -Wbad-function-cast.
485     '-Wno-cast-function-type',
486     # Due to function casts through (void*) we cannot support -Wpedantic:
487     # https://wiki.gnome.org/Projects/GLib/CompilerRequirements#Function_pointer_conversions.
488     '-Wno-pedantic',
489     # A zero-length format string shouldn't be considered an issue.
490     '-Wno-format-zero-length',
491     # We explicitly require variadic macros
492     '-Wno-variadic-macros',
493     '-Werror=format=2',
494     '-Werror=init-self',
495     '-Werror=missing-include-dirs',
496     '-Werror=pointer-arith',
497     '-Werror=unused-result',
498   ]
499
500   warning_c_args = warning_common_args + [
501     '-Wstrict-prototypes',
502     # Due to pervasive use of things like GPOINTER_TO_UINT(), we do not support
503     # building with -Wbad-function-cast.
504     '-Wno-bad-function-cast',
505     '-Werror=declaration-after-statement',
506     '-Werror=implicit-function-declaration',
507     '-Werror=missing-prototypes',
508     '-Werror=pointer-sign',
509   ]
510   warning_cxx_args = warning_common_args
511   warning_objc_args = warning_c_args
512   warning_c_link_args = [
513     '-Wl,-z,nodelete',
514   ]
515   if get_option('bsymbolic_functions')
516     warning_c_link_args += ['-Wl,-Bsymbolic-functions']
517   endif
518 elif cc.get_id() == 'msvc'
519   warning_c_args = [
520     # If a warning is completely useless and spammy, use '/wdXXXX' to suppress it
521     # If a warning is harmless but hard to fix, use '/woXXXX' so it's shown once
522     # NOTE: Only add warnings here if you are sure they're spurious
523     '/wo4057', # 'operator': 'identifier1' differs in indirection to slightly different base types from 'identifier2'
524     '/wd4068', # unknown pragma
525     '/wo4090', # 'operation': different 'modifier' qualifiers
526     '/wd4100', # 'identifier': unreferenced formal parameter
527     '/wd4116', # unnamed type definition in parentheses
528     '/wo4125', # decimal digit terminates octal escape sequence
529     '/wd4127', # conditional expression is constant
530     '/wd4146', # unary minus operator applied to unsigned type, result still unsigned
531     '/wd4152', # nonstandard extension, function/data pointer conversion in expression
532     '/wd4201', # nonstandard extension used: nameless struct/union
533     '/wd4232', # nonstandard extension used: 'identifier': address of dllimport 'dllimport' is not static, identity not guaranteed
534     '/wo4245', # 'conversion_type': conversion from 'type1' to 'type2', signed/unsigned mismatch
535     '/wo4267', # 'variable': conversion from 'size_t' to 'type', possible loss of data
536     '/wd4334', # 'shift_operator': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
537     '/wo4389', # 'operator': signed/unsigned mismatch
538     '/wo4702', # unreachable code
539     '/wd4706', # assignment within conditional expression
540   ]
541
542   warning_cxx_args = []
543   warning_objc_args = []
544   warning_c_link_args = []
545 else
546   warning_c_args = []
547   warning_cxx_args = []
548   warning_objc_args = []
549   warning_c_link_args = []
550 endif
551
552 add_project_arguments(cc.get_supported_arguments(warning_c_args), language: 'c')
553 if have_cxx
554   add_project_arguments(cxx.get_supported_arguments(warning_cxx_args), language: 'cpp')
555 endif
556
557 # FIXME: We cannot build some of the GResource tests with -z nodelete, which
558 # means we cannot use that flag in add_project_link_arguments(), and must add
559 # it to the relevant targets manually. We do the same with -Bsymbolic-functions
560 # because that is what the autotools build did.
561 # See https://github.com/mesonbuild/meson/pull/3520 for a way to eventually
562 # improve this.
563 glib_link_flags = cc.get_supported_link_arguments(warning_c_link_args)
564
565 # Windows SDK requirements and checks
566 if host_system == 'windows'
567   # Check whether we're building for UWP apps
568   code = '''
569   #include <windows.h>
570   #if !(WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP))
571   #error "Not building for UWP"
572   #endif'''
573   if cc.compiles(code, name : 'building for UWP')
574     glib_conf.set('G_WINAPI_ONLY_APP', true)
575     # We require Windows 10+ on WinRT
576     glib_conf.set('_WIN32_WINNT', '0x0A00')
577     uwp_gio_deps = [cc.find_library('shcore'),
578                     cc.find_library('runtimeobject')]
579   else
580     # We require Windows 7+ on Win32
581     glib_conf.set('_WIN32_WINNT', '0x0601')
582     uwp_gio_deps = []
583   endif
584 endif
585
586 functions = [
587   'close_range',
588   'endmntent',
589   'endservent',
590   'epoll_create',
591   'fallocate',
592   'fchmod',
593   'fchown',
594   'fdwalk',
595   'fsync',
596   'getauxval',
597   'getc_unlocked',
598   'getfsstat',
599   'getgrgid_r',
600   'getmntent_r',
601   'getpwuid_r',
602   'getresuid',
603   'getvfsstat',
604   'gmtime_r',
605   'hasmntopt',
606   'inotify_init1',
607   'issetugid',
608   'kevent',
609   'kqueue',
610   'lchmod',
611   'lchown',
612   'link',
613   'localtime_r',
614   'lstat',
615   'mbrtowc',
616   'memalign',
617   'mmap',
618   'newlocale',
619   'pipe2',
620   'poll',
621   'prlimit',
622   'readlink',
623   'recvmmsg',
624   'sendmmsg',
625   'setenv',
626   'setmntent',
627   'strerror_r',
628   'strnlen',
629   'strsignal',
630   'strtod_l',
631   'strtoll_l',
632   'strtoull_l',
633   'symlink',
634   'timegm',
635   'unsetenv',
636   'uselocale',
637   'utimes',
638   'utimensat',
639   'valloc',
640   'vasprintf',
641   'vsnprintf',
642   'wcrtomb',
643   'wcslen',
644   'wcsnlen',
645   'sysctlbyname',
646 ]
647
648 # _NSGetEnviron is available on iOS too, but its usage gets apps rejected from
649 # the app store since it's considered 'private API'
650 if host_system == 'darwin'
651   functions += ['_NSGetEnviron']
652 endif
653
654 if glib_conf.has('HAVE_SYS_STATVFS_H')
655   functions += ['statvfs']
656 else
657   have_func_statvfs = false
658 endif
659 if glib_conf.has('HAVE_SYS_STATFS_H') or glib_conf.has('HAVE_SYS_MOUNT_H')
660   functions += ['statfs']
661 else
662   have_func_statfs = false
663 endif
664
665 if host_system == 'windows'
666   iphlpapi_dep = cc.find_library('iphlpapi')
667   iphlpapi_funcs = ['if_nametoindex', 'if_indextoname']
668   foreach ifunc : iphlpapi_funcs
669     iphl_prefix =  '''#define _WIN32_WINNT @0@
670       #include <winsock2.h>
671       #include <iphlpapi.h>'''.format(glib_conf.get('_WIN32_WINNT'))
672     if cc.has_function(ifunc,
673                        prefix : iphl_prefix,
674                        dependencies : iphlpapi_dep)
675       idefine = 'HAVE_' + ifunc.underscorify().to_upper()
676       glib_conf.set(idefine, 1)
677       glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(idefine)
678       set_variable('have_func_' + ifunc, true)
679     else
680       set_variable('have_func_' + ifunc, false)
681     endif
682   endforeach
683 else
684   functions += ['if_indextoname', 'if_nametoindex']
685 endif
686
687 # AIX splice is something else
688 if host_system != 'aix'
689   functions += ['splice']
690 endif
691
692 foreach f : functions
693   if cc.has_function(f)
694     define = 'HAVE_' + f.underscorify().to_upper()
695     glib_conf.set(define, 1)
696     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
697     set_variable('have_func_' + f, true)
698   else
699     set_variable('have_func_' + f, false)
700   endif
701 endforeach
702
703 # Check that stpcpy() is usable; must use header.
704 # cc.has_function() in some cases (clang, gcc 10+) assumes that if the
705 # compiler provides a builtin of the same name that the function exists, while
706 # it's in fact not provided by any header or library. This is true for
707 # stpcpy() on Windows using clang and gcc as well as posix_memalign() using
708 # gcc on Windows. Skip these checks on Windows for now to avoid false
709 # positives. See https://github.com/mesonbuild/meson/pull/7116,
710 # https://github.com/mesonbuild/meson/issues/3672 and
711 # https://github.com/mesonbuild/meson/issues/5628.
712 # FIXME: Once meson no longer returns success for stpcpy() and
713 # posix_memalign() on Windows using GCC and clang we can remove this.
714 if host_system != 'windows' and cc.has_function('stpcpy', prefix : '#include <string.h>')
715   glib_conf.set('HAVE_STPCPY', 1)
716 endif
717
718 if cc.has_function('memalign', prefix: '#include <stdlib.h>\n#include <malloc.h>')
719   glib_conf.set('HAVE_MEMALIGN', 1)
720 endif
721
722 if cc.has_function('_aligned_malloc', prefix: '#include <malloc.h>')
723   glib_conf.set('HAVE__ALIGNED_MALLOC', 1)
724 endif
725
726 if host_system != 'windows' and cc.has_function('aligned_alloc', prefix: '#include <stdlib.h>')
727   glib_conf.set('HAVE_ALIGNED_ALLOC', 1)
728 endif
729
730 if host_system != 'windows' and cc.has_function('posix_memalign', prefix: '#include <stdlib.h>')
731   glib_conf.set('HAVE_POSIX_MEMALIGN', 1)
732 endif
733
734 # Check that posix_spawn() is usable; must use header
735 if cc.has_function('posix_spawn', prefix : '#include <spawn.h>')
736   glib_conf.set('HAVE_POSIX_SPAWN', 1)
737 endif
738
739 # Check whether strerror_r returns char *
740 if have_func_strerror_r
741   if cc.compiles('''#define _GNU_SOURCE
742                     #include <string.h>
743                     int func (void) {
744                       char error_string[256];
745                       char *ptr = strerror_r (-2, error_string, 256);
746                       char c = *strerror_r (-2, error_string, 256);
747                       return c != 0 && ptr != (void*) 0L;
748                     }
749                  ''',
750                  name : 'strerror_r() returns char *')
751     glib_conf.set('STRERROR_R_CHAR_P', 1,
752                   description: 'Defined if strerror_r returns char *')
753   endif
754 endif
755
756 # Special-case these functions that have alternative names on Windows/MSVC
757 if cc.has_function('snprintf') or cc.has_header_symbol('stdio.h', 'snprintf')
758   glib_conf.set('HAVE_SNPRINTF', 1)
759   glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF 1\n'
760 elif cc.has_function('_snprintf') or cc.has_header_symbol('stdio.h', '_snprintf')
761   hack_define = '1\n#define snprintf _snprintf'
762   glib_conf.set('HAVE_SNPRINTF', hack_define)
763   glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF ' + hack_define
764 endif
765
766 if cc.has_function('strcasecmp', prefix: '#include <strings.h>')
767   glib_conf.set('HAVE_STRCASECMP', 1)
768   glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP 1\n'
769 elif cc.has_function('_stricmp')
770   hack_define = '1\n#define strcasecmp _stricmp'
771   glib_conf.set('HAVE_STRCASECMP', hack_define)
772   glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP ' + hack_define
773 endif
774
775 if cc.has_function('strncasecmp', prefix: '#include <strings.h>')
776   glib_conf.set('HAVE_STRNCASECMP', 1)
777   glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP 1\n'
778 elif cc.has_function('_strnicmp')
779   hack_define = '1\n#define strncasecmp _strnicmp'
780   glib_conf.set('HAVE_STRNCASECMP', hack_define)
781   glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP ' + hack_define
782 endif
783
784 if cc.has_header_symbol('sys/sysmacros.h', 'major')
785   glib_conf.set('MAJOR_IN_SYSMACROS', 1)
786 elif cc.has_header_symbol('sys/mkdev.h', 'major')
787   glib_conf.set('MAJOR_IN_MKDEV', 1)
788 elif cc.has_header_symbol('sys/types.h', 'major')
789   glib_conf.set('MAJOR_IN_TYPES', 1)
790 endif
791
792 if cc.has_header_symbol('dlfcn.h', 'RTLD_LAZY')
793   glib_conf.set('HAVE_RTLD_LAZY', 1)
794 endif
795
796 if cc.has_header_symbol('dlfcn.h', 'RTLD_NOW')
797   glib_conf.set('HAVE_RTLD_NOW', 1)
798 endif
799
800 if cc.has_header_symbol('dlfcn.h', 'RTLD_GLOBAL')
801   glib_conf.set('HAVE_RTLD_GLOBAL', 1)
802 endif
803
804 have_rtld_next = false
805 if cc.has_header_symbol('dlfcn.h', 'RTLD_NEXT', args: '-D_GNU_SOURCE')
806   have_rtld_next = true
807   glib_conf.set('HAVE_RTLD_NEXT', 1)
808 endif
809
810 # Check whether to use statfs or statvfs
811 # Some systems have both statfs and statvfs, pick the most "native" for these
812 if have_func_statfs and have_func_statvfs
813   # on solaris and irix, statfs doesn't even have the f_bavail field
814   if not glib_conf.has('HAVE_STRUCT_STATFS_F_BAVAIL')
815     have_func_statfs = false
816   else
817     # at least on linux, statfs is the actual syscall
818     have_func_statvfs = false
819   endif
820 endif
821 if have_func_statfs
822   glib_conf.set('USE_STATFS', 1)
823   stat_func_to_use = 'statfs'
824 elif have_func_statvfs
825   glib_conf.set('USE_STATVFS', 1)
826   stat_func_to_use = 'statvfs'
827 else
828   stat_func_to_use = 'neither'
829 endif
830 message('Checking whether to use statfs or statvfs .. ' + stat_func_to_use)
831
832 if host_system == 'linux'
833   if cc.has_function('mkostemp',
834                      prefix: '''#define _GNU_SOURCE
835                                 #include <stdlib.h>''')
836     glib_conf.set('HAVE_MKOSTEMP', 1)
837   endif
838 endif
839
840 glib_have_os_x_9_or_later = false
841 glib_have_carbon = false
842 glib_have_cocoa = false
843 if host_system == 'darwin'
844   add_languages('objc', native: false, required: true)
845   objcc = meson.get_compiler('objc')
846
847   add_project_arguments(objcc.get_supported_arguments(warning_objc_args), language: 'objc')
848
849   # Mac OS X Carbon support
850   glib_have_carbon = objcc.compiles('''#include <Carbon/Carbon.h>
851                                        #include <CoreServices/CoreServices.h>''',
852                                     name : 'Mac OS X Carbon support')
853
854   if glib_have_carbon
855     glib_conf.set('HAVE_CARBON', true)
856     glib_have_os_x_9_or_later = objcc.compiles('''#include <AvailabilityMacros.h>
857                                                   #if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
858                                                   #error Compiling for minimum OS X version before 10.9
859                                                   #endif''',
860                                                name : 'OS X 9 or later')
861   endif
862
863   # Mac OS X Cocoa support
864   glib_have_cocoa = objcc.compiles('''#include <Cocoa/Cocoa.h>
865                                       #ifdef GNUSTEP_BASE_VERSION
866                                       #error "Detected GNUstep, not Cocoa"
867                                       #endif''',
868                                    name : 'Mac OS X Cocoa support')
869
870   if glib_have_cocoa
871     glib_conf.set('HAVE_COCOA', true)
872   endif
873 endif
874
875 if host_system == 'qnx'
876   glib_conf.set('HAVE_QNX', 1)
877 endif
878
879 # Check for futex(2)
880 if cc.links('''#include <linux/futex.h>
881                #include <sys/syscall.h>
882                #include <unistd.h>
883                int main (int argc, char ** argv) {
884                  syscall (__NR_futex, NULL, FUTEX_WAKE, FUTEX_WAIT);
885                  return 0;
886                }''', name : 'futex(2) system call')
887   glib_conf.set('HAVE_FUTEX', 1)
888 endif
889
890 # Check for eventfd(2)
891 if cc.links('''#include <sys/eventfd.h>
892                #include <unistd.h>
893                int main (int argc, char ** argv) {
894                  eventfd (0, EFD_CLOEXEC);
895                  return 0;
896                }''', name : 'eventfd(2) system call')
897   glib_conf.set('HAVE_EVENTFD', 1)
898 endif
899
900 # Check for pidfd_open(2)
901 if cc.links('''#include <sys/syscall.h>
902                #include <sys/wait.h>
903                #include <linux/wait.h>
904                #include <unistd.h>
905                int main (int argc, char ** argv) {
906                  siginfo_t child_info = { 0, };
907                  syscall (SYS_pidfd_open, 0, 0);
908                  waitid (P_PIDFD, 0, &child_info, WEXITED | WNOHANG);
909                  return 0;
910                }''', name : 'pidfd_open(2) system call')
911   glib_conf.set('HAVE_PIDFD', 1)
912 endif
913
914 # Check for __uint128_t (gcc) by checking for 128-bit division
915 uint128_t_src = '''int main() {
916 static __uint128_t v1 = 100;
917 static __uint128_t v2 = 10;
918 static __uint128_t u;
919 u = v1 / v2;
920 }'''
921 if cc.compiles(uint128_t_src, name : '__uint128_t available')
922   glib_conf.set('HAVE_UINT128_T', 1)
923 endif
924
925 clock_gettime_test_code = '''
926   #include <time.h>
927   struct timespec t;
928   int main (int argc, char ** argv) {
929     return clock_gettime(CLOCK_REALTIME, &t);
930   }'''
931 librt = []
932 if cc.links(clock_gettime_test_code, name : 'clock_gettime')
933   glib_conf.set('HAVE_CLOCK_GETTIME', 1)
934 elif cc.links(clock_gettime_test_code, args : '-lrt', name : 'clock_gettime in librt')
935   glib_conf.set('HAVE_CLOCK_GETTIME', 1)
936   librt = cc.find_library('rt')
937 endif
938
939 dlopen_dlsym_test_code = '''
940 #include <dlfcn.h>
941 int glib_underscore_test (void) { return 42; }
942 int main (int argc, char ** argv) {
943   void *f1 = (void*)0, *f2 = (void*)0, *handle;
944   handle = dlopen ((void*)0, 0);
945   if (handle) {
946     f1 = dlsym (handle, "glib_underscore_test");
947     f2 = dlsym (handle, "_glib_underscore_test");
948   }
949   return (!f2 || f1);
950 }'''
951 libdl_dep = []
952 if cc.links(dlopen_dlsym_test_code, name : 'dlopen() and dlsym() in system libraries')
953   have_dlopen_dlsym = true
954 elif cc.links(dlopen_dlsym_test_code, args : '-ldl', name : 'dlopen() and dlsym() in libdl')
955   have_dlopen_dlsym = true
956   libdl_dep = cc.find_library('dl')
957 else
958   have_dlopen_dlsym = false
959 endif
960
961 # if statfs() takes 2 arguments (Posix) or 4 (Solaris)
962 if have_func_statfs
963   if cc.compiles(glib_conf_prefix + '''
964                  #include <unistd.h>
965                         #ifdef HAVE_SYS_PARAM_H
966                         #include <sys/param.h>
967                         #endif
968                         #ifdef HAVE_SYS_VFS_H
969                         #include <sys/vfs.h>
970                         #endif
971                         #ifdef HAVE_SYS_MOUNT_H
972                         #include <sys/mount.h>
973                         #endif
974                         #ifdef HAVE_SYS_STATFS_H
975                         #include <sys/statfs.h>
976                         #endif
977                         void some_func (void) {
978                           struct statfs st;
979                           statfs("/", &st);
980                         }''', name : 'number of arguments to statfs() (n=2)')
981     glib_conf.set('STATFS_ARGS', 2)
982   elif cc.compiles(glib_conf_prefix + '''
983                    #include <unistd.h>
984                           #ifdef HAVE_SYS_PARAM_H
985                           #include <sys/param.h>
986                           #endif
987                           #ifdef HAVE_SYS_VFS_H
988                           #include <sys/vfs.h>
989                           #endif
990                           #ifdef HAVE_SYS_MOUNT_H
991                           #include <sys/mount.h>
992                           #endif
993                           #ifdef HAVE_SYS_STATFS_H
994                           #include <sys/statfs.h>
995                           #endif
996                           void some_func (void) {
997                             struct statfs st;
998                             statfs("/", &st, sizeof (st), 0);
999                           }''', name : 'number of arguments to statfs() (n=4)')
1000     glib_conf.set('STATFS_ARGS', 4)
1001   else
1002     error('Unable to determine number of arguments to statfs()')
1003   endif
1004 endif
1005
1006 # open takes O_DIRECTORY as an option
1007 #AC_MSG_CHECKING([])
1008 if cc.compiles('''#include <fcntl.h>
1009                   #include <sys/types.h>
1010                   #include <sys/stat.h>
1011                   void some_func (void) {
1012                     open(0, O_DIRECTORY, 0);
1013                   }''', name : 'open() option O_DIRECTORY')
1014   glib_conf.set('HAVE_OPEN_O_DIRECTORY', 1)
1015 endif
1016
1017 # fcntl takes F_FULLFSYNC as an option
1018 # See https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/fsync.2.html
1019 if cc.compiles('''#include <fcntl.h>
1020                   #include <sys/types.h>
1021                   #include <sys/stat.h>
1022                   void some_func (void) {
1023                     fcntl(0, F_FULLFSYNC, 0);
1024                   }''', name : 'fcntl() option F_FULLFSYNC')
1025   glib_conf.set('HAVE_FCNTL_F_FULLFSYNC', 1)
1026 endif
1027
1028 # Check whether there is a vsnprintf() function with C99 semantics installed.
1029 # (similar tests to AC_FUNC_VSNPRINTF_C99)
1030 # Check whether there is a snprintf() function with C99 semantics installed.
1031 # (similar tests to AC_FUNC_SNPRINTF_C99)
1032 # Check whether there is a printf() function with Unix98 semantics installed.
1033 # (similar tests to AC_FUNC_PRINTF_UNIX98)
1034 have_good_vsnprintf = false
1035 have_good_snprintf = false
1036 have_good_printf = false
1037
1038 if host_system == 'windows' and (cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl')
1039   # Unfortunately the Visual Studio 2015+ implementations of C99-style
1040   # snprintf and vsnprintf don't seem to be quite good enough.
1041   # (Sorry, I don't know exactly what is the problem,
1042   # but it is related to floating point formatting and decimal point vs. comma.)
1043   # The simple tests in AC_FUNC_VSNPRINTF_C99 and AC_FUNC_SNPRINTF_C99 aren't
1044   # rigorous enough to notice, though.
1045   glib_conf.set('HAVE_C99_SNPRINTF', false)
1046   glib_conf.set('HAVE_C99_VSNPRINTF', false)
1047   glib_conf.set('HAVE_UNIX98_PRINTF', false)
1048 elif not cc_can_run and host_system in ['ios', 'darwin']
1049   # All these are true when compiling natively on macOS, so we should use good
1050   # defaults when building for iOS and tvOS.
1051   glib_conf.set('HAVE_C99_SNPRINTF', true)
1052   glib_conf.set('HAVE_C99_VSNPRINTF', true)
1053   glib_conf.set('HAVE_UNIX98_PRINTF', true)
1054   have_good_vsnprintf = true
1055   have_good_snprintf = true
1056   have_good_printf = true
1057 else
1058   vsnprintf_c99_test_code = '''
1059 #include <stdio.h>
1060 #include <stdarg.h>
1061 #include <stdlib.h>
1062
1063 int
1064 doit(char * s, ...)
1065 {
1066   char buffer[32];
1067   va_list args;
1068   int r;
1069
1070   va_start(args, s);
1071   r = vsnprintf(buffer, 5, s, args);
1072   va_end(args);
1073
1074   if (r != 7)
1075     exit(1);
1076
1077   /* AIX 5.1 and Solaris seems to have a half-baked vsnprintf()
1078      implementation. The above will return 7 but if you replace
1079      the size of the buffer with 0, it borks! */
1080   va_start(args, s);
1081   r = vsnprintf(buffer, 0, s, args);
1082   va_end(args);
1083
1084   if (r != 7)
1085     exit(1);
1086
1087   exit(0);
1088 }
1089
1090 int
1091 main(void)
1092 {
1093   doit("1234567");
1094   exit(1);
1095 }'''
1096
1097   if cc_can_run
1098     rres = cc.run(vsnprintf_c99_test_code, name : 'C99 vsnprintf')
1099     if rres.compiled() and rres.returncode() == 0
1100       glib_conf.set('HAVE_C99_VSNPRINTF', 1)
1101       have_good_vsnprintf = true
1102     endif
1103   else
1104       have_good_vsnprintf = meson.get_external_property('have_c99_vsnprintf', false)
1105       glib_conf.set('HAVE_C99_VSNPRINTF', have_good_vsnprintf)
1106   endif
1107
1108   snprintf_c99_test_code = '''
1109 #include <stdio.h>
1110 #include <stdarg.h>
1111 #include <stdlib.h>
1112
1113 int
1114 doit()
1115 {
1116   char buffer[32];
1117   va_list args;
1118   int r;
1119
1120   r = snprintf(buffer, 5, "1234567");
1121
1122   if (r != 7)
1123     exit(1);
1124
1125   r = snprintf(buffer, 0, "1234567");
1126
1127   if (r != 7)
1128     exit(1);
1129
1130   r = snprintf(NULL, 0, "1234567");
1131
1132   if (r != 7)
1133     exit(1);
1134
1135   exit(0);
1136 }
1137
1138 int
1139 main(void)
1140 {
1141   doit();
1142   exit(1);
1143 }'''
1144
1145   if cc_can_run
1146     rres = cc.run(snprintf_c99_test_code, name : 'C99 snprintf')
1147     if rres.compiled() and rres.returncode() == 0
1148       glib_conf.set('HAVE_C99_SNPRINTF', 1)
1149       have_good_snprintf = true
1150     endif
1151   else
1152       have_good_snprintf = meson.get_external_property('have_c99_snprintf', false)
1153       glib_conf.set('HAVE_C99_SNPRINTF', have_good_snprintf)
1154   endif
1155
1156   printf_unix98_test_code = '''
1157 #include <stdio.h>
1158 #include <stdlib.h>
1159 #include <string.h>
1160
1161 int
1162 main (void)
1163 {
1164   char buffer[128];
1165
1166   sprintf (buffer, "%2\$d %3\$d %1\$d", 1, 2, 3);
1167   if (strcmp ("2 3 1", buffer) == 0)
1168     exit (0);
1169   exit (1);
1170 }'''
1171
1172   if cc_can_run
1173     rres = cc.run(printf_unix98_test_code, name : 'Unix98 printf positional parameters')
1174     if rres.compiled() and rres.returncode() == 0
1175       glib_conf.set('HAVE_UNIX98_PRINTF', 1)
1176       have_good_printf = true
1177     endif
1178   else
1179       have_good_printf = meson.get_external_property('have_unix98_printf', false)
1180       glib_conf.set('HAVE_UNIX98_PRINTF', have_good_printf)
1181   endif
1182 endif
1183
1184 if host_system == 'windows'
1185   glib_conf.set_quoted('EXEEXT', '.exe')
1186 else
1187   glib_conf.set('EXEEXT', '')
1188 endif
1189
1190 # Our printf is 'good' only if vsnpintf()/snprintf()/printf() supports C99 well enough
1191 use_system_printf = have_good_vsnprintf and have_good_snprintf and have_good_printf
1192 glib_conf.set('USE_SYSTEM_PRINTF', use_system_printf)
1193 glibconfig_conf.set('GLIB_USING_SYSTEM_PRINTF', use_system_printf)
1194
1195 if not use_system_printf
1196   # gnulib has vasprintf so override the previous check
1197   glib_conf.set('HAVE_VASPRINTF', 1)
1198 endif
1199
1200 # Check for nl_langinfo and CODESET
1201 if cc.links('''#include <langinfo.h>
1202                int main (int argc, char ** argv) {
1203                  char *codeset = nl_langinfo (CODESET);
1204                  return 0;
1205                }''', name : 'nl_langinfo and CODESET')
1206   glib_conf.set('HAVE_LANGINFO_CODESET', 1)
1207   glib_conf.set('HAVE_CODESET', 1)
1208 endif
1209
1210 # Check for nl_langinfo and LC_TIME parts that are needed in gdatetime.c
1211 if cc.links('''#include <langinfo.h>
1212                int main (int argc, char ** argv) {
1213                  char *str;
1214                  str = nl_langinfo (PM_STR);
1215                  str = nl_langinfo (D_T_FMT);
1216                  str = nl_langinfo (D_FMT);
1217                  str = nl_langinfo (T_FMT);
1218                  str = nl_langinfo (T_FMT_AMPM);
1219                  str = nl_langinfo (MON_1);
1220                  str = nl_langinfo (ABMON_12);
1221                  str = nl_langinfo (DAY_1);
1222                  str = nl_langinfo (ABDAY_7);
1223                  return 0;
1224                }''', name : 'nl_langinfo (PM_STR)')
1225   glib_conf.set('HAVE_LANGINFO_TIME', 1)
1226 endif
1227 if cc.links('''#include <langinfo.h>
1228                int main (int argc, char ** argv) {
1229                  char *str;
1230                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT0_MB);
1231                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT1_MB);
1232                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT2_MB);
1233                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT3_MB);
1234                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT4_MB);
1235                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT5_MB);
1236                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT6_MB);
1237                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT7_MB);
1238                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT8_MB);
1239                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT9_MB);
1240                  return 0;
1241                }''', name : 'nl_langinfo (_NL_CTYPE_OUTDIGITn_MB)')
1242   glib_conf.set('HAVE_LANGINFO_OUTDIGIT', 1)
1243 endif
1244
1245 # Check for nl_langinfo and alternative month names
1246 if cc.links('''#ifndef _GNU_SOURCE
1247               # define _GNU_SOURCE
1248               #endif
1249               #include <langinfo.h>
1250                int main (int argc, char ** argv) {
1251                  char *str;
1252                  str = nl_langinfo (ALTMON_1);
1253                  str = nl_langinfo (ALTMON_2);
1254                  str = nl_langinfo (ALTMON_3);
1255                  str = nl_langinfo (ALTMON_4);
1256                  str = nl_langinfo (ALTMON_5);
1257                  str = nl_langinfo (ALTMON_6);
1258                  str = nl_langinfo (ALTMON_7);
1259                  str = nl_langinfo (ALTMON_8);
1260                  str = nl_langinfo (ALTMON_9);
1261                  str = nl_langinfo (ALTMON_10);
1262                  str = nl_langinfo (ALTMON_11);
1263                  str = nl_langinfo (ALTMON_12);
1264                  return 0;
1265                }''', name : 'nl_langinfo (ALTMON_n)')
1266   glib_conf.set('HAVE_LANGINFO_ALTMON', 1)
1267 endif
1268
1269 # Check for nl_langinfo and abbreviated alternative month names
1270 if cc.links('''#ifndef _GNU_SOURCE
1271               # define _GNU_SOURCE
1272               #endif
1273               #include <langinfo.h>
1274                int main (int argc, char ** argv) {
1275                  char *str;
1276                  str = nl_langinfo (_NL_ABALTMON_1);
1277                  str = nl_langinfo (_NL_ABALTMON_2);
1278                  str = nl_langinfo (_NL_ABALTMON_3);
1279                  str = nl_langinfo (_NL_ABALTMON_4);
1280                  str = nl_langinfo (_NL_ABALTMON_5);
1281                  str = nl_langinfo (_NL_ABALTMON_6);
1282                  str = nl_langinfo (_NL_ABALTMON_7);
1283                  str = nl_langinfo (_NL_ABALTMON_8);
1284                  str = nl_langinfo (_NL_ABALTMON_9);
1285                  str = nl_langinfo (_NL_ABALTMON_10);
1286                  str = nl_langinfo (_NL_ABALTMON_11);
1287                  str = nl_langinfo (_NL_ABALTMON_12);
1288                  return 0;
1289                }''', name : 'nl_langinfo (_NL_ABALTMON_n)')
1290   glib_conf.set('HAVE_LANGINFO_ABALTMON', 1)
1291 endif
1292
1293 # Check for nl_langinfo and _NL_TIME_CODESET
1294 if cc.links('''#include <langinfo.h>
1295                int main (int argc, char ** argv) {
1296                  char *codeset = nl_langinfo (_NL_TIME_CODESET);
1297                  return 0;
1298                }''', name : 'nl_langinfo and _NL_TIME_CODESET')
1299   glib_conf.set('HAVE_LANGINFO_TIME_CODESET', 1)
1300 endif
1301
1302 # Check if C compiler supports the 'signed' keyword
1303 if not cc.compiles('''signed char x;''', name : 'signed')
1304   glib_conf.set('signed', '/* NOOP */')
1305 endif
1306
1307 # Check if the ptrdiff_t type exists
1308 if cc.has_header_symbol('stddef.h', 'ptrdiff_t')
1309   glib_conf.set('HAVE_PTRDIFF_T', 1)
1310 endif
1311
1312 # Check for sig_atomic_t type
1313 if cc.links('''#include <signal.h>
1314                #include <sys/types.h>
1315                sig_atomic_t val = 42;
1316                int main (int argc, char ** argv) {
1317                  return val == 42 ? 0 : 1;
1318                }''', name : 'sig_atomic_t')
1319   glib_conf.set('HAVE_SIG_ATOMIC_T', 1)
1320 endif
1321
1322 # Check if 'long long' works
1323 # jm_AC_TYPE_LONG_LONG
1324 if cc.compiles('''long long ll = 1LL;
1325                   int i = 63;
1326                   int some_func (void) {
1327                     long long llmax = (long long) -1;
1328                     return ll << i | ll >> i | llmax / ll | llmax % ll;
1329                   }''', name : 'long long')
1330   glib_conf.set('HAVE_LONG_LONG', 1)
1331   have_long_long = true
1332 else
1333   have_long_long = false
1334 endif
1335
1336 # Test whether the compiler supports the 'long double' type.
1337 if cc.compiles('''/* The Stardent Vistra knows sizeof(long double), but does not support it.  */
1338                   long double foo = 0.0;
1339                   /* On Ultrix 4.3 cc, long double is 4 and double is 8.  */
1340                   int array [2*(sizeof(long double) >= sizeof(double)) - 1];''',
1341                name : 'long double')
1342   glib_conf.set('HAVE_LONG_DOUBLE', 1)
1343 endif
1344
1345 # Test whether <stddef.h> has the 'wchar_t' type.
1346 if cc.has_header_symbol('stddef.h', 'wchar_t')
1347   glib_conf.set('HAVE_WCHAR_T', 1)
1348 endif
1349
1350 # Test whether <wchar.h> has the 'wint_t' type.
1351 if cc.has_header_symbol('wchar.h', 'wint_t')
1352   glib_conf.set('HAVE_WINT_T', 1)
1353 endif
1354
1355 found_uintmax_t = false
1356
1357 # Define HAVE_INTTYPES_H_WITH_UINTMAX if <inttypes.h> exists,
1358 # doesn't clash with <sys/types.h>, and declares uintmax_t.
1359 # jm_AC_HEADER_INTTYPES_H
1360 if cc.compiles('''#include <sys/types.h>
1361                   #include <inttypes.h>
1362                   void some_func (void) {
1363                     uintmax_t i = (uintmax_t) -1;
1364                   }''', name : 'uintmax_t in inttypes.h')
1365   glib_conf.set('HAVE_INTTYPES_H_WITH_UINTMAX', 1)
1366   found_uintmax_t = true
1367 endif
1368
1369 # Define HAVE_STDINT_H_WITH_UINTMAX if <stdint.h> exists,
1370 # doesn't clash with <sys/types.h>, and declares uintmax_t.
1371 # jm_AC_HEADER_STDINT_H
1372 if cc.compiles('''#include <sys/types.h>
1373                   #include <stdint.h>
1374                   void some_func (void) {
1375                     uintmax_t i = (uintmax_t) -1;
1376                   }''', name : 'uintmax_t in stdint.h')
1377   glib_conf.set('HAVE_STDINT_H_WITH_UINTMAX', 1)
1378   found_uintmax_t = true
1379 endif
1380
1381 # Define intmax_t to 'long' or 'long long'
1382 # if it is not already defined in <stdint.h> or <inttypes.h>.
1383 # For simplicity, we assume that a header file defines 'intmax_t' if and
1384 # only if it defines 'uintmax_t'.
1385 if found_uintmax_t
1386   glib_conf.set('HAVE_INTMAX_T', 1)
1387 elif have_long_long
1388   glib_conf.set('intmax_t', 'long long')
1389 else
1390   glib_conf.set('intmax_t', 'long')
1391 endif
1392
1393 char_size = cc.sizeof('char')
1394 short_size = cc.sizeof('short')
1395 int_size = cc.sizeof('int')
1396 voidp_size = cc.sizeof('void*')
1397 long_size = cc.sizeof('long')
1398 if have_long_long
1399   long_long_size = cc.sizeof('long long')
1400 else
1401   long_long_size = 0
1402 endif
1403 sizet_size = cc.sizeof('size_t')
1404 if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
1405   ssizet_size = cc.sizeof('SSIZE_T', prefix : '#include <BaseTsd.h>')
1406 else
1407   ssizet_size = cc.sizeof('ssize_t', prefix : '#include <unistd.h>')
1408 endif
1409
1410 # Some platforms (Apple) hard-code int64_t to long long instead of
1411 # using long on 64-bit architectures. This can cause type mismatch
1412 # warnings when trying to interface with code using the standard
1413 # library type. Test for the warnings and set gint64 to whichever
1414 # works.
1415 if long_long_size == long_size
1416   if cc.compiles('''#if defined(_AIX) && !defined(__GNUC__)
1417                     #pragma options langlvl=stdc99
1418                     #endif
1419                     #pragma GCC diagnostic error "-Wincompatible-pointer-types"
1420                     #include <stdint.h>
1421                     #include <stdio.h>
1422                     int main () {
1423                       int64_t i1 = 1;
1424                       long *i2 = &i1;
1425                       return 1;
1426                     }''', name : 'int64_t is long')
1427     int64_t_typedef = 'long'
1428   elif cc.compiles('''#if defined(_AIX) && !defined(__GNUC__)
1429                       #pragma options langlvl=stdc99
1430                       #endif
1431                       #pragma GCC diagnostic error "-Wincompatible-pointer-types"
1432                       #include <stdint.h>
1433                       #include <stdio.h>
1434                       int main () {
1435                         int64_t i1 = 1;
1436                         long long *i2 = &i1;
1437                         return 1;
1438                       }''', name : 'int64_t is long long')
1439     int64_t_typedef = 'long long'
1440   endif
1441 endif
1442
1443 int64_m = 'll'
1444 char_align = cc.alignment('char')
1445 short_align = cc.alignment('short')
1446 int_align = cc.alignment('int')
1447 voidp_align = cc.alignment('void*')
1448 long_align = cc.alignment('long')
1449 long_long_align = cc.alignment('long long')
1450 # NOTE: We don't check for size of __int64 because long long is guaranteed to
1451 # be 64-bit in C99, and it is available on all supported compilers
1452 sizet_align = cc.alignment('size_t')
1453
1454 glib_conf.set('ALIGNOF_UNSIGNED_LONG', long_align)
1455
1456 glib_conf.set('SIZEOF_CHAR', char_size)
1457 glib_conf.set('SIZEOF_INT', int_size)
1458 glib_conf.set('SIZEOF_SHORT', short_size)
1459 glib_conf.set('SIZEOF_LONG', long_size)
1460 glib_conf.set('SIZEOF_LONG_LONG', long_long_size)
1461 glib_conf.set('SIZEOF_SIZE_T', sizet_size)
1462 glib_conf.set('SIZEOF_SSIZE_T', ssizet_size)
1463 glib_conf.set('SIZEOF_VOID_P', voidp_size)
1464 glib_conf.set('SIZEOF_WCHAR_T', cc.sizeof('wchar_t', prefix: '#include <stddef.h>'))
1465
1466 if short_size == 2
1467   gint16 = 'short'
1468   gint16_modifier='h'
1469   gint16_format='hi'
1470   guint16_format='hu'
1471 elif int_size == 2
1472   gint16 = 'int'
1473   gint16_modifier=''
1474   gint16_format='i'
1475   guint16_format='u'
1476 else
1477   error('Compiler provides no native 16-bit integer type')
1478 endif
1479 glibconfig_conf.set('gint16', gint16)
1480 glibconfig_conf.set_quoted('gint16_modifier', gint16_modifier)
1481 glibconfig_conf.set_quoted('gint16_format', gint16_format)
1482 glibconfig_conf.set_quoted('guint16_format', guint16_format)
1483
1484 if short_size == 4
1485   gint32 = 'short'
1486   gint32_modifier='h'
1487   gint32_format='hi'
1488   guint32_format='hu'
1489   guint32_align = short_align
1490 elif int_size == 4
1491   gint32 = 'int'
1492   gint32_modifier=''
1493   gint32_format='i'
1494   guint32_format='u'
1495   guint32_align = int_align
1496 elif long_size == 4
1497   gint32 = 'long'
1498   gint32_modifier='l'
1499   gint32_format='li'
1500   guint32_format='lu'
1501   guint32_align = long_align
1502 else
1503   error('Compiler provides no native 32-bit integer type')
1504 endif
1505 glibconfig_conf.set('gint32', gint32)
1506 glibconfig_conf.set_quoted('gint32_modifier', gint32_modifier)
1507 glibconfig_conf.set_quoted('gint32_format', gint32_format)
1508 glibconfig_conf.set_quoted('guint32_format', guint32_format)
1509 glib_conf.set('ALIGNOF_GUINT32', guint32_align)
1510
1511 if int_size == 8
1512   gint64 = 'int'
1513   gint64_modifier=''
1514   gint64_format='i'
1515   guint64_format='u'
1516   glib_extension=''
1517   gint64_constant='(val)'
1518   guint64_constant='(val)'
1519   guint64_align = int_align
1520 elif long_size == 8 and (long_long_size != long_size or int64_t_typedef == 'long')
1521   gint64 = 'long'
1522   glib_extension=''
1523   gint64_modifier='l'
1524   gint64_format='li'
1525   guint64_format='lu'
1526   gint64_constant='(val##L)'
1527   guint64_constant='(val##UL)'
1528   guint64_align = long_align
1529 elif long_long_size == 8 and (long_long_size != long_size or int64_t_typedef == 'long long')
1530   gint64 = 'long long'
1531   glib_extension='G_GNUC_EXTENSION '
1532   gint64_modifier=int64_m
1533   gint64_format=int64_m + 'i'
1534   guint64_format=int64_m + 'u'
1535   gint64_constant='(G_GNUC_EXTENSION (val##LL))'
1536   guint64_constant='(G_GNUC_EXTENSION (val##ULL))'
1537   guint64_align = long_long_align
1538 else
1539   error('Compiler provides no native 64-bit integer type')
1540 endif
1541 glibconfig_conf.set('glib_extension', glib_extension)
1542 glibconfig_conf.set('gint64', gint64)
1543 glibconfig_conf.set_quoted('gint64_modifier', gint64_modifier)
1544 glibconfig_conf.set_quoted('gint64_format', gint64_format)
1545 glibconfig_conf.set_quoted('guint64_format', guint64_format)
1546 glibconfig_conf.set('gint64_constant', gint64_constant)
1547 glibconfig_conf.set('guint64_constant', guint64_constant)
1548 glib_conf.set('ALIGNOF_GUINT64', guint64_align)
1549
1550 if host_system == 'windows'
1551   glibconfig_conf.set('g_pid_type', 'void*')
1552   glibconfig_conf.set_quoted('g_pid_format', 'p')
1553   if host_machine.cpu_family() == 'x86_64'
1554     glibconfig_conf.set_quoted('g_pollfd_format', '%#' + int64_m + 'x')
1555   else
1556     glibconfig_conf.set_quoted('g_pollfd_format', '%#x')
1557   endif
1558   glibconfig_conf.set('g_dir_separator', '\\\\')
1559   glibconfig_conf.set('g_searchpath_separator', ';')
1560 else
1561   glibconfig_conf.set('g_pid_type', 'int')
1562   glibconfig_conf.set_quoted('g_pid_format', 'i')
1563   glibconfig_conf.set_quoted('g_pollfd_format', '%d')
1564   glibconfig_conf.set('g_dir_separator', '/')
1565   glibconfig_conf.set('g_searchpath_separator', ':')
1566 endif
1567
1568 g_sizet_compatibility = {
1569   'short': sizet_size == short_size,
1570   'int': sizet_size == int_size,
1571   'long': sizet_size == long_size,
1572   'long long': sizet_size == long_long_size,
1573 }
1574
1575 # Do separate checks for gcc/clang (and ignore other compilers for now), since
1576 # we need to explicitly pass -Werror to the compilers.
1577 # FIXME: https://github.com/mesonbuild/meson/issues/5399
1578 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
1579   foreach type_name, size_compatibility : g_sizet_compatibility
1580     g_sizet_compatibility += { type_name: size_compatibility and
1581       cc.compiles(
1582         '''#include <stddef.h>
1583         size_t f (size_t *i) { return *i + 1; }
1584         int main (void) {
1585           unsigned ''' + type_name + ''' i = 0;
1586           f (&i);
1587           return 0;
1588         }''',
1589         args: ['-Werror'],
1590         name : 'GCC size_t typedef is ' + type_name), }
1591   endforeach
1592 endif
1593
1594 if g_sizet_compatibility['short']
1595   glibconfig_conf.set('glib_size_type_define', 'short')
1596   glibconfig_conf.set_quoted('gsize_modifier', 'h')
1597   glibconfig_conf.set_quoted('gssize_modifier', 'h')
1598   glibconfig_conf.set_quoted('gsize_format', 'hu')
1599   glibconfig_conf.set_quoted('gssize_format', 'hi')
1600   glibconfig_conf.set('glib_msize_type', 'SHRT')
1601 elif g_sizet_compatibility['int']
1602   glibconfig_conf.set('glib_size_type_define', 'int')
1603   glibconfig_conf.set_quoted('gsize_modifier', '')
1604   glibconfig_conf.set_quoted('gssize_modifier', '')
1605   glibconfig_conf.set_quoted('gsize_format', 'u')
1606   glibconfig_conf.set_quoted('gssize_format', 'i')
1607   glibconfig_conf.set('glib_msize_type', 'INT')
1608 elif g_sizet_compatibility['long']
1609   glibconfig_conf.set('glib_size_type_define', 'long')
1610   glibconfig_conf.set_quoted('gsize_modifier', 'l')
1611   glibconfig_conf.set_quoted('gssize_modifier', 'l')
1612   glibconfig_conf.set_quoted('gsize_format', 'lu')
1613   glibconfig_conf.set_quoted('gssize_format', 'li')
1614   glibconfig_conf.set('glib_msize_type', 'LONG')
1615 elif g_sizet_compatibility['long long']
1616   glibconfig_conf.set('glib_size_type_define', 'long long')
1617   glibconfig_conf.set_quoted('gsize_modifier', int64_m)
1618   glibconfig_conf.set_quoted('gssize_modifier', int64_m)
1619   glibconfig_conf.set_quoted('gsize_format', int64_m + 'u')
1620   glibconfig_conf.set_quoted('gssize_format', int64_m + 'i')
1621   glibconfig_conf.set('glib_msize_type', 'INT64')
1622 else
1623   error('Could not determine size of size_t.')
1624 endif
1625
1626 if voidp_size == int_size
1627   glibconfig_conf.set('glib_intptr_type_define', 'int')
1628   glibconfig_conf.set_quoted('gintptr_modifier', '')
1629   glibconfig_conf.set_quoted('gintptr_format', 'i')
1630   glibconfig_conf.set_quoted('guintptr_format', 'u')
1631   glibconfig_conf.set('glib_gpi_cast', '(gint)')
1632   glibconfig_conf.set('glib_gpui_cast', '(guint)')
1633 elif voidp_size == long_size
1634   glibconfig_conf.set('glib_intptr_type_define', 'long')
1635   glibconfig_conf.set_quoted('gintptr_modifier', 'l')
1636   glibconfig_conf.set_quoted('gintptr_format', 'li')
1637   glibconfig_conf.set_quoted('guintptr_format', 'lu')
1638   glibconfig_conf.set('glib_gpi_cast', '(glong)')
1639   glibconfig_conf.set('glib_gpui_cast', '(gulong)')
1640 elif voidp_size == long_long_size
1641   glibconfig_conf.set('glib_intptr_type_define', 'long long')
1642   glibconfig_conf.set_quoted('gintptr_modifier', int64_m)
1643   glibconfig_conf.set_quoted('gintptr_format', int64_m + 'i')
1644   glibconfig_conf.set_quoted('guintptr_format', int64_m + 'u')
1645   glibconfig_conf.set('glib_gpi_cast', '(gint64)')
1646   glibconfig_conf.set('glib_gpui_cast', '(guint64)')
1647 else
1648   error('Could not determine size of void *')
1649 endif
1650
1651 if long_size != 8 and long_long_size != 8 and int_size != 8
1652   error('GLib requires a 64-bit type. You might want to consider using the GNU C compiler.')
1653 endif
1654
1655 glibconfig_conf.set('gintbits', int_size * 8)
1656 glibconfig_conf.set('glongbits', long_size * 8)
1657 glibconfig_conf.set('gsizebits', sizet_size * 8)
1658 glibconfig_conf.set('gssizebits', ssizet_size * 8)
1659
1660 # XXX: https://gitlab.gnome.org/GNOME/glib/issues/1413
1661 if host_system == 'windows'
1662   g_module_suffix = 'dll'
1663 else
1664   g_module_suffix = 'so'
1665 endif
1666 glibconfig_conf.set('g_module_suffix', g_module_suffix)
1667
1668 glibconfig_conf.set('GLIB_MAJOR_VERSION', major_version)
1669 glibconfig_conf.set('GLIB_MINOR_VERSION', minor_version)
1670 glibconfig_conf.set('GLIB_MICRO_VERSION', micro_version)
1671 glibconfig_conf.set('GLIB_VERSION', glib_version)
1672
1673 glibconfig_conf.set('glib_void_p', voidp_size)
1674 glibconfig_conf.set('glib_long', long_size)
1675 glibconfig_conf.set('glib_size_t', sizet_size)
1676 glibconfig_conf.set('glib_ssize_t', ssizet_size)
1677 if host_machine.endian() == 'big'
1678   glibconfig_conf.set('g_byte_order', 'G_BIG_ENDIAN')
1679   glibconfig_conf.set('g_bs_native', 'BE')
1680   glibconfig_conf.set('g_bs_alien', 'LE')
1681 else
1682   glibconfig_conf.set('g_byte_order', 'G_LITTLE_ENDIAN')
1683   glibconfig_conf.set('g_bs_native', 'LE')
1684   glibconfig_conf.set('g_bs_alien', 'BE')
1685 endif
1686
1687 # === va_copy checks ===
1688 # we currently check for all three va_copy possibilities, so we get
1689 # all results in config.log for bug reports.
1690
1691 va_copy_func = ''
1692 foreach try_func : [ '__va_copy', 'va_copy' ]
1693   if cc.compiles('''#include <stdarg.h>
1694                     #include <stdlib.h>
1695                     #ifdef _MSC_VER
1696                     # include "msvc_recommended_pragmas.h"
1697                     #endif
1698                     void f (int i, ...) {
1699                     va_list args1, args2;
1700                     va_start (args1, i);
1701                     @0@ (args2, args1);
1702                     if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1703                       exit (1);
1704                     va_end (args1); va_end (args2);
1705                     }
1706                     int main() {
1707                       f (0, 42);
1708                       return 0;
1709                     }'''.format(try_func),
1710                     name : try_func + ' check')
1711     va_copy_func = try_func
1712   endif
1713 endforeach
1714 if va_copy_func != ''
1715   glib_conf.set('G_VA_COPY', va_copy_func)
1716   glib_vacopy = '#define G_VA_COPY ' + va_copy_func
1717 else
1718   glib_vacopy = '/* #undef G_VA_COPY */'
1719 endif
1720
1721 va_list_val_copy_prog = '''
1722   #include <stdarg.h>
1723   #include <stdlib.h>
1724   void f (int i, ...) {
1725     va_list args1, args2;
1726     va_start (args1, i);
1727     args2 = args1;
1728     if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1729       exit (1);
1730     va_end (args1); va_end (args2);
1731   }
1732   int main() {
1733     f (0, 42);
1734     return 0;
1735   }'''
1736
1737 if cc_can_run
1738   rres = cc.run(va_list_val_copy_prog, name : 'va_lists can be copied as values')
1739   glib_va_val_copy = rres.compiled() and rres.returncode() == 0
1740 else
1741   glib_va_val_copy = meson.get_external_property('va_val_copy', true)
1742 endif
1743 if not glib_va_val_copy
1744   glib_vacopy = glib_vacopy + '\n#define G_VA_COPY_AS_ARRAY 1'
1745   glib_conf.set('G_VA_COPY_AS_ARRAY', 1)
1746 endif
1747 glibconfig_conf.set('glib_vacopy', glib_vacopy)
1748
1749 # check for flavours of varargs macros
1750 g_have_iso_c_varargs = cc.compiles('''
1751   void some_func (void) {
1752     int a(int p1, int p2, int p3);
1753     #define call_a(...) a(1,__VA_ARGS__)
1754     call_a(2,3);
1755   }''', name : 'ISO C99 varargs macros in C')
1756
1757 if not g_have_iso_c_varargs
1758   error('GLib requires a C compiler with support for C99 __VA_ARG__ in macros.')
1759 endif
1760
1761 if have_cxx
1762   g_have_iso_cxx_varargs = cxx.compiles('''
1763     void some_func (void) {
1764       int a(int p1, int p2, int p3);
1765       #define call_a(...) a(1,__VA_ARGS__)
1766       call_a(2,3);
1767     }''', name : 'ISO C99 varargs macros in C++')
1768
1769   if not g_have_iso_cxx_varargs
1770     error('GLib requires a C++ compiler with support for C99 __VA_ARG__ in macros.')
1771   endif
1772 endif
1773
1774 g_have_gnuc_varargs = cc.compiles('''
1775   void some_func (void) {
1776     int a(int p1, int p2, int p3);
1777     #define call_a(params...) a(1,params)
1778     call_a(2,3);
1779   }''', name : 'GNUC varargs macros')
1780
1781 if cc.has_header('alloca.h')
1782   glibconfig_conf.set('GLIB_HAVE_ALLOCA_H', true)
1783 endif
1784 has_syspoll = cc.has_header('sys/poll.h')
1785 has_systypes = cc.has_header('sys/types.h')
1786 if has_syspoll
1787   glibconfig_conf.set('GLIB_HAVE_SYS_POLL_H', true)
1788 endif
1789 has_winsock2 = cc.has_header('winsock2.h')
1790
1791 if has_syspoll and has_systypes
1792   poll_includes = '''
1793       #include<sys/poll.h>
1794       #include<sys/types.h>'''
1795 elif has_winsock2
1796   poll_includes = '''
1797       #define _WIN32_WINNT @0@
1798       #include <winsock2.h>'''.format(glib_conf.get('_WIN32_WINNT'))
1799 else
1800   # FIXME?
1801   error('FIX POLL* defines')
1802 endif
1803
1804 poll_defines = [
1805   [ 'POLLIN', 'g_pollin', 1 ],
1806   [ 'POLLOUT', 'g_pollout', 4 ],
1807   [ 'POLLPRI', 'g_pollpri', 2 ],
1808   [ 'POLLERR', 'g_pollerr', 8 ],
1809   [ 'POLLHUP', 'g_pollhup', 16 ],
1810   [ 'POLLNVAL', 'g_pollnval', 32 ],
1811 ]
1812
1813 if has_syspoll and has_systypes
1814   foreach d : poll_defines
1815     val = cc.compute_int(d[0], prefix: poll_includes)
1816     glibconfig_conf.set(d[1], val)
1817   endforeach
1818 elif has_winsock2
1819   # Due to a missed bug in configure.ac the poll test
1820   # never succeeded on Windows and used some pre-defined
1821   # values as a fallback. Keep using them to maintain
1822   # ABI compatibility with autotools builds of glibs
1823   # and with *any* glib-using code compiled against them,
1824   # since these values end up in a public header glibconfig.h.
1825   foreach d : poll_defines
1826     glibconfig_conf.set(d[1], d[2])
1827   endforeach
1828 endif
1829
1830 # Internet address families
1831 # FIXME: what about Cygwin (G_WITH_CYGWIN)
1832 if host_system == 'windows'
1833   inet_includes = '''
1834       #include <winsock2.h>'''
1835 else
1836   inet_includes = '''
1837       #include <sys/types.h>
1838       #include <sys/socket.h>'''
1839 endif
1840
1841 inet_defines = [
1842   [ 'AF_UNIX', 'g_af_unix' ],
1843   [ 'AF_INET', 'g_af_inet' ],
1844   [ 'AF_INET6', 'g_af_inet6' ],
1845   [ 'MSG_OOB', 'g_msg_oob' ],
1846   [ 'MSG_PEEK', 'g_msg_peek' ],
1847   [ 'MSG_DONTROUTE', 'g_msg_dontroute' ],
1848 ]
1849 foreach d : inet_defines
1850   val = cc.compute_int(d[0], prefix: inet_includes)
1851   glibconfig_conf.set(d[1], val)
1852 endforeach
1853
1854 if host_system == 'windows'
1855   have_ipv6 = true
1856 else
1857   have_ipv6 = cc.has_type('struct in6_addr', prefix: '#include <netinet/in.h>')
1858 endif
1859 glib_conf.set('HAVE_IPV6', have_ipv6)
1860
1861 # We need to decide at configure time if GLib will use real atomic
1862 # operations ("lock free") or emulated ones with a mutex.  This is
1863 # because we must put this information in glibconfig.h so we know if
1864 # it is safe or not to inline using compiler intrinsics directly from
1865 # the header.
1866 #
1867 # We also publish the information via G_ATOMIC_LOCK_FREE in case the
1868 # user is interested in knowing if they can use the atomic ops across
1869 # processes.
1870 #
1871 # We can currently support the atomic ops natively when building GLib
1872 # with recent versions of GCC or MSVC.
1873 #
1874 # Note that the atomic ops are only available with GCC on x86 when
1875 # using -march=i486 or higher.  If we detect that the atomic ops are
1876 # not available but would be available given the right flags, we want
1877 # to abort and advise the user to fix their CFLAGS.  It's better to do
1878 # that then to silently fall back on emulated atomic ops just because
1879 # the user had the wrong build environment.
1880 atomictest = '''int main() {
1881   int atomic = 2;
1882   __sync_bool_compare_and_swap (&atomic, 2, 3);
1883   return 0;
1884 }
1885 '''
1886
1887 atomicdefine = '''
1888 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1889 #error "compiler has atomic ops, but doesn't define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4"
1890 #endif
1891 '''
1892
1893 # We know that we can always use real ("lock free") atomic operations with MSVC
1894 if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl' or cc.links(atomictest, name : 'atomic ops')
1895   have_atomic_lock_free = true
1896   if cc.get_id() == 'gcc' and not cc.compiles(atomicdefine, name : 'atomic ops define')
1897     # Old gcc release may provide
1898     # __sync_bool_compare_and_swap but doesn't define
1899     # __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1900     glib_conf.set('__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4', true)
1901   endif
1902
1903   if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
1904     sync_swap_test = '''
1905       int main() {
1906         int atomic = 2;
1907         __sync_swap (&atomic, 2);
1908         return 0;
1909       }
1910     '''
1911
1912     glib_conf.set('_GLIB_GCC_HAVE_SYNC_SWAP', cc.links(sync_swap_test, name : 'sync swap'))
1913   endif
1914 else
1915   have_atomic_lock_free = false
1916   if host_machine.cpu_family() == 'x86' and cc.links(atomictest, args : '-march=i486')
1917     error('GLib must be built with -march=i486 or later.')
1918   endif
1919 endif
1920 glibconfig_conf.set('G_ATOMIC_LOCK_FREE', have_atomic_lock_free)
1921
1922 # === Threads ===
1923
1924 if get_option('force_posix_threads')
1925   warning('DEPRECATION: Option \'force_posix_threads\' is deprecated and will be removed after GLib 2.72; please file an issue with your use case if you still require it')
1926 endif
1927
1928 # Determination of thread implementation
1929 if host_system == 'windows' and not get_option('force_posix_threads')
1930   thread_dep = []
1931   threads_implementation = 'win32'
1932   glibconfig_conf.set('g_threads_impl_def', 'WIN32')
1933   glib_conf.set('THREADS_WIN32', 1)
1934 else
1935   thread_dep = dependency('threads')
1936   threads_implementation = 'posix'
1937   pthread_prefix = '''
1938       #ifndef _GNU_SOURCE
1939       # define _GNU_SOURCE
1940       #endif
1941       #include <pthread.h>'''
1942   glibconfig_conf.set('g_threads_impl_def', 'POSIX')
1943   glib_conf.set('THREADS_POSIX', 1)
1944   if cc.has_header_symbol('pthread.h', 'pthread_attr_setstacksize')
1945     glib_conf.set('HAVE_PTHREAD_ATTR_SETSTACKSIZE', 1)
1946   endif
1947   if cc.has_header_symbol('pthread.h', 'pthread_attr_setinheritsched')
1948     glib_conf.set('HAVE_PTHREAD_ATTR_SETINHERITSCHED', 1)
1949   endif
1950   if cc.has_header_symbol('pthread.h', 'pthread_condattr_setclock')
1951     glib_conf.set('HAVE_PTHREAD_CONDATTR_SETCLOCK', 1)
1952   endif
1953   if cc.has_header_symbol('pthread.h', 'pthread_cond_timedwait_relative_np')
1954     glib_conf.set('HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP', 1)
1955   endif
1956   if cc.has_header_symbol('pthread.h', 'pthread_getname_np', prefix : pthread_prefix)
1957     glib_conf.set('HAVE_PTHREAD_GETNAME_NP', 1)
1958   endif
1959
1960   if cc.has_header_symbol('sys/syscall.h', 'SYS_sched_getattr')
1961     glib_conf.set('HAVE_SYS_SCHED_GETATTR', 1)
1962   endif
1963
1964   # Assume that pthread_setname_np is available in some form; same as configure
1965   if cc.links(pthread_prefix + '''
1966               int main() {
1967                 pthread_setname_np("example");
1968                 return 0;
1969               }''',
1970               name : 'pthread_setname_np(const char*)',
1971               dependencies : thread_dep)
1972     # macOS and iOS
1973     glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID', 1)
1974   elif cc.links(pthread_prefix + '''
1975                 int main() {
1976                   pthread_setname_np(pthread_self(), "example");
1977                   return 0;
1978                 }''',
1979                 name : 'pthread_setname_np(pthread_t, const char*)',
1980                 dependencies : thread_dep)
1981     # Linux, Solaris, etc.
1982     glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID', 1)
1983   elif cc.links(pthread_prefix + '''
1984                 int main() {
1985                   pthread_setname_np(pthread_self(), "%s", "example");
1986                   return 0;
1987                 }''',
1988                 name : 'pthread_setname_np(pthread_t, const char*, void*)',
1989                 dependencies : thread_dep)
1990     # NetBSD
1991     glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID_AND_ARG', 1)
1992   elif cc.links(pthread_prefix + '''
1993                 #include <pthread_np.h>
1994                 int main() {
1995                   pthread_set_name_np(pthread_self(), "example");
1996                   return 0;
1997                 }''',
1998                 name : 'pthread_set_name_np(pthread_t, const char*)',
1999                 dependencies : thread_dep)
2000     # FreeBSD, DragonFlyBSD, OpenBSD, etc.
2001     glib_conf.set('HAVE_PTHREAD_SET_NAME_NP', 1)
2002   endif
2003 endif
2004
2005 # FIXME: we should make it print the result and always return 0, so that
2006 # the output in meson shows up as green
2007 # volatile is needed here to avoid optimisations in the test
2008 stack_grows_check_prog = '''
2009   volatile int *a = 0, *b = 0;
2010   void f (int i) {
2011     volatile int x = 5;
2012     if (i == 0)
2013       b = &x;
2014     else
2015       f (i - 1);
2016   }
2017   int main () {
2018     volatile int y = 7;
2019     a = &y;
2020     f (100);
2021     return b > a ? 0 : 1;
2022   }'''
2023
2024 if cc_can_run
2025   rres = cc.run(stack_grows_check_prog, name : 'stack grows check')
2026   growing_stack = rres.compiled() and rres.returncode() == 0
2027 else
2028   growing_stack = meson.get_external_property('growing_stack', false)
2029 endif
2030
2031 glibconfig_conf.set10('G_HAVE_GROWING_STACK', growing_stack)
2032
2033 # Tests for iconv
2034 #
2035 # We should never use the MinGW C library's iconv because it may not be
2036 # available in the actual runtime environment. On Windows, we always use
2037 # the built-in implementation
2038 if host_system == 'windows'
2039   # We have a #include "win_iconv.c" in gconvert.c on Windows, so we don't need
2040   # any external library for it
2041   libiconv = []
2042 else
2043   libiconv = dependency('iconv')
2044 endif
2045
2046 pcre2 = dependency('libpcre2-8', version: '>= 10.32', required : false)
2047 if not pcre2.found()
2048   if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
2049   # MSVC: Search for the PCRE2 library by the configuration, which corresponds
2050   # to the output of CMake builds of PCRE2.  Note that debugoptimized
2051   # is really a Release build with .PDB files.
2052     if vs_crt == 'debug'
2053       pcre2 = cc.find_library('pcre2d-8', required : false)
2054     else
2055       pcre2 = cc.find_library('pcre2-8', required : false)
2056     endif
2057   endif
2058 endif
2059
2060 # Try again with the fallback
2061 if not pcre2.found()
2062   pcre2 = dependency('libpcre2-8', required : true, fallback : ['pcre2', 'libpcre2_8'])
2063   use_pcre2_static_flag = true
2064 elif host_system == 'windows'
2065   pcre2_static = cc.links('''#define PCRE2_STATIC
2066                              #define PCRE2_CODE_UNIT_WIDTH 8
2067                              #include <pcre2.h>
2068                              int main() {
2069                                void *p = NULL;
2070                                pcre2_code_free(p);
2071                                return 0;
2072                              }''',
2073                          dependencies: pcre2,
2074                          name : 'Windows system PCRE2 is a static build')
2075   use_pcre2_static_flag = pcre2_static
2076 else
2077   use_pcre2_static_flag = false
2078 endif
2079
2080 # Import the gvdb sources as a subproject to avoid having the copylib in-tree
2081 subproject('gvdb')
2082 gvdb_dep = dependency('gvdb')
2083
2084 libm = cc.find_library('m', required : false)
2085 libffi_dep = dependency('libffi', version : '>= 3.0.0', fallback : ['libffi', 'ffi_dep'])
2086
2087 libz_dep = dependency('zlib')
2088
2089 # First check in libc, fallback to libintl, and as last chance build
2090 # proxy-libintl subproject.
2091 # FIXME: glib-gettext.m4 has much more checks to detect broken/uncompatible
2092 # implementations. This could be extended if issues are found in some platforms.
2093 libintl_deps = []
2094 libintl = dependency('intl', required: false)
2095 if libintl.found()
2096   # libintl supports different threading APIs, which may not
2097   # require additional flags, but it defaults to using pthreads if
2098   # found. Meson's "threads" dependency does not allow you to
2099   # prefer pthreads. We may not be using pthreads for glib itself
2100   # either so just link the library to satisfy libintl rather than
2101   # also defining the macros with the -pthread flag.
2102   #
2103   # Meson's builtin dependency lookup as of 0.60.0 doesn't check for
2104   # pthread, so we do this manually here.
2105   if cc.has_function('ngettext', dependencies : libintl)
2106     libintl_deps += [libintl]
2107   else
2108     libintl_pthread = cc.find_library('pthread', required : false)
2109     if libintl_pthread.found() and cc.has_function('ngettext', dependencies : [libintl, libintl_pthread])
2110       libintl_deps += [libintl, libintl_pthread]
2111     else
2112       libintl = disabler()
2113     endif
2114   endif
2115 endif
2116
2117 if libintl.found()
2118   have_bind_textdomain_codeset = cc.has_function('bind_textdomain_codeset', dependencies: libintl_deps)
2119 else
2120   libintl = subproject('proxy-libintl').get_variable('intl_dep')
2121   libintl_deps = [libintl]
2122   have_bind_textdomain_codeset = true  # proxy-libintl supports it
2123 endif
2124
2125 glib_conf.set('HAVE_BIND_TEXTDOMAIN_CODESET', have_bind_textdomain_codeset)
2126
2127 # We require gettext to always be present
2128 glib_conf.set('HAVE_DCGETTEXT', 1)
2129 glib_conf.set('HAVE_GETTEXT', 1)
2130
2131 glib_conf.set_quoted('GLIB_LOCALE_DIR', join_paths(glib_datadir, 'locale'))
2132
2133 # libmount is only used by gio, but we need to fetch the libs to generate the
2134 # pkg-config file below
2135 libmount_dep = []
2136 if host_system == 'linux'
2137   libmount_dep = dependency('mount', version : '>=2.23', required : get_option('libmount'))
2138   glib_conf.set('HAVE_LIBMOUNT', libmount_dep.found())
2139 endif
2140
2141 if host_system == 'windows'
2142   winsock2 = cc.find_library('ws2_32')
2143 else
2144   winsock2 = not_found
2145 endif
2146
2147 selinux_dep = []
2148 if host_system == 'linux'
2149   selinux_dep = dependency('libselinux', version: '>=2.2', required: get_option('selinux'))
2150
2151   glib_conf.set('HAVE_SELINUX', selinux_dep.found())
2152 endif
2153
2154 xattr_dep = []
2155 if host_system != 'windows' and get_option('xattr')
2156   # either glibc or libattr can provide xattr support
2157   # for both of them, we check for getxattr being in
2158   # the library and a valid xattr header.
2159
2160   # try glibc
2161   if cc.has_function('getxattr') and cc.has_header('sys/xattr.h')
2162     glib_conf.set('HAVE_SYS_XATTR_H', 1)
2163     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_SYS_XATTR_H')
2164   #failure. try libattr
2165   elif cc.has_header_symbol('attr/xattr.h', 'getxattr')
2166     glib_conf.set('HAVE_ATTR_XATTR_H', 1)
2167     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_ATTR_XATTR_H')
2168     xattr_dep = [cc.find_library('xattr')]
2169   else
2170     error('No getxattr implementation found in C library or libxattr')
2171   endif
2172
2173   glib_conf.set('HAVE_XATTR', 1)
2174   if cc.compiles(glib_conf_prefix + '''
2175                  #include <stdio.h>
2176                  #ifdef HAVE_SYS_TYPES_H
2177                  #include <sys/types.h>
2178                  #endif
2179                  #ifdef HAVE_SYS_XATTR_H
2180                  #include <sys/xattr.h>
2181                  #elif HAVE_ATTR_XATTR_H
2182                  #include <attr/xattr.h>
2183                  #endif
2184
2185                  int main (void) {
2186                    ssize_t len = getxattr("", "", NULL, 0, 0, XATTR_NOFOLLOW);
2187                    return len;
2188                  }''',
2189                  name : 'XATTR_NOFOLLOW')
2190     glib_conf.set('HAVE_XATTR_NOFOLLOW', 1)
2191   endif
2192 endif
2193
2194 # If strlcpy is present (BSD and similar), check that it conforms to the BSD
2195 # specification. Specifically Solaris 8's strlcpy() does not, see
2196 # https://bugzilla.gnome.org/show_bug.cgi?id=53933 for further context.
2197 if cc.has_function('strlcpy')
2198   if cc_can_run
2199     rres = cc.run('''#include <stdlib.h>
2200                     #include <string.h>
2201                     int main() {
2202                       char p[10];
2203                       (void) strlcpy (p, "hi", 10);
2204                       if (strlcat (p, "bye", 0) != 3)
2205                         return 1;
2206                       return 0;
2207                     }''',
2208                   name : 'OpenBSD strlcpy/strlcat')
2209     if rres.compiled() and rres.returncode() == 0
2210       glib_conf.set('HAVE_STRLCPY', 1)
2211     endif
2212   elif meson.get_external_property('have_strlcpy', false)
2213     glib_conf.set('HAVE_STRLCPY', 1)
2214   endif
2215 endif
2216
2217 cmdline_test_code = '''
2218 #include <fcntl.h>
2219 #include <sys/stat.h>
2220 #include <stdio.h>
2221 #include <stdlib.h>
2222 #include <unistd.h>
2223
2224 static int
2225 __getcmdline (void)
2226 {
2227 /* This code is a dumbed-down version of g_file_get_contents() */
2228 #ifndef O_BINARY
2229 #define O_BINARY 0
2230 #endif
2231 #define BUFSIZE 1024
2232   char result[BUFSIZE];
2233   struct stat stat_buf;
2234
2235   int fd = open ("/proc/self/cmdline", O_RDONLY|O_BINARY);
2236   if (fd < 0)
2237     exit (1);
2238   if (fstat (fd, &stat_buf))
2239     exit (1);
2240
2241   if (stat_buf.st_size > 0 && S_ISREG (stat_buf.st_mode))
2242     {
2243       if (read (fd, result, BUFSIZE) <= 0)
2244         exit (1);
2245     }
2246   else
2247     {
2248       FILE *f = fdopen (fd, "r");
2249       if (f == NULL)
2250         exit (1);
2251
2252       if (fread (result, 1, BUFSIZE, f) <= 0)
2253         exit (1);
2254     }
2255
2256   return 0;
2257 }
2258
2259 int
2260 main (void)
2261 {
2262   exit (__getcmdline ());
2263 }'''
2264
2265 if cc_can_run
2266   rres = cc.run(cmdline_test_code, name : '/proc/self/cmdline')
2267   have_proc_self_cmdline = rres.compiled() and rres.returncode() == 0
2268 else
2269   have_proc_self_cmdline = meson.get_external_property('have_proc_self_cmdline', false)
2270 endif
2271
2272 glib_conf.set('HAVE_PROC_SELF_CMDLINE', have_proc_self_cmdline)
2273
2274 python = import('python').find_installation('python3')
2275 # used for '#!/usr/bin/env <name>'
2276 python_name = 'python3'
2277
2278 python_version = python.language_version()
2279 python_version_req = '>=3.5'
2280 if not python_version.version_compare(python_version_req)
2281   error('Requires Python @0@, @1@ found.'.format(python_version_req, python_version))
2282 endif
2283
2284 # Determine which user environment-dependent files that we want to install
2285 have_bash = find_program('bash', required : false).found() # For completion scripts
2286 bash_comp_dep = dependency('bash-completion', version: '>=2.0', required: false)
2287 have_sh = find_program('sh', required : false).found() # For glib-gettextize
2288
2289 # Some installed tests require a custom environment
2290 env_program = find_program('env', required: installed_tests_enabled)
2291
2292 # FIXME: How to detect Solaris? https://github.com/mesonbuild/meson/issues/1578
2293 if host_system == 'sunos'
2294   glib_conf.set('_XOPEN_SOURCE_EXTENDED', 1)
2295   glib_conf.set('_XOPEN_SOURCE', 2)
2296   glib_conf.set('__EXTENSIONS__',1)
2297 endif
2298
2299 # Sadly Meson does not expose this value:
2300 # https://github.com/mesonbuild/meson/pull/3460
2301 if host_system == 'windows'
2302   # Autotools explicitly removed --Wl,--export-all-symbols from windows builds,
2303   # with no explanation. Do the same here for now but this could be revisited if
2304   # if causes issues.
2305   export_dynamic_ldflags = []
2306 elif host_system == 'cygwin'
2307   export_dynamic_ldflags = ['-Wl,--export-all-symbols']
2308 elif host_system in ['darwin', 'ios']
2309   export_dynamic_ldflags = []
2310 elif host_system == 'sunos'
2311   export_dynamic_ldflags = []
2312 else
2313   export_dynamic_ldflags = ['-Wl,--export-dynamic']
2314 endif
2315
2316 win32_cflags = []
2317 win32_ldflags = []
2318 if host_system == 'windows' and cc.get_id() != 'msvc' and cc.get_id() != 'clang-cl'
2319   # Ensure MSVC-compatible struct packing convention is used when
2320   # compiling for Win32 with gcc. It is used for the whole project and exposed
2321   # in glib-2.0.pc.
2322   win32_cflags = ['-mms-bitfields']
2323   add_project_arguments(win32_cflags, language : 'c')
2324
2325   # Win32 API libs, used only by libglib and exposed in glib-2.0.pc
2326   win32_ldflags = ['-lws2_32', '-lole32', '-lwinmm', '-lshlwapi', '-luuid']
2327 elif host_system == 'cygwin'
2328   win32_ldflags = ['-luser32', '-lkernel32']
2329 endif
2330
2331 # Tracing: dtrace
2332 want_dtrace = get_option('dtrace')
2333 enable_dtrace = false
2334
2335 # Since dtrace support is opt-in we just error out if it was requested but
2336 # is not available. We don't bother with autodetection yet.
2337 if want_dtrace
2338   if glib_have_carbon
2339     error('GLib dtrace support not yet compatible with macOS dtrace')
2340   endif
2341   dtrace = find_program('dtrace', required : true) # error out if not found
2342   if not cc.has_header('sys/sdt.h')
2343     error('dtrace support needs sys/sdt.h header')
2344   endif
2345   # FIXME: autotools build also passes -fPIC -DPIC but is it needed in this case?
2346   dtrace_obj_gen = generator(dtrace,
2347     output : '@BASENAME@.o',
2348     arguments : ['-G', '-s', '@INPUT@', '-o', '@OUTPUT@'])
2349   # FIXME: $(SED) -e "s,define STAP_HAS_SEMAPHORES 1,undef STAP_HAS_SEMAPHORES,"
2350   #               -e "s,define _SDT_HAS_SEMAPHORES 1,undef _SDT_HAS_SEMAPHORES,"
2351   dtrace_hdr_gen = generator(dtrace,
2352     output : '@BASENAME@.h',
2353     arguments : ['-h', '-s', '@INPUT@', '-o', '@OUTPUT@'])
2354   glib_conf.set('HAVE_DTRACE', 1)
2355   enable_dtrace = true
2356 endif
2357
2358 # systemtap
2359 want_systemtap = get_option('systemtap')
2360 enable_systemtap = false
2361
2362 if want_systemtap and enable_dtrace
2363   tapset_install_dir = get_option('tapset_install_dir')
2364   if tapset_install_dir == ''
2365     tapset_install_dir = join_paths(get_option('datadir'), 'systemtap/tapset', host_machine.cpu_family())
2366   endif
2367   stp_cdata = configuration_data()
2368   stp_cdata.set('ABS_GLIB_RUNTIME_LIBDIR', glib_libdir)
2369   stp_cdata.set('LT_CURRENT', minor_version * 100)
2370   stp_cdata.set('LT_REVISION', micro_version)
2371   enable_systemtap = true
2372 endif
2373
2374 test_timeout = 60
2375 test_timeout_slow = 180
2376
2377 pkg = import('pkgconfig')
2378 windows = import('windows')
2379 subdir('glib')
2380 subdir('gobject')
2381 subdir('gthread')
2382 subdir('gmodule')
2383 subdir('gio')
2384 subdir('fuzzing')
2385 subdir('tools')
2386
2387 # xgettext is optional (on Windows for instance)
2388 if find_program('xgettext', required : get_option('nls')).found()
2389   subdir('po')
2390 endif
2391
2392 # Install m4 macros that other projects use
2393 install_data('m4macros/glib-2.0.m4', 'm4macros/glib-gettext.m4', 'm4macros/gsettings.m4',
2394   install_dir : join_paths(get_option('datadir'), 'aclocal'))
2395
2396 configure_file(output : 'config.h', configuration : glib_conf)
2397
2398 if host_system == 'windows'
2399   install_headers([ 'msvc_recommended_pragmas.h' ], subdir : 'glib-2.0')
2400 endif
2401
2402 if get_option('man')
2403   xsltproc = find_program('xsltproc', required : true)
2404   xsltproc_command = [
2405     xsltproc,
2406     '--nonet',
2407     '--stringparam', 'man.output.quietly', '1',
2408     '--stringparam', 'funcsynopsis.style', 'ansi',
2409     '--stringparam', 'man.th.extra1.suppress', '1',
2410     '--stringparam', 'man.authors.section.enabled', '0',
2411     '--stringparam', 'man.copyright.section.enabled', '0',
2412     '-o', '@OUTPUT@',
2413     'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl',
2414     '@INPUT@',
2415   ]
2416   man1_dir = join_paths(glib_prefix, get_option('mandir'), 'man1')
2417 endif
2418
2419 gnome = import('gnome')
2420 subdir('docs/reference')