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