Imported Upstream version 2.57.1
[platform/upstream/glib.git] / meson.build
1 project('glib', 'c', 'cpp',
2   version : '2.57.1',
3   meson_version : '>= 0.46.0',
4   default_options : [
5     'buildtype=debugoptimized',
6     'warning_level=1',
7     'c_std=gnu89'
8   ]
9 )
10
11 cc = meson.get_compiler('c')
12 cxx = meson.get_compiler('cpp')
13
14 cc_can_run = not meson.is_cross_build() or meson.has_exe_wrapper()
15
16 if cc.get_id() == 'msvc'
17   # Ignore several spurious warnings for things glib does very commonly
18   # If a warning is completely useless and spammy, use '/wdXXXX' to suppress it
19   # If a warning is harmless but hard to fix, use '/woXXXX' so it's shown once
20   # NOTE: Only add warnings here if you are sure they're spurious
21   add_project_arguments('/wd4035', '/wd4715', '/wd4116',
22     '/wd4046', '/wd4068', '/wo4090', '/FImsvc_recommended_pragmas.h',language : 'c')
23   # Disable SAFESEH with MSVC for plugins and libs that use external deps that
24   # are built with MinGW
25   noseh_link_args = ['/SAFESEH:NO']
26 else
27   noseh_link_args = []
28   # -mms-bitfields vs -fnative-struct ?
29 endif
30
31 host_system = host_machine.system()
32
33 glib_version = meson.project_version()
34 glib_api_version = '2.0'
35 version_arr = glib_version.split('.')
36 major_version = version_arr[0].to_int()
37 minor_version = version_arr[1].to_int()
38 micro_version = version_arr[2].to_int()
39
40 interface_age = minor_version.is_odd() ? 0 : micro_version
41 binary_age = 100 * minor_version + micro_version
42
43 soversion = 0
44 # Maintain compatibility with previous libtool versioning
45 # current = minor * 100 + micro
46 library_version = '@0@.@1@.@2@'.format(soversion, binary_age - interface_age, interface_age)
47
48 configinc = include_directories('.')
49 glibinc = include_directories('glib')
50 gobjectinc = include_directories('gobject')
51 gmoduleinc = include_directories('gmodule')
52 gioinc = include_directories('gio')
53
54 glib_prefix = get_option('prefix')
55 glib_bindir = join_paths(glib_prefix, get_option('bindir'))
56 glib_libdir = join_paths(glib_prefix, get_option('libdir'))
57 glib_datadir = join_paths(glib_prefix, get_option('datadir'))
58 glib_pkgdatadir = join_paths(glib_datadir, 'glib-2.0')
59 glib_includedir = join_paths(glib_prefix, get_option('includedir'))
60 glib_giomodulesdir = get_option('gio_module_dir')
61 if glib_giomodulesdir == ''
62   glib_giomodulesdir = join_paths(glib_libdir, 'gio', 'modules')
63 endif
64
65 glib_pkgconfigreldir = join_paths(glib_libdir, 'pkgconfig')
66
67 add_project_arguments('-D_GNU_SOURCE', language: 'c')
68
69 # Disable strict aliasing;
70 # see https://bugzilla.gnome.org/show_bug.cgi?id=791622
71 if cc.has_argument('-fno-strict-aliasing')
72   add_project_arguments('-fno-strict-aliasing', language: 'c')
73 endif
74
75 ########################
76 # Configuration begins #
77 ########################
78 glib_conf = configuration_data()
79 glibconfig_conf = configuration_data()
80
81 # accumulated list of defines as we check for them, so we can easily
82 # use them later in test programs (autoconf does this automatically)
83 glib_conf_prefix = ''
84
85 glib_conf.set('GLIB_VERSION', glib_version)
86 glib_conf.set('GLIB_MAJOR_VERSION', major_version)
87 glib_conf.set('GLIB_MINOR_VERSION', minor_version)
88 glib_conf.set('GLIB_MICRO_VERSION', micro_version)
89 glib_conf.set('GLIB_INTERFACE_AGE', interface_age)
90 glib_conf.set('GLIB_BINARY_AGE', binary_age)
91 glib_conf.set_quoted('GETTEXT_PACKAGE', 'glib20')
92 glib_conf.set_quoted('PACKAGE_BUGREPORT', 'http://bugzilla.gnome.org/enter_bug.cgi?product=glib')
93 glib_conf.set_quoted('PACKAGE_NAME', 'glib')
94 glib_conf.set_quoted('PACKAGE_STRING', 'glib @0@'.format(meson.project_version()))
95 glib_conf.set_quoted('PACKAGE_TARNAME', 'glib')
96 glib_conf.set_quoted('PACKAGE_URL', '')
97 glib_conf.set_quoted('PACKAGE_VERSION', meson.project_version())
98 glib_conf.set('ENABLE_NLS', 1)
99
100 # Variables used in glib-gettextize and pkg-config files
101 # These should not contain " quotes around the values
102 glib_conf.set('PACKAGE', 'glib')
103 glib_conf.set('VERSION', meson.project_version())
104 glib_conf.set('prefix', glib_prefix)
105 glib_conf.set('exec_prefix', glib_prefix)
106 glib_conf.set('libdir', glib_libdir)
107 glib_conf.set('includedir', glib_includedir)
108 glib_conf.set('datadir', glib_datadir)
109 glib_conf.set('datarootdir', glib_datadir)
110
111 glib_conf.set('_GNU_SOURCE', 1)
112
113 if host_system == 'windows'
114   # Poll doesn't work on devices on Windows
115   glib_conf.set('BROKEN_POLL', true)
116 endif
117
118 # Check for GNU visibility attributes
119 g_have_gnuc_visibility = cc.compiles('''
120   void
121   __attribute__ ((visibility ("hidden")))
122        f_hidden (void)
123   {
124   }
125   void
126   __attribute__ ((visibility ("internal")))
127        f_internal (void)
128   {
129   }
130   void
131   __attribute__ ((visibility ("protected")))
132        f_protected (void)
133   {
134   }
135   void
136   __attribute__ ((visibility ("default")))
137        f_default (void)
138   {
139   }
140   int main (void)
141   {
142     f_hidden();
143     f_internal();
144     f_protected();
145     f_default();
146     return 0;
147   }
148   ''',
149   # Not supported by MSVC, but MSVC also won't support visibility,
150   # so it's OK to pass -Werror explicitly. Replace with
151   # override_options : 'werror=true' once that is supported
152   args: ['-Werror'],
153   name : 'GNU C visibility attributes test')
154
155 if g_have_gnuc_visibility
156   glibconfig_conf.set('G_HAVE_GNUC_VISIBILITY', '1')
157 endif
158
159 # Detect and set symbol visibility
160 glib_hidden_visibility_args = []
161 if get_option('default_library') != 'static'
162   if host_system == 'windows'
163     glib_conf.set('DLL_EXPORT', true)
164     if cc.get_id() == 'msvc'
165       glib_conf.set('_GLIB_EXTERN', '__declspec(dllexport) extern')
166     elif cc.has_argument('-fvisibility=hidden')
167       glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) __declspec(dllexport) extern')
168       glib_hidden_visibility_args = ['-fvisibility=hidden']
169     endif
170   elif cc.has_argument('-fvisibility=hidden')
171     glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) extern')
172     glib_hidden_visibility_args = ['-fvisibility=hidden']
173   endif
174 endif
175
176 if host_system == 'windows' and get_option('default_library') == 'static'
177     glibconfig_conf.set('GLIB_STATIC_COMPILATION', '1')
178     glibconfig_conf.set('GOBJECT_STATIC_COMPILATION', '1')
179 endif
180
181 # FIXME: what about Cygwin (G_WITH_CYGWIN)
182 if host_system == 'windows'
183   glib_os = '''#define G_OS_WIN32
184 #define G_PLATFORM_WIN32'''
185 else
186   glib_os = '#define G_OS_UNIX'
187 endif
188 glibconfig_conf.set('glib_os', glib_os)
189
190 # We need to know the build type to determine what .lib files we need on Visual Studio
191 # for dependencies that don't normally come with pkg-config files for Visual Studio builds
192 buildtype = get_option('buildtype')
193
194 glib_debug_cflags = []
195 if buildtype.startswith('debug')
196   glib_debug_cflags += ['-DG_ENABLE_DEBUG']
197 elif buildtype == 'release'
198   glib_debug_cflags += ['-DG_DISABLE_CAST_CHECKS']
199 endif
200
201 add_project_arguments(glib_debug_cflags, language: 'c')
202
203 # check for header files
204
205 headers = [
206   'stdlib.h',
207   'string.h',
208   'strings.h',
209   'memory.h',
210   'alloca.h',
211   'locale.h',
212   'xlocale.h',
213   'float.h',
214   'limits.h',
215   'pwd.h',
216   'grp.h',
217   'poll.h',
218   'termios.h',
219   'sys/param.h',
220   'sys/resource.h',
221   'mach/mach_time.h',
222   'sys/select.h',
223   'stdint.h',
224   'inttypes.h',
225   'sched.h',
226   'malloc.h',
227   'sys/vfs.h',
228   'sys/vmount.h',
229   'sys/statfs.h',
230   'sys/statvfs.h',
231   'sys/filio.h',
232   'mntent.h',
233   'sys/mnttab.h',
234   'sys/vfstab.h',
235   'sys/mntctl.h',
236   'fstab.h',
237   'linux/magic.h',
238   'termios.h',
239   'dirent.h', # MSC does not come with this by default
240   'sys/time.h', # MSC does not come with this by default
241   'sys/times.h',
242   'sys/wait.h',
243   'unistd.h',
244   'values.h',
245   'sys/types.h',
246   'sys/uio.h',
247   'sys/mkdev.h',
248   'sys/mount.h',
249   'sys/sysctl.h',
250   'crt_externs.h',
251   'sys/inotify.h',
252   'sys/event.h',
253   'sys/stat.h',
254 ]
255
256 foreach h : headers
257   if cc.has_header(h)
258     define = 'HAVE_' + h.underscorify().to_upper()
259     glib_conf.set(define, 1)
260     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
261   endif
262 endforeach
263
264 if cc.has_header('linux/netlink.h')
265   glib_conf.set('HAVE_NETLINK', 1)
266 endif
267
268 if glib_conf.has('HAVE_LOCALE_H')
269   if cc.has_header_symbol('locale.h', 'LC_MESSAGES')
270     glib_conf.set('HAVE_LC_MESSAGES', 1)
271   endif
272 endif
273
274 struct_stat_blkprefix = '''
275 #include <sys/types.h>
276 #include <sys/stat.h>
277 #ifdef HAVE_UNISTD_H
278 #include <unistd.h>
279 #endif
280 #ifdef HAVE_SYS_STATFS_H
281 #include <sys/statfs.h>
282 #endif
283 #ifdef HAVE_SYS_PARAM_H
284 #include <sys/param.h>
285 #endif
286 #ifdef HAVE_SYS_MOUNT_H
287 #include <sys/mount.h>
288 #endif
289 '''
290
291 struct_members = [
292   [ 'stat', 'st_mtimensec' ],
293   [ 'stat', 'st_mtim.tv_nsec' ],
294   [ 'stat', 'st_atimensec' ],
295   [ 'stat', 'st_atim.tv_nsec' ],
296   [ 'stat', 'st_ctimensec' ],
297   [ 'stat', 'st_ctim.tv_nsec' ],
298   [ 'stat', 'st_birthtime' ],
299   [ 'stat', 'st_birthtimensec' ],
300   [ 'stat', 'st_birthtim' ],
301   [ 'stat', 'st_birthtim.tv_nsec' ],
302   [ 'stat', 'st_blksize', struct_stat_blkprefix ],
303   [ 'stat', 'st_blocks', struct_stat_blkprefix ],
304   [ 'statfs', 'f_fstypename', struct_stat_blkprefix ],
305   [ 'statfs', 'f_bavail', struct_stat_blkprefix ],
306   [ 'dirent', 'd_type', '''#include <sys/types.h>
307                            #include <dirent.h>''' ],
308 ]
309
310 foreach m : struct_members
311   header_check_prefix = glib_conf_prefix
312   if m.length() == 3
313     header_check_prefix = header_check_prefix + m[2]
314   else
315     header_check_prefix = header_check_prefix + '#include <sys/stat.h>'
316   endif
317   if cc.has_member('struct ' + m[0], m[1], prefix : header_check_prefix)
318     define = 'HAVE_STRUCT_@0@_@1@'.format(m[0].to_upper(), m[1].underscorify().to_upper())
319     glib_conf.set(define, 1)
320     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
321   else
322   endif
323 endforeach
324
325 # Compiler flags
326 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
327   test_c_args = [
328     '-Wall',
329     '-Wduplicated-branches',
330     '-Wstrict-prototypes',
331     '-Werror=declaration-after-statement',
332     '-Werror=format=2',
333     '-Werror=format-security',
334     '-Werror=implicit-function-declaration',
335     '-Werror=init-self',
336     '-Werror=missing-include-dirs',
337     '-Werror=missing-prototypes',
338     '-Werror=pointer-arith',
339   ]
340   test_c_link_args = [
341     '-Wl,-z,nodelete',
342   ]
343   if get_option('bsymbolic_functions')
344     test_c_link_args += ['-Wl,-Bsymbolic-functions']
345   endif
346 else
347   test_c_args = []
348   test_c_link_args = []
349 endif
350
351 add_project_arguments(cc.get_supported_arguments(test_c_args), language: 'c')
352
353 # FIXME: We cannot build some of the GResource tests with -z nodelete, which
354 # means we cannot use that flag in add_project_link_arguments(), and must add
355 # it to the relevant targets manually. We do the same with -Bsymbolic-functions
356 # because that is what the autotools build did.
357 # See https://github.com/mesonbuild/meson/pull/3520 for a way to eventually
358 # improve this.
359 glib_link_flags = cc.get_supported_link_arguments(test_c_link_args)
360
361 # Windows Support (Vista+)
362 if host_system == 'windows'
363   glib_conf.set('_WIN32_WINNT', '0x0601')
364 endif
365
366 functions = [
367   'alloca',
368   'mmap',
369   'memalign',
370   'valloc',
371   'fsync',
372   'pipe2',
373   'issetugid',
374   'timegm',
375   'gmtime_r',
376   'strerror_r',
377   'lstat',
378   'strsignal',
379   'vsnprintf',
380   'poll',
381   'vasprintf',
382   'setenv',
383   'unsetenv',
384   'getc_unlocked',
385   'readlink',
386   'symlink',
387   'fdwalk',
388   'lchmod',
389   'lchown',
390   'fchmod',
391   'fchown',
392   'utimes',
393   'getresuid',
394   'getmntent_r',
395   'setmntent',
396   'endmntent',
397   'hasmntopt',
398   'getfsstat',
399   'getvfsstat',
400   'fallocate',
401   'localtime_r',
402   'gmtime_r',
403   'getpwuid_r',
404   'getgrgid_r',
405   'prlimit',
406   'strnlen',
407   'wcslen',
408   'wcsnlen',
409   'mbrtowc',
410   'wcrtomb',
411   'newlocale',
412   'uselocale',
413   'strtod_l',
414   'strtoll_l',
415   'strtoull_l',
416   'inotify_init1',
417   'kqueue',
418   'kevent',
419   'endservent',
420   'sendmmsg',
421   'recvmmsg',
422   'link',
423 ]
424
425 if glib_conf.has('HAVE_SYS_STATVFS_H')
426   functions += ['statvfs']
427 else
428   have_func_statvfs = false
429 endif
430 if glib_conf.has('HAVE_SYS_STATFS_H') or glib_conf.has('HAVE_SYS_MOUNT_H')
431   functions += ['statfs']
432 else
433   have_func_statfs = false
434 endif
435
436 if host_system == 'windows'
437   iphlpapi_dep = cc.find_library('iphlpapi')
438   iphlpapi_funcs = ['if_nametoindex', 'if_indextoname']
439   foreach ifunc : iphlpapi_funcs
440     if cc.has_function(ifunc,
441                        prefix : '#define _WIN32_WINNT 0x0601\n#include <winsock2.h>\n#include <iphlpapi.h>',
442                        dependencies : iphlpapi_dep)
443       idefine = 'HAVE_' + ifunc.underscorify().to_upper()
444       glib_conf.set(idefine, 1)
445       glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(idefine)
446       set_variable('have_func_' + ifunc, true)
447     else
448       set_variable('have_func_' + ifunc, false)
449     endif
450   endforeach
451 else
452   functions += ['if_indextoname', 'if_nametoindex']
453 endif
454
455 # AIX splice is something else
456 if host_system != 'aix'
457   functions += ['splice']
458 endif
459
460 foreach f : functions
461   if cc.has_function(f)
462     define = 'HAVE_' + f.underscorify().to_upper()
463     glib_conf.set(define, 1)
464     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
465     set_variable('have_func_' + f, true)
466   else
467     set_variable('have_func_' + f, false)
468   endif
469 endforeach
470
471 # Check that stpcpy() is usable; must use header
472 if cc.has_function('stpcpy', prefix : '#include <string.h>')
473   glib_conf.set('HAVE_STPCPY', 1)
474 endif
475
476 # Check that posix_memalign() is usable; must use header
477 if cc.has_function('posix_memalign', prefix : '#include <stdlib.h>')
478   glib_conf.set('HAVE_POSIX_MEMALIGN', 1)
479 endif
480
481 # Check whether strerror_r returns char *
482 if have_func_strerror_r
483   if cc.compiles('''#define _GNU_SOURCE
484                     #include <string.h>
485                     int func (void) {
486                       char error_string[256];
487                       char *ptr = strerror_r (-2, error_string, 256);
488                       char c = *strerror_r (-2, error_string, 256);
489                       return c != 0 && ptr != (void*) 0L;
490                     }
491                  ''',
492                  name : 'strerror_r() returns char *')
493     glib_conf.set('STRERROR_R_CHAR_P', 1,
494                   description: 'Defined if strerror_r returns char *')
495   endif
496 endif
497
498 # Special-case these functions that have alternative names on Windows/MSVC
499 if cc.has_function('snprintf') or cc.has_header_symbol('stdio.h', 'snprintf')
500   glib_conf.set('HAVE_SNPRINTF', 1)
501   glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF 1\n'
502 elif cc.has_function('_snprintf') or cc.has_header_symbol('stdio.h', '_snprintf')
503   hack_define = '1\n#define snprintf _snprintf'
504   glib_conf.set('HAVE_SNPRINTF', hack_define)
505   glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF ' + hack_define
506 endif
507
508 if cc.has_function('strcasecmp')
509   glib_conf.set('HAVE_STRCASECMP', 1)
510   glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP 1\n'
511 elif cc.has_function('_stricmp')
512   hack_define = '1\n#define strcasecmp _stricmp'
513   glib_conf.set('HAVE_STRCASECMP', hack_define)
514   glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP ' + hack_define
515 endif
516
517 if cc.has_function('strncasecmp')
518   glib_conf.set('HAVE_STRNCASECMP', 1)
519   glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP 1\n'
520 elif cc.has_function('_strnicmp')
521   hack_define = '1\n#define strncasecmp _strnicmp'
522   glib_conf.set('HAVE_STRNCASECMP', hack_define)
523   glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP ' + hack_define
524 endif
525
526 if cc.has_header_symbol('sys/sysmacros.h', 'major')
527   glib_conf.set('MAJOR_IN_SYSMACROS', 1)
528 elif cc.has_header_symbol('sys/mkdev.h', 'major')
529   glib_conf.set('MAJOR_IN_MKDEV', 1)
530 endif
531
532 if cc.has_header_symbol('dlfcn.h', 'RTLD_LAZY')
533   glib_conf.set('HAVE_RTLD_LAZY', 1)
534 endif
535
536 if cc.has_header_symbol('dlfcn.h', 'RTLD_NOW')
537   glib_conf.set('HAVE_RTLD_NOW', 1)
538 endif
539
540 if cc.has_header_symbol('dlfcn.h', 'RTLD_GLOBAL')
541   glib_conf.set('HAVE_RTLD_GLOBAL', 1)
542 endif
543
544 # Check whether to use statfs or statvfs
545 # Some systems have both statfs and statvfs, pick the most "native" for these
546 if have_func_statfs and have_func_statvfs
547   # on solaris and irix, statfs doesn't even have the f_bavail field
548   if not glib_conf.has('HAVE_STRUCT_STATFS_F_BAVAIL')
549     have_func_statfs = false
550   else
551     # at least on linux, statfs is the actual syscall
552     have_func_statvfs = false
553   endif
554 endif
555 if have_func_statfs
556   glib_conf.set('USE_STATFS', 1)
557   stat_func_to_use = 'statfs'
558 elif have_func_statvfs
559   glib_conf.set('USE_STATVFS', 1)
560   stat_func_to_use = 'statvfs'
561 else
562   stat_func_to_use = 'neither'
563 endif
564 message('Checking whether to use statfs or statvfs .. ' + stat_func_to_use)
565
566 if host_system == 'linux'
567   if cc.has_function('mkostemp',
568                      prefix: '''#define _GNU_SOURCE
569                                 #include <stdlib.h>''')
570     glib_conf.set('HAVE_MKOSTEMP', 1)
571   endif
572 endif
573
574 osx_ldflags = []
575
576 # Mac OS X Carbon support
577 glib_have_carbon = cc.compiles('''#include <Carbon/Carbon.h>
578                                   #include <CoreServices/CoreServices.h>''',
579                                name : 'Mac OS X Carbon support')
580
581 glib_have_os_x_9_or_later = false
582
583 if glib_have_carbon
584   glib_conf.set('HAVE_CARBON', true)
585   osx_ldflags += '-Wl,-framework,Carbon'
586   glib_have_os_x_9_or_later = cc.compiles('''#include <AvailabilityMacros.h>
587                                              #if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
588                                              #error Compiling for minimum OS X version before 10.9
589                                              #endif''', name : 'OS X 9 or later')
590 endif
591
592 # Mac OS X Cocoa support
593 glib_have_cocoa = cc.compiles('''#include <Cocoa/Cocoa.h>
594                                  #ifdef GNUSTEP_BASE_VERSION
595                                  #error "Detected GNUstep, not Cocoa"
596                                  #endif''',
597                               name : 'Mac OS X Cocoa support')
598
599 if glib_have_cocoa
600   glib_conf.set('HAVE_COCOA', true)
601   osx_ldflags += ['-Wl,-framework,Foundation', '-Wl,-framework,AppKit']
602 endif
603
604 add_project_link_arguments(osx_ldflags, language : 'c')
605
606 # Check for futex(2)
607 if cc.links('''#include <linux/futex.h>
608                #include <sys/syscall.h>
609                #include <unistd.h>
610                int main (int argc, char ** argv) {
611                  syscall (__NR_futex, NULL, FUTEX_WAKE, FUTEX_WAIT);
612                  return 0;
613                }''', name : 'futex(2) system call')
614   glib_conf.set('HAVE_FUTEX', 1)
615 endif
616
617 # Check for eventfd(2)
618 if cc.links('''#include <sys/eventfd.h>
619                #include <unistd.h>
620                int main (int argc, char ** argv) {
621                  eventfd (0, EFD_CLOEXEC);
622                  return 0;
623                }''', name : 'eventfd(2) system call')
624   glib_conf.set('HAVE_EVENTFD', 1)
625 endif
626
627 clock_gettime_test_code = '''
628   #include <time.h>
629   struct timespec t;
630   int main (int argc, char ** argv) {
631     return clock_gettime(CLOCK_REALTIME, &t);
632   }'''
633 librt = []
634 if cc.links(clock_gettime_test_code, name : 'clock_gettime')
635   glib_conf.set('HAVE_CLOCK_GETTIME', 1)
636 elif cc.links(clock_gettime_test_code, args : '-lrt', name : 'clock_gettime in librt')
637   glib_conf.set('HAVE_CLOCK_GETTIME', 1)
638   librt = cc.find_library('rt')
639 endif
640
641 # if statfs() takes 2 arguments (Posix) or 4 (Solaris)
642 if have_func_statfs
643   if cc.compiles(glib_conf_prefix + '''
644                  #include <unistd.h>
645                         #ifdef HAVE_SYS_PARAM_H
646                         #include <sys/param.h>
647                         #endif
648                         #ifdef HAVE_SYS_VFS_H
649                         #include <sys/vfs.h>
650                         #endif
651                         #ifdef HAVE_SYS_MOUNT_H
652                         #include <sys/mount.h>
653                         #endif
654                         #ifdef HAVE_SYS_STATFS_H
655                         #include <sys/statfs.h>
656                         #endif
657                         void some_func (void) {
658                           struct statfs st;
659                           statfs("/", &st);
660                         }''', name : 'number of arguments to statfs() (n=2)')
661     glib_conf.set('STATFS_ARGS', 2)
662   elif cc.compiles(glib_conf_prefix + '''
663                    #include <unistd.h>
664                           #ifdef HAVE_SYS_PARAM_H
665                           #include <sys/param.h>
666                           #endif
667                           #ifdef HAVE_SYS_VFS_H
668                           #include <sys/vfs.h>
669                           #endif
670                           #ifdef HAVE_SYS_MOUNT_H
671                           #include <sys/mount.h>
672                           #endif
673                           #ifdef HAVE_SYS_STATFS_H
674                           #include <sys/statfs.h>
675                           #endif
676                           void some_func (void) {
677                             struct statfs st;
678                             statfs("/", &st, sizeof (st), 0);
679                           }''', name : 'number of arguments to statfs() (n=4)')
680     glib_conf.set('STATFS_ARGS', 4)
681   else
682     error('Unable to determine number of arguments to statfs()')
683   endif
684 endif
685
686 # open takes O_DIRECTORY as an option
687 #AC_MSG_CHECKING([])
688 if cc.compiles('''#include <fcntl.h>
689                   #include <sys/types.h>
690                   #include <sys/stat.h>],
691                   void some_func (void) {
692                     open(0, O_DIRECTORY, 0);
693                   }''', name : 'open() option O_DIRECTORY')
694   glib_conf.set('HAVE_OPEN_O_DIRECTORY', 1)
695 endif
696
697 # Check whether there is a vsnprintf() function with C99 semantics installed.
698 # AC_FUNC_VSNPRINTF_C99
699 # Check whether there is a snprintf() function with C99 semantics installed.
700 # AC_FUNC_SNPRINTF_C99
701
702 have_good_vsnprintf = false
703 have_good_snprintf = false
704
705 if host_system == 'windows' and cc.get_id() == 'msvc'
706   # Unfortunately the Visual Studio 2015+ implementations of C99-style
707   # snprintf and vsnprintf don't seem to be quite good enough.
708   # (Sorry, I don't know exactly what is the problem,
709   # but it is related to floating point formatting and decimal point vs. comma.)
710   # The simple tests in AC_FUNC_VSNPRINTF_C99 and AC_FUNC_SNPRINTF_C99 aren't
711   # rigorous enough to notice, though.
712   glib_conf.set('HAVE_C99_SNPRINTF', false)
713   glib_conf.set('HAVE_C99_VSNPRINTF', false)
714 else
715   vsnprintf_c99_test_code = '''
716 #include <stdio.h>
717 #include <stdarg.h>
718
719 int
720 doit(char * s, ...)
721 {
722   char buffer[32];
723   va_list args;
724   int r;
725
726   va_start(args, s);
727   r = vsnprintf(buffer, 5, s, args);
728   va_end(args);
729
730   if (r != 7)
731     exit(1);
732
733   /* AIX 5.1 and Solaris seems to have a half-baked vsnprintf()
734      implementation. The above will return 7 but if you replace
735      the size of the buffer with 0, it borks! */
736   va_start(args, s);
737   r = vsnprintf(buffer, 0, s, args);
738   va_end(args);
739
740   if (r != 7)
741     exit(1);
742
743   exit(0);
744 }
745
746 int
747 main(void)
748 {
749   doit("1234567");
750   exit(1);
751 }'''
752
753   if cc_can_run
754     rres = cc.run(vsnprintf_c99_test_code, name : 'C99 vsnprintf')
755     if rres.compiled() and rres.returncode() == 0
756       glib_conf.set('HAVE_C99_VSNPRINTF', 1)
757       have_good_vsnprintf = true
758     endif
759   else
760       have_good_vsnprintf = meson.get_cross_property('have_c99_vsnprintf', false)
761       glib_conf.set('HAVE_C99_VSNPRINTF', have_good_vsnprintf)
762   endif
763
764   snprintf_c99_test_code = '''
765 #include <stdio.h>
766 #include <stdarg.h>
767
768 int
769 doit()
770 {
771   char buffer[32];
772   va_list args;
773   int r;
774
775   r = snprintf(buffer, 5, "1234567");
776
777   if (r != 7)
778     exit(1);
779
780   r = snprintf(buffer, 0, "1234567");
781
782   if (r != 7)
783     exit(1);
784
785   r = snprintf(NULL, 0, "1234567");
786
787   if (r != 7)
788     exit(1);
789
790   exit(0);
791 }
792
793 int
794 main(void)
795 {
796   doit();
797   exit(1);
798 }'''
799
800   if cc_can_run
801     rres = cc.run(snprintf_c99_test_code, name : 'C99 snprintf')
802     if rres.compiled() and rres.returncode() == 0
803       glib_conf.set('HAVE_C99_SNPRINTF', 1)
804       have_good_snprintf = true
805     endif
806   else
807       have_good_snprintf = meson.get_cross_property('have_c99_snprintf', false)
808       glib_conf.set('HAVE_C99_SNPRINTF', have_good_snprintf)
809   endif
810 endif
811
812 if host_system == 'windows'
813   glib_conf.set_quoted('EXEEXT', '.exe')
814 else
815   glib_conf.set('EXEEXT', '')
816 endif
817
818 if have_good_vsnprintf and have_good_snprintf
819   # Our printf is 'good' only if vsnpintf()/snprintf() supports C99 well enough
820   glib_conf.set('HAVE_GOOD_PRINTF', 1) # FIXME: Check for HAVE_UNIX98_PRINTF?
821 else
822   glib_conf.set('HAVE_VASPRINTF', 1)
823 endif
824
825 # Check whether the printf() family supports Unix98 %n$ positional parameters
826 # AC_FUNC_PRINTF_UNIX98
827 # Nothing uses HAVE_UNIX98_PRINTF
828
829
830 # Check for nl_langinfo and CODESET
831 # FIXME: Check for HAVE_BIND_TEXTDOMAIN_CODESET
832 if cc.links('''#include <langinfo.h>
833                int main (int argc, char ** argv) {
834                  char *codeset = nl_langinfo (CODESET);
835                  return 0;
836                }''', name : 'nl_langinfo and CODESET')
837   glib_conf.set('HAVE_LANGINFO_CODESET', 1)
838   glib_conf.set('HAVE_CODESET', 1)
839 endif
840
841 # Check for nl_langinfo and LC_TIME parts that are needed in gdatetime.c
842 if cc.links('''#include <langinfo.h>
843                int main (int argc, char ** argv) {
844                  char *str;
845                  str = nl_langinfo (PM_STR);
846                  str = nl_langinfo (D_T_FMT);
847                  str = nl_langinfo (D_FMT);
848                  str = nl_langinfo (T_FMT);
849                  str = nl_langinfo (T_FMT_AMPM);
850                  str = nl_langinfo (MON_1);
851                  str = nl_langinfo (ABMON_12);
852                  str = nl_langinfo (DAY_1);
853                  str = nl_langinfo (ABDAY_7);
854                  return 0;
855                }''', name : 'nl_langinfo (PM_STR)')
856   glib_conf.set('HAVE_LANGINFO_TIME', 1)
857 endif
858 if cc.links('''#include <langinfo.h>
859                int main (int argc, char ** argv) {
860                  char *str;
861                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT0_MB);
862                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT1_MB);
863                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT2_MB);
864                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT3_MB);
865                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT4_MB);
866                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT5_MB);
867                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT6_MB);
868                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT7_MB);
869                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT8_MB);
870                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT9_MB);
871                  return 0;
872                }''', name : 'nl_langinfo (_NL_CTYPE_OUTDIGITn_MB)')
873   glib_conf.set('HAVE_LANGINFO_OUTDIGIT', 1)
874 endif
875
876 # Check for nl_langinfo and alternative month names
877 if cc.links('''#ifndef _GNU_SOURCE
878               # define _GNU_SOURCE
879               #endif
880               #include <langinfo.h>
881                int main (int argc, char ** argv) {
882                  char *str;
883                  str = nl_langinfo (ALTMON_1);
884                  str = nl_langinfo (ALTMON_2);
885                  str = nl_langinfo (ALTMON_3);
886                  str = nl_langinfo (ALTMON_4);
887                  str = nl_langinfo (ALTMON_5);
888                  str = nl_langinfo (ALTMON_6);
889                  str = nl_langinfo (ALTMON_7);
890                  str = nl_langinfo (ALTMON_8);
891                  str = nl_langinfo (ALTMON_9);
892                  str = nl_langinfo (ALTMON_10);
893                  str = nl_langinfo (ALTMON_11);
894                  str = nl_langinfo (ALTMON_12);
895                  return 0;
896                }''', name : 'nl_langinfo (ALTMON_n)')
897   glib_conf.set('HAVE_LANGINFO_ALTMON', 1)
898 endif
899
900 # Check for nl_langinfo and abbreviated alternative month names
901 if cc.links('''#ifndef _GNU_SOURCE
902               # define _GNU_SOURCE
903               #endif
904               #include <langinfo.h>
905                int main (int argc, char ** argv) {
906                  char *str;
907                  str = nl_langinfo (_NL_ALTMON_1);
908                  str = nl_langinfo (_NL_ALTMON_2);
909                  str = nl_langinfo (_NL_ALTMON_3);
910                  str = nl_langinfo (_NL_ALTMON_4);
911                  str = nl_langinfo (_NL_ALTMON_5);
912                  str = nl_langinfo (_NL_ALTMON_6);
913                  str = nl_langinfo (_NL_ALTMON_7);
914                  str = nl_langinfo (_NL_ALTMON_8);
915                  str = nl_langinfo (_NL_ALTMON_9);
916                  str = nl_langinfo (_NL_ALTMON_10);
917                  str = nl_langinfo (_NL_ALTMON_11);
918                  str = nl_langinfo (_NL_ALTMON_12);
919                  return 0;
920                }''', name : 'nl_langinfo (_NL_ALTMON_n)')
921   glib_conf.set('HAVE_LANGINFO_ABALTMON', 1)
922 endif
923
924 # Check if C compiler supports the 'signed' keyword
925 if not cc.compiles('''signed char x;''', name : 'signed')
926   glib_conf.set('signed', '/* NOOP */')
927 endif
928
929 # Check if the ptrdiff_t type exists
930 if cc.has_header_symbol('stddef.h', 'ptrdiff_t')
931   glib_conf.set('HAVE_PTRDIFF_T', 1)
932 endif
933
934 # Check for sig_atomic_t type
935 if cc.links('''#include <signal.h>
936                #include <sys/types.h>
937                sig_atomic_t val = 42;
938                int main (int argc, char ** argv) {
939                  return val == 42 ? 0 : 1;
940                }''', name : 'sig_atomic_t')
941   glib_conf.set('HAVE_SIG_ATOMIC_T', 1)
942 endif
943
944 # Check if 'long long' works and what format can be used to print it
945 # jm_AC_TYPE_LONG_LONG
946 # Nothing uses HAVE_LONG_LONG_FORMAT and HAVE_INT64_AND_I64
947 if cc.compiles('''long long ll = 1LL;
948                   int i = 63;
949                   int some_func (void) {
950                     long long llmax = (long long) -1;
951                     return ll << i | ll >> i | llmax / ll | llmax % ll;
952                   }''', name : 'long long')
953   glib_conf.set('HAVE_LONG_LONG', 1)
954   have_long_long = true
955 else
956   have_long_long = false
957 endif
958
959 # Test whether the compiler supports the 'long double' type.
960 if cc.compiles('''/* The Stardent Vistra knows sizeof(long double), but does not support it.  */
961                   long double foo = 0.0;
962                   /* On Ultrix 4.3 cc, long double is 4 and double is 8.  */
963                   int array [2*(sizeof(long double) >= sizeof(double)) - 1];''',
964                name : 'long double')
965   glib_conf.set('HAVE_LONG_DOUBLE', 1)
966 endif
967
968 # Test whether <stddef.h> has the 'wchar_t' type.
969 if cc.has_header_symbol('stddef.h', 'wchar_t')
970   glib_conf.set('HAVE_WCHAR_T', 1)
971 endif
972
973 # Test whether <wchar.h> has the 'wint_t' type.
974 if cc.has_header_symbol('wchar.h', 'wint_t')
975   glib_conf.set('HAVE_WINT_T', 1)
976 endif
977
978 found_uintmax_t = false
979
980 # Define HAVE_INTTYPES_H_WITH_UINTMAX if <inttypes.h> exists,
981 # doesn't clash with <sys/types.h>, and declares uintmax_t.
982 # jm_AC_HEADER_INTTYPES_H
983 if cc.compiles('''#include <sys/types.h>
984                   #include <inttypes.h>
985                   void some_func (void) {
986                     uintmax_t i = (uintmax_t) -1;
987                   }''', name : 'uintmax_t in inttypes.h')
988   glib_conf.set('HAVE_INTTYPES_H_WITH_UINTMAX', 1)
989   found_uintmax_t = true
990 endif
991
992 # Define HAVE_STDINT_H_WITH_UINTMAX if <stdint.h> exists,
993 # doesn't clash with <sys/types.h>, and declares uintmax_t.
994 # jm_AC_HEADER_STDINT_H
995 if cc.compiles('''#include <sys/types.h>
996                   #include <stdint.h>
997                   void some_func (void) {
998                     uintmax_t i = (uintmax_t) -1;
999                   }''', name : 'uintmax_t in stdint.h')
1000   glib_conf.set('HAVE_STDINT_H_WITH_UINTMAX', 1)
1001   found_uintmax_t = true
1002 endif
1003
1004 # Define intmax_t to 'long' or 'long long'
1005 # if it is not already defined in <stdint.h> or <inttypes.h>.
1006 # For simplicity, we assume that a header file defines 'intmax_t' if and
1007 # only if it defines 'uintmax_t'.
1008 if found_uintmax_t
1009   glib_conf.set('HAVE_INTMAX_T', 1)
1010 elif have_long_long
1011   glib_conf.set('intmax_t', 'long long')
1012 else
1013   glib_conf.set('intmax_t', 'long')
1014 endif
1015
1016 char_size = cc.sizeof('char')
1017 short_size = cc.sizeof('short')
1018 int_size = cc.sizeof('int')
1019 voidp_size = cc.sizeof('void*')
1020 long_size = cc.sizeof('long')
1021 if have_long_long
1022   long_long_size = cc.sizeof('long long')
1023 else
1024   long_long_size = 0
1025 endif
1026 sizet_size = cc.sizeof('size_t')
1027 if cc.get_id() == 'msvc'
1028   ssizet_size = cc.sizeof('SSIZE_T', prefix : '#include <BaseTsd.h>')
1029 else
1030   ssizet_size = cc.sizeof('ssize_t')
1031 endif
1032
1033 int64_m = 'll'
1034 char_align = cc.alignment('char')
1035 short_align = cc.alignment('short')
1036 int_align = cc.alignment('int')
1037 voidp_align = cc.alignment('void*')
1038 long_align = cc.alignment('long')
1039 long_long_align = cc.alignment('long long')
1040 # NOTE: We don't check for size of __int64 because long long is guaranteed to
1041 # be 64-bit in C99, and it is available on all supported compilers
1042 sizet_align = cc.alignment('size_t')
1043
1044 glib_conf.set('ALIGNOF_UNSIGNED_LONG', long_align)
1045
1046 glib_conf.set('SIZEOF_CHAR', char_size)
1047 glib_conf.set('SIZEOF_INT', int_size)
1048 glib_conf.set('SIZEOF_SHORT', short_size)
1049 glib_conf.set('SIZEOF_LONG', long_size)
1050 glib_conf.set('SIZEOF_LONG_LONG', long_long_size)
1051 glib_conf.set('SIZEOF_SIZE_T', sizet_size)
1052 glib_conf.set('SIZEOF_SSIZE_T', ssizet_size)
1053 glib_conf.set('SIZEOF_VOID_P', voidp_size)
1054
1055 if short_size == 2
1056   gint16 = 'short'
1057   gint16_modifier='h'
1058   gint16_format='hi'
1059   guint16_format='hu'
1060 elif int_size == 2
1061   gint16 = 'int'
1062   gint16_modifier=''
1063   gint16_format='i'
1064   guint16_format='u'
1065 else
1066   error('Compiler provides no native 16-bit integer type')
1067 endif
1068 glibconfig_conf.set('gint16', gint16)
1069 glibconfig_conf.set_quoted('gint16_modifier', gint16_modifier)
1070 glibconfig_conf.set_quoted('gint16_format', gint16_format)
1071 glibconfig_conf.set_quoted('guint16_format', guint16_format)
1072
1073 if short_size == 4
1074   gint32 = 'short'
1075   gint32_modifier='h'
1076   gint32_format='hi'
1077   guint32_format='hu'
1078   guint32_align = short_align
1079 elif int_size == 4
1080   gint32 = 'int'
1081   gint32_modifier=''
1082   gint32_format='i'
1083   guint32_format='u'
1084   guint32_align = int_align
1085 elif long_size == 4
1086   gint32 = 'long'
1087   gint32_modifier='l'
1088   gint32_format='li'
1089   guint32_format='lu'
1090   guint32_align = long_align
1091 else
1092   error('Compiler provides no native 32-bit integer type')
1093 endif
1094 glibconfig_conf.set('gint32', gint32)
1095 glibconfig_conf.set_quoted('gint32_modifier', gint32_modifier)
1096 glibconfig_conf.set_quoted('gint32_format', gint32_format)
1097 glibconfig_conf.set_quoted('guint32_format', guint32_format)
1098 glib_conf.set('ALIGNOF_GUINT32', guint32_align)
1099
1100 if int_size == 8
1101   gint64 = 'int'
1102   gint64_modifier=''
1103   gint64_format='i'
1104   guint64_format='u'
1105   glib_extension=''
1106   gint64_constant='(val)'
1107   guint64_constant='(val)'
1108   guint64_align = int_align
1109 elif long_size == 8
1110   gint64 = 'long'
1111   glib_extension=''
1112   gint64_modifier='l'
1113   gint64_format='li'
1114   guint64_format='lu'
1115   gint64_constant='(val##L)'
1116   guint64_constant='(val##UL)'
1117   guint64_align = long_align
1118 elif long_long_size == 8
1119   gint64 = 'long long'
1120   glib_extension='G_GNUC_EXTENSION '
1121   gint64_modifier=int64_m
1122   gint64_format=int64_m + 'i'
1123   guint64_format=int64_m + 'u'
1124   gint64_constant='(G_GNUC_EXTENSION (val##LL))'
1125   guint64_constant='(G_GNUC_EXTENSION (val##ULL))'
1126   guint64_align = long_long_align
1127 else
1128   error('Compiler provides no native 64-bit integer type')
1129 endif
1130 glibconfig_conf.set('glib_extension', glib_extension)
1131 glibconfig_conf.set('gint64', gint64)
1132 glibconfig_conf.set_quoted('gint64_modifier', gint64_modifier)
1133 glibconfig_conf.set_quoted('gint64_format', gint64_format)
1134 glibconfig_conf.set_quoted('guint64_format', guint64_format)
1135 glibconfig_conf.set('gint64_constant', gint64_constant)
1136 glibconfig_conf.set('guint64_constant', guint64_constant)
1137 glib_conf.set('ALIGNOF_GUINT64', guint64_align)
1138
1139 if host_system == 'windows'
1140   glibconfig_conf.set('g_pid_type', 'void*')
1141   glibconfig_conf.set_quoted('g_pid_format', 'p')
1142   if host_machine.cpu_family() == 'x86_64'
1143     glibconfig_conf.set_quoted('g_pollfd_format', '%#' + int64_m + 'x')
1144   else
1145     glibconfig_conf.set_quoted('g_pollfd_format', '%#x')
1146   endif
1147   glibconfig_conf.set('g_dir_separator', '\\\\')
1148   glibconfig_conf.set('g_searchpath_separator', ';')
1149 else
1150   glibconfig_conf.set('g_pid_type', 'int')
1151   glibconfig_conf.set_quoted('g_pid_format', 'i')
1152   glibconfig_conf.set_quoted('g_pollfd_format', '%d')
1153   glibconfig_conf.set('g_dir_separator', '/')
1154   glibconfig_conf.set('g_searchpath_separator', ':')
1155 endif
1156
1157 if sizet_size == short_size
1158   glibconfig_conf.set('glib_size_type_define', 'short')
1159   glibconfig_conf.set_quoted('gsize_modifier', 'h')
1160   glibconfig_conf.set_quoted('gssize_modifier', 'h')
1161   glibconfig_conf.set_quoted('gsize_format', 'hu')
1162   glibconfig_conf.set_quoted('gssize_format', 'hi')
1163   glibconfig_conf.set('glib_msize_type', 'SHRT')
1164 elif sizet_size == int_size
1165   glibconfig_conf.set('glib_size_type_define', 'int')
1166   glibconfig_conf.set_quoted('gsize_modifier', '')
1167   glibconfig_conf.set_quoted('gssize_modifier', '')
1168   glibconfig_conf.set_quoted('gsize_format', 'u')
1169   glibconfig_conf.set_quoted('gssize_format', 'i')
1170   glibconfig_conf.set('glib_msize_type', 'INT')
1171 elif sizet_size == long_size
1172   glibconfig_conf.set('glib_size_type_define', 'long')
1173   glibconfig_conf.set_quoted('gsize_modifier', 'l')
1174   glibconfig_conf.set_quoted('gssize_modifier', 'l')
1175   glibconfig_conf.set_quoted('gsize_format', 'lu')
1176   glibconfig_conf.set_quoted('gssize_format', 'li')
1177   glibconfig_conf.set('glib_msize_type', 'LONG')
1178 elif sizet_size == long_long_size
1179   glibconfig_conf.set('glib_size_type_define', 'long long')
1180   glibconfig_conf.set_quoted('gsize_modifier', int64_m)
1181   glibconfig_conf.set_quoted('gssize_modifier', int64_m)
1182   glibconfig_conf.set_quoted('gsize_format', int64_m + 'u')
1183   glibconfig_conf.set_quoted('gssize_format', int64_m + 'i')
1184   glibconfig_conf.set('glib_msize_type', 'INT64')
1185 else
1186   error('Could not determine size of size_t.')
1187 endif
1188
1189 if voidp_size == int_size
1190   glibconfig_conf.set('glib_intptr_type_define', 'int')
1191   glibconfig_conf.set_quoted('gintptr_modifier', '')
1192   glibconfig_conf.set_quoted('gintptr_format', 'i')
1193   glibconfig_conf.set_quoted('guintptr_format', 'u')
1194   glibconfig_conf.set('glib_gpi_cast', '(gint)')
1195   glibconfig_conf.set('glib_gpui_cast', '(guint)')
1196 elif voidp_size == long_size
1197   glibconfig_conf.set('glib_intptr_type_define', 'long')
1198   glibconfig_conf.set_quoted('gintptr_modifier', 'l')
1199   glibconfig_conf.set_quoted('gintptr_format', 'li')
1200   glibconfig_conf.set_quoted('guintptr_format', 'lu')
1201   glibconfig_conf.set('glib_gpi_cast', '(glong)')
1202   glibconfig_conf.set('glib_gpui_cast', '(gulong)')
1203 elif voidp_size == long_long_size
1204   glibconfig_conf.set('glib_intptr_type_define', 'long long')
1205   glibconfig_conf.set_quoted('gintptr_modifier', int64_m)
1206   glibconfig_conf.set_quoted('gintptr_format', int64_m + 'i')
1207   glibconfig_conf.set_quoted('guintptr_format', int64_m + 'u')
1208   glibconfig_conf.set('glib_gpi_cast', '(gint64)')
1209   glibconfig_conf.set('glib_gpui_cast', '(guint64)')
1210 else
1211   error('Could not determine size of void *')
1212 endif
1213
1214 if long_size != 8 and long_long_size != 8 and int_size != 8
1215   error('GLib requires a 64-bit type. You might want to consider using the GNU C compiler.')
1216 endif
1217
1218 glibconfig_conf.set('gintbits', int_size * 8)
1219 glibconfig_conf.set('glongbits', long_size * 8)
1220 glibconfig_conf.set('gsizebits', sizet_size * 8)
1221 glibconfig_conf.set('gssizebits', ssizet_size * 8)
1222
1223 # FIXME: maybe meson should tell us the libsuffix?
1224 if host_system == 'windows'
1225   g_module_suffix = 'dll'
1226 elif host_system == 'darwin'
1227   g_module_suffix = 'dylib'
1228 else
1229   g_module_suffix = 'so'
1230 endif
1231 glibconfig_conf.set('g_module_suffix', g_module_suffix)
1232
1233 glibconfig_conf.set('GLIB_MAJOR_VERSION', major_version)
1234 glibconfig_conf.set('GLIB_MINOR_VERSION', minor_version)
1235 glibconfig_conf.set('GLIB_MICRO_VERSION', micro_version)
1236 glibconfig_conf.set('GLIB_VERSION', glib_version)
1237
1238 glibconfig_conf.set('glib_void_p', voidp_size)
1239 glibconfig_conf.set('glib_long', long_size)
1240 glibconfig_conf.set('glib_size_t', sizet_size)
1241 glibconfig_conf.set('glib_ssize_t', ssizet_size)
1242 if host_machine.endian() == 'big'
1243   glibconfig_conf.set('g_byte_order', 'G_BIG_ENDIAN')
1244   glibconfig_conf.set('g_bs_native', 'BE')
1245   glibconfig_conf.set('g_bs_alien', 'LE')
1246 else
1247   glibconfig_conf.set('g_byte_order', 'G_LITTLE_ENDIAN')
1248   glibconfig_conf.set('g_bs_native', 'LE')
1249   glibconfig_conf.set('g_bs_alien', 'BE')
1250 endif
1251
1252 # === va_copy checks ===
1253 # we currently check for all three va_copy possibilities, so we get
1254 # all results in config.log for bug reports.
1255
1256 va_copy_func = ''
1257 foreach try_func : [ '__va_copy', 'va_copy' ]
1258   if cc.compiles('''#include <stdarg.h>
1259                     #include <stdlib.h>
1260                     #ifdef _MSC_VER
1261                     # include "msvc_recommended_pragmas.h"
1262                     #endif
1263                     void f (int i, ...) {
1264                     va_list args1, args2;
1265                     va_start (args1, i);
1266                     @0@ (args2, args1);
1267                     if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1268                       exit (1);
1269                     va_end (args1); va_end (args2);
1270                     }
1271                     int main() {
1272                       f (0, 42);
1273                       return 0;
1274                     }'''.format(try_func),
1275                     name : try_func + ' check')
1276     va_copy_func = try_func
1277   endif
1278 endforeach
1279 if va_copy_func != ''
1280   glib_conf.set('G_VA_COPY', va_copy_func)
1281   glib_vacopy = '#define G_VA_COPY ' + va_copy_func
1282 else
1283   glib_vacopy = '/* #undef G_VA_COPY */'
1284 endif
1285
1286 va_list_val_copy_prog = '''
1287   #include <stdarg.h>
1288   #include <stdlib.h>
1289   void f (int i, ...) {
1290     va_list args1, args2;
1291     va_start (args1, i);
1292     args2 = args1;
1293     if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1294       exit (1);
1295     va_end (args1); va_end (args2);
1296   }
1297   int main() {
1298     f (0, 42);
1299     return 0;
1300   }'''
1301
1302 if cc_can_run
1303   rres = cc.run(va_list_val_copy_prog, name : 'va_lists can be copied as values')
1304   glib_va_val_copy = rres.returncode() == 0
1305 else
1306   glib_va_val_copy = meson.get_cross_property('va_val_copy', true)
1307 endif
1308 if not glib_va_val_copy
1309   glib_vacopy = glib_vacopy + '\n#define G_VA_COPY_AS_ARRAY 1'
1310   glib_conf.set('G_VA_COPY_AS_ARRAY', 1)
1311 endif
1312 glibconfig_conf.set('glib_vacopy', glib_vacopy)
1313
1314 # check for flavours of varargs macros
1315 g_have_iso_c_varargs = cc.compiles('''
1316   void some_func (void) {
1317     int a(int p1, int p2, int p3);
1318     #define call_a(...) a(1,__VA_ARGS__)
1319     call_a(2,3);
1320   }''', name : 'ISO C99 varargs macros in C')
1321
1322 if g_have_iso_c_varargs
1323   glibconfig_conf.set('g_have_iso_c_varargs', '''
1324 #ifndef __cplusplus
1325 # define G_HAVE_ISO_VARARGS 1
1326 #endif''')
1327 endif
1328
1329 g_have_iso_cxx_varargs = cxx.compiles('''
1330   void some_func (void) {
1331     int a(int p1, int p2, int p3);
1332     #define call_a(...) a(1,__VA_ARGS__)
1333     call_a(2,3);
1334   }''', name : 'ISO C99 varargs macros in C++')
1335
1336 if g_have_iso_cxx_varargs
1337   glibconfig_conf.set('g_have_iso_cxx_varargs', '''
1338 #ifdef __cplusplus
1339 # define G_HAVE_ISO_VARARGS 1
1340 #endif''')
1341 endif
1342
1343 g_have_gnuc_varargs = cc.compiles('''
1344   void some_func (void) {
1345     int a(int p1, int p2, int p3);
1346     #define call_a(params...) a(1,params)
1347     call_a(2,3);
1348   }''', name : 'GNUC varargs macros')
1349
1350 if cc.has_header('alloca.h')
1351   glibconfig_conf.set('GLIB_HAVE_ALLOCA_H', true)
1352 endif
1353 has_syspoll = cc.has_header('sys/poll.h')
1354 has_systypes = cc.has_header('sys/types.h')
1355 if has_syspoll
1356   glibconfig_conf.set('GLIB_HAVE_SYS_POLL_H', true)
1357 endif
1358 has_winsock2 = cc.has_header('winsock2.h')
1359
1360 if has_syspoll and has_systypes
1361   poll_includes = '''
1362       #include<sys/poll.h>
1363       #include<sys/types.h>'''
1364 elif has_winsock2
1365   poll_includes = '''
1366       #define _WIN32_WINNT 0x0600
1367       #include <winsock2.h>'''
1368 else
1369   # FIXME?
1370   error('FIX POLL* defines')
1371 endif
1372
1373 poll_defines = [
1374   [ 'POLLIN', 'g_pollin', 1 ],
1375   [ 'POLLOUT', 'g_pollout', 4 ],
1376   [ 'POLLPRI', 'g_pollpri', 2 ],
1377   [ 'POLLERR', 'g_pollerr', 8 ],
1378   [ 'POLLHUP', 'g_pollhup', 16 ],
1379   [ 'POLLNVAL', 'g_pollnval', 32 ],
1380 ]
1381
1382 if has_syspoll and has_systypes
1383   foreach d : poll_defines
1384     val = cc.compute_int(d[0], prefix: poll_includes)
1385     glibconfig_conf.set(d[1], val)
1386   endforeach
1387 elif has_winsock2
1388   # Due to a missed bug in configure.ac the poll test
1389   # never succeeded on Windows and used some pre-defined
1390   # values as a fallback. Keep using them to maintain
1391   # ABI compatibility with autotools builds of glibs
1392   # and with *any* glib-using code compiled against them,
1393   # since these values end up in a public header glibconfig.h.
1394   foreach d : poll_defines
1395     glibconfig_conf.set(d[1], d[2])
1396   endforeach
1397 endif
1398
1399 # Internet address families
1400 # FIXME: what about Cygwin (G_WITH_CYGWIN)
1401 if host_system == 'windows'
1402   inet_includes = '''
1403       #include <winsock2.h>'''
1404 else
1405   inet_includes = '''
1406       #include <sys/types.h>
1407       #include <sys/socket.h>'''
1408 endif
1409
1410 inet_defines = [
1411   [ 'AF_UNIX', 'g_af_unix' ],
1412   [ 'AF_INET', 'g_af_inet' ],
1413   [ 'AF_INET6', 'g_af_inet6' ],
1414   [ 'MSG_OOB', 'g_msg_oob' ],
1415   [ 'MSG_PEEK', 'g_msg_peek' ],
1416   [ 'MSG_DONTROUTE', 'g_msg_dontroute' ],
1417 ]
1418 foreach d : inet_defines
1419   val = cc.compute_int(d[0], prefix: inet_includes)
1420   glibconfig_conf.set(d[1], val)
1421 endforeach
1422
1423 glibconfig_conf.set('GLIB_USING_SYSTEM_PRINTF', true) # FIXME!
1424
1425 # We need a more robust approach here...
1426 host_cpu_family = host_machine.cpu_family()
1427 if host_cpu_family == 'x86' or host_cpu_family == 'x86_64' or host_cpu_family == 's390' or host_cpu_family == 's390x' or host_cpu_family.startswith('arm') or host_cpu_family.startswith('crisv32') or host_cpu_family.startswith('etrax')
1428   glib_memory_barrier_needed = false
1429 elif host_cpu_family.startswith('sparc') or host_cpu_family.startswith('alpha') or host_cpu_family.startswith('powerpc') or host_cpu_family == 'ia64'
1430   glib_memory_barrier_needed = true
1431 else
1432   warning('Unknown host cpu: ' + host_cpu_family)
1433   glib_memory_barrier_needed = true
1434 endif
1435 glibconfig_conf.set('G_ATOMIC_OP_MEMORY_BARRIER_NEEDED', glib_memory_barrier_needed)
1436
1437 # We need to decide at configure time if GLib will use real atomic
1438 # operations ("lock free") or emulated ones with a mutex.  This is
1439 # because we must put this information in glibconfig.h so we know if
1440 # it is safe or not to inline using compiler intrinsics directly from
1441 # the header.
1442 #
1443 # We also publish the information via G_ATOMIC_LOCK_FREE in case the
1444 # user is interested in knowing if they can use the atomic ops across
1445 # processes.
1446 #
1447 # We can currently support the atomic ops natively when building GLib
1448 # with recent versions of GCC or MSVC.
1449 #
1450 # Note that the atomic ops are only available with GCC on x86 when
1451 # using -march=i486 or higher.  If we detect that the atomic ops are
1452 # not available but would be available given the right flags, we want
1453 # to abort and advise the user to fix their CFLAGS.  It's better to do
1454 # that then to silently fall back on emulated atomic ops just because
1455 # the user had the wrong build environment.
1456 atomictest = '''int main() {
1457   volatile int atomic = 2;
1458   __sync_bool_compare_and_swap (&atomic, 2, 3);
1459   return 0;
1460 }
1461 '''
1462
1463 atomicdefine = '''
1464 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1465 #error "compiler has atomic ops, but doesn't define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4"
1466 #endif
1467 '''
1468
1469 # We know that we can always use real ("lock free") atomic operations with MSVC
1470 if cc.get_id() == 'msvc' or cc.links(atomictest, name : 'atomic ops')
1471   have_atomic_lock_free = true
1472   if host_system == 'android' and not cc.compiles(atomicdefine, name : 'atomic ops define')
1473     # When building for armv5 on Android, gcc 4.9 provides
1474     # __sync_bool_compare_and_swap but doesn't define
1475     # __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1476     glib_conf.set('__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4', true)
1477   endif
1478 else
1479   have_atomic_lock_free = false
1480   if host_machine.cpu_family() == 'x86' and cc.links(atomictest, args : '-march=i486')
1481     error('GLib must be built with -march=i486 or later.')
1482   endif
1483 endif
1484 glibconfig_conf.set('G_ATOMIC_LOCK_FREE', have_atomic_lock_free)
1485
1486 # === Threads ===
1487
1488 # Determination of thread implementation
1489 if host_system == 'windows' and not get_option('force_posix_threads')
1490   thread_dep = []
1491   threads_implementation = 'win32'
1492   glibconfig_conf.set('g_threads_impl_def', 'WIN32')
1493   glib_conf.set('THREADS_WIN32', 1)
1494 else
1495   # FIXME: probably needs more tweaking in meson for things like -D_REENTRANT etc.
1496   thread_dep = dependency('threads')
1497   threads_implementation = 'posix'
1498   pthread_prefix = '''
1499       #ifndef _GNU_SOURCE
1500       # define _GNU_SOURCE
1501       #endif
1502       #include <pthread.h>'''
1503   glibconfig_conf.set('g_threads_impl_def', 'POSIX')
1504   glib_conf.set('THREADS_POSIX', 1)
1505   if cc.has_header_symbol('pthread.h', 'pthread_attr_setstacksize')
1506     glib_conf.set('HAVE_PTHREAD_ATTR_SETSTACKSIZE', 1)
1507   endif
1508   if cc.has_header_symbol('pthread.h', 'pthread_condattr_setclock')
1509     glib_conf.set('HAVE_PTHREAD_CONDATTR_SETCLOCK', 1)
1510   endif
1511   if cc.has_header_symbol('pthread.h', 'pthread_cond_timedwait_relative_np')
1512     glib_conf.set('HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP', 1)
1513   endif
1514   if cc.has_header_symbol('pthread.h', 'pthread_getname_np', prefix : pthread_prefix)
1515     glib_conf.set('HAVE_PTHREAD_GETNAME_NP', 1)
1516   endif
1517   # Assume that pthread_setname_np is available in some form; same as configure
1518   if cc.links(pthread_prefix + '''
1519               int main() {
1520                 pthread_setname_np("example");
1521                 return 0;
1522               }''',
1523               name : 'pthread_setname_np(const char*)',
1524               dependencies : thread_dep)
1525     # macOS and iOS
1526     glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID', 1)
1527   elif cc.links(pthread_prefix + '''
1528                 int main() {
1529                   pthread_setname_np(pthread_self(), "example");
1530                   return 0;
1531                 }''',
1532                 name : 'pthread_setname_np(pthread_t, const char*)',
1533                 dependencies : thread_dep)
1534     # Linux, Solaris, etc.
1535     glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID', 1)
1536   endif
1537 endif
1538
1539 # FIXME: we should make it print the result and always return 0, so that
1540 # the output in meson shows up as green
1541 stack_grows_check_prog = '''
1542   volatile int *a = 0, *b = 0;
1543   void f (int i) {
1544     volatile int x = 5;
1545     if (i == 0)
1546       b = &x;
1547     else
1548       f (i - 1);
1549   }
1550   int main () {
1551     volatile int y = 7;
1552     a = &y;
1553     f (100);
1554     return b > a ? 0 : 1;
1555   }'''
1556
1557 if cc_can_run
1558   rres = cc.run(stack_grows_check_prog, name : 'stack grows check')
1559   growing_stack = rres.returncode() == 0
1560 else
1561   growing_stack = meson.get_cross_property('growing_stack', false)
1562 endif
1563
1564 glibconfig_conf.set('G_HAVE_GROWING_STACK', growing_stack)
1565
1566 # Tests for iconv
1567 #
1568 # USE_LIBICONV_GNU: Using GNU libiconv
1569 # USE_LIBICONV_NATIVE: Using a native impl of iconv in a separate library
1570 #
1571 # We should never use the MinGW C library's iconv. On Windows we use the
1572 # GNU implementation that ships with MinGW.
1573
1574 # On Windows, just always use the built-in implementation
1575 if host_system == 'windows'
1576   libiconv = []
1577   glib_conf.set('USE_LIBICONV_NATIVE', true)
1578 else
1579   found_iconv = false
1580   iconv_opt = get_option('iconv')
1581   if iconv_opt == 'libc'
1582     if cc.has_function('iconv_open')
1583       libiconv = []
1584       found_iconv = true
1585     endif
1586   elif iconv_opt == 'gnu'
1587     if cc.has_header_symbol('iconv.h', 'libiconv_open')
1588       glib_conf.set('USE_LIBICONV_GNU', true)
1589       libiconv = [cc.find_library('iconv')]
1590       found_iconv = true
1591     endif
1592   elif iconv_opt == 'native'
1593     if cc.has_header_symbol('iconv.h', 'iconv_open')
1594       glib_conf.set('USE_LIBICONV_NATIVE', true)
1595       libiconv = [cc.find_library('iconv')]
1596       found_iconv = true
1597     endif
1598   endif
1599
1600   if not found_iconv
1601     error('iconv implementation "@0@" not found'.format(iconv_opt))
1602   endif
1603
1604 endif
1605
1606 if get_option('internal_pcre')
1607   pcre = []
1608   use_system_pcre = false
1609 else
1610   pcre = dependency('libpcre', required : false) # Should check for Unicode support, too. FIXME
1611   if not pcre.found()
1612     if cc.get_id() == 'msvc'
1613     # MSVC: Search for the PCRE library by the configuration, which corresponds
1614     # to the output of CMake builds of PCRE.  Note that debugoptimized
1615     # is really a Release build with .PDB files.
1616       if buildtype == 'debug'
1617         pcre = cc.find_library('pcred', required : false)
1618       else
1619         pcre = cc.find_library('pcre', required : false)
1620       endif
1621     endif
1622   endif
1623   use_system_pcre = pcre.found()
1624 endif
1625 glib_conf.set('USE_SYSTEM_PCRE', use_system_pcre)
1626
1627 use_pcre_static_flag = false
1628
1629 if host_system == 'windows'
1630   if not use_system_pcre
1631     use_pcre_static_flag = true
1632   else
1633     pcre_static = cc.links('''#define PCRE_STATIC
1634                               #include <pcre.h>
1635                               int main() {
1636                                 void *p = NULL;
1637                                 pcre_free(p);
1638                                 return 0;
1639                               }''',
1640                            dependencies: pcre,
1641                            name : 'Windows system PCRE is a static build')
1642     if pcre_static
1643       use_pcre_static_flag = true
1644     endif
1645   endif
1646 endif
1647
1648 libm = cc.find_library('m', required : false)
1649 libffi_dep = dependency('libffi', version : '>= 3.0.0', fallback : ['libffi', 'ffi_dep'])
1650 zlib_libname = '-lz'
1651 if cc.get_id() != 'msvc'
1652   libz_dep = dependency('zlib', fallback : ['zlib', 'zlib_dep'])
1653 else
1654   # MSVC: Don't use the bundled ZLib sources until we are sure that we can't
1655   # find the ZLib .lib
1656   libz_dep = dependency('zlib', required : false)
1657
1658   # MSVC: Search for the ZLib .lib, which corresponds to the results of
1659   # of using ZLib's win32/makefile.msc.
1660   if not libz_dep.found()
1661     libz_dep = cc.find_library('zlib1', required : false)
1662     if libz_dep.found()
1663       zlib_libname = '-lzlib1'
1664     else
1665       libz_dep = cc.find_library('zlib', required : false)
1666       if libz_dep.found()
1667         zlib_libname = '-lzlib'
1668       else
1669         libz_dep = subproject('zlib').get_variable('zlib_dep')
1670       endif
1671     endif
1672   endif
1673 endif
1674
1675 # Only used on non-glibc targets
1676 libintl = cc.find_library('intl', required : false)
1677 if host_system == 'windows' and not libintl.found()
1678   # Used only when the gettext library is not available (MSVC, not MinGW)
1679   libintl = subproject('proxy-libintl').get_variable('intl_dep')
1680   glib_conf.set('HAVE_DCGETTEXT', 1)
1681 else
1682   glib_conf.set('HAVE_DCGETTEXT', cc.has_header_symbol('libintl.h', 'dcgettext'))
1683 endif
1684 # We require gettext to always be present
1685 glib_conf.set('HAVE_GETTEXT', 1)
1686 glib_conf.set_quoted('GLIB_LOCALE_DIR', join_paths(glib_datadir, 'locale'))
1687 # xgettext is optional (on Windows for instance)
1688 xgettext = find_program('xgettext', required : false)
1689
1690 # libmount is only used by gio, but we need to fetch the libs to generate the
1691 # pkg-config file below
1692 libmount_dep = []
1693 if host_system == 'linux' and get_option('libmount')
1694   libmount_dep = [dependency('mount', version : '>=2.23', required : true)]
1695   glib_conf.set('HAVE_LIBMOUNT', 1)
1696 endif
1697
1698 if host_system == 'windows'
1699   winsock2 = cc.find_library('ws2_32')
1700 endif
1701
1702 selinux_dep = []
1703 if host_system == 'linux' and get_option('selinux')
1704   selinux_dep = [dependency('libselinux')]
1705   glib_conf.set('HAVE_SELINUX', 1)
1706 endif
1707
1708 xattr_dep = []
1709 if host_system != 'windows' and get_option('xattr')
1710   # either glibc or libattr can provide xattr support
1711   # for both of them, we check for getxattr being in
1712   # the library and a valid xattr header.
1713
1714   # try glibc
1715   if cc.has_function('getxattr') and cc.has_header('sys/xattr.h')
1716     glib_conf.set('HAVE_SYS_XATTR_H', 1)
1717     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_SYS_XATTR_H')
1718   #failure. try libattr
1719   elif cc.has_header_symbol('attr/xattr.h', 'getxattr')
1720     glib_conf.set('HAVE_ATTR_XATTR_H', 1)
1721     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_ATTR_XATTR_H')
1722     xattr_dep = [cc.find_library('xattr')]
1723   else
1724     error('No getxattr implementation found in C library or libxattr')
1725   endif
1726
1727   glib_conf.set('HAVE_XATTR', 1)
1728   if cc.compiles(glib_conf_prefix + '''
1729                  #include <stdio.h>
1730                  #ifdef HAVE_SYS_TYPES_H
1731                  #include <sys/types.h>
1732                  #endif
1733                  #ifdef HAVE_SYS_XATTR_H
1734                  #include <sys/xattr.h>
1735                  #elif HAVE_ATTR_XATTR_H
1736                  #include <attr/xattr.h>
1737                  #endif
1738
1739                  int main (void) {
1740                    ssize_t len = getxattr("", "", NULL, 0, 0, XATTR_NOFOLLOW);
1741                    return len;
1742                  }''',
1743                  name : 'XATTR_NOFOLLOW')
1744     glib_conf.set('HAVE_XATTR_NOFOLLOW', 1)
1745   endif
1746 endif
1747
1748 python = import('python3').find_python()
1749
1750 # Determine which user environment-dependent files that we want to install
1751 have_bash = find_program('bash', required : false).found() # For completion scripts
1752 have_m4 = find_program('m4', required : false).found() # For m4 macros
1753 have_sh = find_program('sh', required : false).found() # For glib-gettextize
1754
1755 # FIXME: defines in config.h that are not actually used anywhere
1756 # (we add them for now to minimise the diff)
1757 glib_conf.set('HAVE_DLFCN_H', 1)
1758 glib_conf.set('__EXTENSIONS__', 1)
1759 glib_conf.set('STDC_HEADERS', 1)
1760 # THREADS_NONE
1761 glib_conf.set('SIZEOF___INT64', 8)
1762
1763 glib_conf.set('GIO_MODULE_DIR', glib_giomodulesdir)
1764
1765 # Sadly Meson does not expose this value:
1766 # https://github.com/mesonbuild/meson/pull/3460
1767 if host_system == 'windows'
1768   # Autotools explicitly removed --Wl,--export-all-symbols from windows builds,
1769   # with no explanation. Do the same here for now but this could be revisited if
1770   # if causes issues.
1771   export_dynamic_ldflags = []
1772 elif host_system == 'cygwin'
1773   export_dynamic_ldflags = ['-Wl,--export-all-symbols']
1774 elif host_system == 'darwin'
1775   export_dynamic_ldflags = []
1776 else
1777   export_dynamic_ldflags = ['-Wl,--export-dynamic']
1778 endif
1779
1780 win32_cflags = []
1781 win32_ldflags = []
1782 if host_system == 'windows' and cc.get_id() != 'msvc'
1783   # Ensure MSVC-compatible struct packing convention is used when
1784   # compiling for Win32 with gcc. It is used for the whole project and exposed
1785   # in glib-2.0.pc.
1786   win32_cflags = ['-mms-bitfields']
1787   add_project_arguments(win32_cflags, language : 'c')
1788
1789   # Win32 API libs, used only by libglib and exposed in glib-2.0.pc
1790   win32_ldflags = ['-lws2_32', '-lole32', '-lwinmm', '-lshlwapi']
1791 elif host_system == 'cygwin'
1792   win32_ldflags = ['-luser32', '-lkernel32']
1793 endif
1794
1795 # Tracing: dtrace
1796 want_dtrace = get_option('dtrace')
1797 enable_dtrace = false
1798
1799 # Since dtrace support is opt-in we just error out if it was requested but
1800 # is not available. We don't bother with autodetection yet.
1801 if want_dtrace
1802   if glib_have_carbon
1803     error('GLib dtrace support not yet compatible with macOS dtrace')
1804   endif
1805   dtrace = find_program('dtrace', required : true) # error out if not found
1806   if not cc.has_header('sys/sdt.h')
1807     error('dtrace support needs sys/sdt.h header')
1808   endif
1809   # FIXME: autotools build also passes -fPIC -DPIC but is it needed in this case?
1810   dtrace_obj_gen = generator(dtrace,
1811     output : '@BASENAME@.o',
1812     arguments : ['-G', '-s', '@INPUT@', '-o', '@OUTPUT@'])
1813   # FIXME: $(SED) -e "s,define STAP_HAS_SEMAPHORES 1,undef STAP_HAS_SEMAPHORES,"
1814   #               -e "s,define _SDT_HAS_SEMAPHORES 1,undef _SDT_HAS_SEMAPHORES,"
1815   dtrace_hdr_gen = generator(dtrace,
1816     output : '@BASENAME@.h',
1817     arguments : ['-h', '-s', '@INPUT@', '-o', '@OUTPUT@'])
1818   glib_conf.set('HAVE_DTRACE', 1)
1819   enable_dtrace = true
1820 endif
1821
1822 # systemtap
1823 want_systemtap = get_option('systemtap')
1824 enable_systemtap = false
1825
1826 if want_systemtap and enable_dtrace
1827   tapset_install_dir = get_option('tapset_install_dir')
1828   if tapset_install_dir == ''
1829     tapset_install_dir = join_paths(get_option('datadir'), 'systemtap/tapset', host_machine.cpu_family())
1830   endif
1831   stp_cdata = configuration_data()
1832   stp_cdata.set('ABS_GLIB_RUNTIME_LIBDIR', glib_libdir)
1833   stp_cdata.set('LT_CURRENT', minor_version * 100)
1834   stp_cdata.set('LT_REVISION', micro_version)
1835   enable_systemtap = true
1836 endif
1837
1838
1839 pkg = import('pkgconfig')
1840 windows = import('windows')
1841 subdir('glib')
1842 subdir('gobject')
1843 subdir('gthread')
1844 subdir('gmodule')
1845 subdir('gio')
1846 if xgettext.found()
1847   subdir('po')
1848 endif
1849 subdir('tests')
1850
1851 # NOTE: We skip glib-zip.in because the filenames it assumes don't match ours
1852
1853 # Install glib-gettextize executable, if a UNIX-style shell is found
1854 if have_sh
1855   configure_file(input : 'glib-gettextize.in',
1856     install : true,
1857     install_dir : 'bin',
1858     output : 'glib-gettextize',
1859     configuration : glib_conf)
1860 endif
1861
1862 if have_m4
1863   # Install m4 macros that other projects use
1864   install_data('m4macros/glib-2.0.m4', 'm4macros/glib-gettext.m4', 'm4macros/gsettings.m4',
1865     install_dir : join_paths(get_option('datadir'), 'aclocal'))
1866 endif
1867
1868 if host_system != 'windows'
1869   # Install Valgrind suppression file (except on Windows,
1870   # as Valgrind is currently not supported on Windows)
1871   install_data('glib.supp',
1872     install_dir : join_paths(get_option('datadir'), 'glib-2.0', 'valgrind'))
1873 endif
1874
1875 configure_file(input : 'config.h.meson',
1876   output : 'config.h',
1877   configuration : glib_conf)
1878
1879 if host_system == 'windows'
1880   install_headers([ 'msvc_recommended_pragmas.h' ], subdir : 'glib-2.0')
1881 endif
1882
1883 if get_option('man')
1884   xsltproc = find_program('xsltproc', required : true)
1885   xsltproc_command = [
1886     xsltproc,
1887     '--nonet',
1888     '--stringparam', 'man.output.quietly', '1',
1889     '--stringparam', 'funcsynopsis.style', 'ansi',
1890     '--stringparam', 'man.th.extra1.suppress', '1',
1891     '--stringparam', 'man.authors.section.enabled', '0',
1892     '--stringparam', 'man.copyright.section.enabled', '0',
1893     '-o', '@OUTPUT@',
1894     'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl',
1895     '@INPUT@',
1896   ]
1897   man1_dir = get_option('mandir') + '/man1'
1898 endif
1899
1900 gnome = import('gnome')
1901 subdir('docs/reference/glib')
1902 subdir('docs/reference/gobject')
1903 subdir('docs/reference/gio')