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