summaryrefslogtreecommitdiffstats
path: root/lib/util/wscript_configure
blob: fbaeb095dd4daafe330059bb62d5907760e0c814 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/env python
from waflib import Logs, Options, Errors

import os, sys

if Options.options.disable_fault_handling:
    conf.DEFINE('HAVE_DISABLE_FAULT_HANDLING',1)

# backtrace could be in libexecinfo or in libc.
# This is our preferred backtrace handler (more useful output than libunwind as at Ubuntu 20.04 x86_64)
conf.CHECK_FUNCS_IN('backtrace backtrace_symbols', 'execinfo', checklibc=True, headers='execinfo.h')
conf.CHECK_HEADERS('execinfo.h')

conf.SET_TARGET_TYPE('LIBUNWIND', 'EMPTY')
if Options.options.with_libunwind:
    if conf.check_cfg(package='libunwind-generic',
                      args='--cflags --libs',
                      msg='Checking for libunwind',
                      uselib_store='LIBUNWIND',
                      mandatory=False):
        if conf.CHECK_HEADERS('libunwind.h'):
            conf.SET_TARGET_TYPE('LIBUNWIND', 'SYSLIB')
    else:
        raise Errors.WafError('--with-libunwind specified but libunwind not found')
elif Options.options.with_libunwind == None:
    if not conf.CONFIG_SET('HAVE_BACKTRACE_SYMBOLS') \
       and not Options.options.disable_fault_handling:
        raise Errors.WafError(
'''backtrace_symbols() not found but
--with-libunwind not specified.
Use --without-libunwind to build without internal backtrace support or
--disable-fault-handling to totally defer fault handling to the OS.''')

conf.CHECK_STRUCTURE_MEMBER('struct statvfs', 'f_frsize', define='HAVE_FRSIZE', headers='sys/statvfs.h')

# all the different ways of doing statfs
statfs_types = [
    ( 'STAT_STATVFS',
      'statvfs (SVR4)',
      'struct statvfs fsd; exit(statvfs(0, &fsd))',
      'sys/statvfs.h' ),

    ( 'STAT_STATFS3_OSF1',
      '3-argument statfs function (DEC OSF/1)',
      'struct statfs fsd; fsd.f_fsize = 0; exit(statfs(".", &fsd, sizeof(struct statfs)))',
      'sys/param.h sys/mount.h' ),

    ( 'STAT_STATFS2_BSIZE',
      'two-argument statfs with statfs.bsize',
      'struct statfs fsd; fsd.f_bsize = 0; exit(statfs(".", &fsd))',
      'sys/param.h sys/mount.h  sys/vfs.h' ),

    ( 'STAT_STATFS4',
      'four-argument statfs  (AIX-3.2.5, SVR3)',
      'struct statfs fsd; exit(statfs(".", &fsd, sizeof fsd, 0))',
      'sys/statfs.h' ),

    ( 'STAT_STATFS2_FSIZE',
      'two-argument statfs with statfs.fsize',
      'struct statfs fsd; fsd.f_fsize = 0; exit(statfs(".", &fsd))',
      'sys/param.h sys/mount.h' ),

    ( 'STAT_STATFS2_FS_DATA',
      'two-argument statfs with struct fs_data (Ultrix)',
      'struct fs_data fsd; exit(statfs(".", &fsd) != 1)',
      'sys/param.h sys/mount.h sys/fs_types.h' )
]

found_statfs=False
for (define, msg, code, headers) in statfs_types:
    if conf.CHECK_CODE(code,
                       define=define,
                       headers=headers,
                       msg='Checking for %s' % msg,
                       local_include=False):
        found_statfs=True
        break

if not found_statfs:
    print("FATAL: Failed to find a statfs method")
    raise

conf.CHECK_CODE("""struct statfs fsd;
		fsd.f_bsize = 0;
		fsd.f_iosize = 0;
		return (statfs (".", &fsd));
		""",
                headers='sys/param.h sys/mount.h sys/vfs.h',
                define='BSD_STYLE_STATVFS',
                msg='Checking for *bsd style statfs with statfs.f_iosize',
                execute=True,
                local_include=False)

