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