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