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