systemd: fix detection of libsystemd
[sfrench/samba-autobuild/.git] / lib / util / wscript_configure
1 #!/usr/bin/env python
2 import Options
3
4 if Options.options.disable_fault_handling:
5     conf.DEFINE('HAVE_DISABLE_FAULT_HANDLING',1)
6
7 # backtrace could be in libexecinfo or in libc
8 conf.CHECK_FUNCS_IN('backtrace backtrace_symbols', 'execinfo', checklibc=True, headers='execinfo.h')
9
10 conf.CHECK_STRUCTURE_MEMBER('struct statvfs', 'f_frsize', define='HAVE_FRSIZE', headers='sys/statvfs.h')
11
12 # all the different ways of doing statfs
13 statfs_types = [
14     ( 'STAT_STATVFS',
15       'statvfs (SVR4)',
16       'struct statvfs fsd; exit(statvfs(0, &fsd))',
17       'sys/statvfs.h' ),
18
19     ( 'STAT_STATFS3_OSF1',
20       '3-argument statfs function (DEC OSF/1)',
21       'struct statfs fsd; fsd.f_fsize = 0; exit(statfs(".", &fsd, sizeof(struct statfs)))',
22       'sys/param.h sys/mount.h' ),
23
24     ( 'STAT_STATFS2_BSIZE',
25       'two-argument statfs with statfs.bsize',
26       'struct statfs fsd; fsd.f_bsize = 0; exit(statfs(".", &fsd))',
27       'sys/param.h sys/mount.h  sys/vfs.h' ),
28
29     ( 'STAT_STATFS4',
30       'four-argument statfs  (AIX-3.2.5, SVR3)',
31       'struct statfs fsd; exit(statfs(".", &fsd, sizeof fsd, 0))',
32       'sys/statfs.h' ),
33
34     ( 'STAT_STATFS2_FSIZE',
35       'two-argument statfs with statfs.fsize',
36       'struct statfs fsd; fsd.f_fsize = 0; exit(statfs(".", &fsd))',
37       'sys/param.h sys/mount.h' ),
38
39     ( 'STAT_STATFS2_FS_DATA',
40       'two-argument statfs with struct fs_data (Ultrix)',
41       'struct fs_data fsd; exit(statfs(".", &fsd) != 1)',
42       'sys/param.h sys/mount.h sys/fs_types.h' )
43 ]
44
45 found_statfs=False
46 for (define, msg, code, headers) in statfs_types:
47     if conf.CHECK_CODE(code,
48                        define=define,
49                        headers=headers,
50                        msg='Checking for %s' % msg,
51                        local_include=False):
52         found_statfs=True
53         break
54
55 if not found_statfs:
56     print("FATAL: Failed to find a statfs method")
57     raise
58
59 conf.CHECK_CODE("""struct statfs fsd;
60                 fsd.f_bsize = 0;
61                 fsd.f_iosize = 0;
62                 return (statfs (".", &fsd));
63                 """,
64                 headers='sys/param.h sys/mount.h sys/vfs.h',
65                 define='BSD_STYLE_STATVFS',
66                 msg='Checking for *bsd style statfs with statfs.f_iosize',
67                 execute=True,
68                 local_include=False)
69
70 conf.CHECK_CODE('struct statvfs buf; buf.f_fsid = 0',
71                 define='HAVE_FSID_INT',
72                 msg='Checking if f_fsid is an integer',
73                 execute=False,
74                 local_include=False,
75                 headers='sys/statvfs.h')
76
77 # fsusage.c assumes that statvfs has an f_frsize entry. Some weird
78 # systems use f_bsize.
79 conf.CHECK_CODE('struct statvfs buf; buf.f_frsize = 0',
80                 define='HAVE_FRSIZE',
81                 msg='Checking that statvfs.f_frsize works',
82                 headers='sys/statvfs.h',
83                 execute=False,
84                 local_include=False)
85
86 # Some systems use f_flag in struct statvfs while others use f_flags
87 conf.CHECK_CODE('struct statvfs buf; buf.f_flag = 0',
88                 define='HAVE_STATVFS_F_FLAG',
89                 msg='Checking whether statvfs.f_flag exists',
90                 headers='sys/statvfs.h',
91                 local_include=False,
92                 execute=False)
93
94 conf.CHECK_CODE('struct statvfs buf; buf.f_flags = 0',
95                 define='HAVE_STATVFS_F_FLAGS',
96                 msg='Checking whether statvfs.f_flags exists',
97                 headers='sys/statvfs.h',
98                 local_include=False,
99                 execute=False)
100
101 #
102 # systemd removed the libsystemd-daemon and libsystemd-journal libraries. In newer
103 # versions it is only libsystemd. As waf pkg-config handling does not provide
104 # targets which could be used as a dependency based on the package name we need
105 # to look for them on our own. This enabled one of the library targets based on
106 # which version we detect.
107 #
108 conf.SET_TARGET_TYPE('systemd-daemon', 'EMPTY')
109 conf.SET_TARGET_TYPE('systemd-journal', 'EMPTY')
110 conf.SET_TARGET_TYPE('systemd', 'EMPTY')
111
112 if Options.options.enable_systemd != False:
113     r_daemon = conf.CHECK_CFG(package='libsystemd-daemon', args='--cflags --libs',
114                    msg='Checking for libsystemd-daemon')
115     r_journal = conf.CHECK_CFG(package='libsystemd-journal', args='--cflags --libs',
116                    msg='Checking for libsystemd-journal')
117     if r_daemon is None and r_journal is None:
118         conf.CHECK_CFG(package='libsystemd', args='--cflags --libs',
119                    msg='Checking for libsystemd')
120         conf.CHECK_LIB('systemd', shlib=True)
121     else:
122         conf.CHECK_LIB('systemd-daemon', shlib=True)
123         conf.CHECK_LIB('systemd-journal', shlib=True)
124
125 if Options.options.enable_lttng != False:
126     conf.CHECK_CFG(package='lttng-ust', args='--cflags --libs',
127                    msg='Checking for lttng-ust', uselib_store="LTTNG-UST")
128     conf.CHECK_HEADERS('lttng/tracef.h', lib='lttng-st')
129     conf.CHECK_LIB('lttng-ust', shlib=True)
130
131 if (conf.CONFIG_SET('HAVE_LTTNG_TRACEF_H') and
132     conf.CONFIG_SET('HAVE_LTTNG_UST')):
133     conf.DEFINE('HAVE_LTTNG_TRACEF', '1')
134     conf.env['HAVE_LTTNG_TRACEF'] = True
135 else:
136     conf.SET_TARGET_TYPE('lttng-ust', 'EMPTY')
137     conf.undefine('HAVE_LTTNG_TRACEF')
138
139 conf.env['CPPPATH_GPFS'] = Options.options.gpfs_headers_dir
140 if conf.CHECK_HEADERS('gpfs.h', False, False, "gpfs"):
141     conf.DEFINE('HAVE_GPFS', '1')