conf.CHECK_CODE('struct statvfs buf; buf.f_fsid = 0',
                define='HAVE_FSID_INT',
                msg='Checking if f_fsid is an integer',
                execute=False,
                local_include=False,
                headers='sys/statvfs.h')

# fsusage.c assumes that statvfs has an f_frsize entry. Some weird
# systems use f_bsize.
conf.CHECK_CODE('struct statvfs buf; buf.f_frsize = 0',
                define='HAVE_FRSIZE',
                msg='Checking that statvfs.f_frsize works',
                headers='sys/statvfs.h',
                execute=False,
                local_include=False)

# Some systems use f_flag in struct statvfs while others use f_flags
conf.CHECK_CODE('struct statvfs buf; buf.f_flag = 0',
                define='HAVE_STATVFS_F_FLAG',
                msg='Checking whether statvfs.f_flag exists',
                headers='sys/statvfs.h',
                local_include=False,
                execute=False)

conf.CHECK_CODE('struct statvfs buf; buf.f_flags = 0',
                define='HAVE_STATVFS_F_FLAGS',
                msg='Checking whether statvfs.f_flags exists',
                headers='sys/statvfs.h',
                local_include=False,
                execute=False)

#
# systemd removed the libsystemd-daemon and libsystemd-journal libraries. In newer
# versions it is only libsystemd. As waf pkg-config handling does not provide
# targets which could be used as a dependency based on the package name we need
# to look for them on our own. This enabled one of the library targets based on
# which version we detect.
#
conf.SET_TARGET_TYPE('systemd-daemon', 'EMPTY')
conf.SET_TARGET_TYPE('systemd-journal', 'EMPTY')
conf.SET_TARGET_TYPE('systemd', 'EMPTY')

if Options.options.enable_systemd != False:
    r_daemon = conf.CHECK_CFG(package='libsystemd-daemon', args='--cflags --libs',
                   msg='Checking for libsystemd-daemon')
    r_journal = conf.CHECK_CFG(package='libsystemd-journal', args='--cflags --libs',
                   msg='Checking for libsystemd-journal')
    if r_daemon is None and r_journal is None:
        conf.CHECK_CFG(package='libsystemd', args='--cflags --libs',
                   msg='Checking for libsystemd')
        conf.CHECK_LIB('systemd', shlib=True)
    else:
        conf.CHECK_LIB('systemd-daemon', shlib=True)
        conf.CHECK_LIB('systemd-journal', shlib=True)

conf.SET_TARGET_TYPE('lttng-ust', 'EMPTY')

if Options.options.enable_lttng != False:
    conf.CHECK_CFG(package='lttng-ust', args='--cflags --libs',
                   msg='Checking for lttng-ust', uselib_store="LTTNG-UST")
    conf.CHECK_HEADERS('lttng/tracef.h', lib='lttng-st')
    conf.CHECK_LIB('lttng-ust', shlib=True)

if (conf.CONFIG_SET('HAVE_LTTNG_TRACEF_H') and
    conf.CONFIG_SET('HAVE_LTTNG_UST')):
    conf.DEFINE('HAVE_LTTNG_TRACEF', '1')
    conf.env['HAVE_LTTNG_TRACEF'] = True

if Options.options.gpfs_headers_dir:
    conf.env['CPPPATH_GPFS'] = Options.options.gpfs_headers_dir
    if conf.CHECK_HEADERS('gpfs.h', False, False, "gpfs"):
        Logs.info('Using gpfs.h from %s' % Options.options.gpfs_headers_dir)
        conf.DEFINE('HAVE_GPFS', '1')
else:
    conf.env['CPPPATH_GPFS'] = "/usr/lpp/mmfs/include/"
    if conf.CHECK_HEADERS('gpfs.h', False, False, "gpfs"):
        Logs.info('Using gpfs.h from installed gpfs package.')
        conf.DEFINE('HAVE_GPFS', '1')
    else:
        if sys.platform.startswith('linux'):
            conf.env['CPPPATH_GPFS'] = os.path.abspath("third_party/gpfs")
            if conf.CHECK_HEADERS('gpfs.h', False, False, "gpfs"):
                Logs.info('Using gpfs.h from third_party directory.')
                conf.DEFINE('HAVE_GPFS', '1')