-
Notifications
You must be signed in to change notification settings - Fork 0
/
wscript
190 lines (153 loc) · 6.27 KB
/
wscript
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
178
179
180
181
182
183
184
185
186
187
188
189
190
# encoding: utf-8
#
# WAF build scripts for XMMS2
# Copyright (C) 2006-2009 XMMS2 Team
#
import sys
if sys.version_info < (2,4):
raise RuntimeError("Python 2.4 or newer is required")
import os
from waflib import Options, Utils, Logs
BASEVERSION = "0.01"
APPNAME = 's4'
top = '.'
out = '_build_'
lib_dir = 'src/lib'
test_dir = 'tests'
tool_dirs = ['src/tools/bench', 'src/tools/s4']
####
## Initialization
####
def init(ctx):
import gc
gc.disable()
####
## Build
####
def build(bld):
subdirs = bld.env.S4_SUBDIRS
newest = max([os.stat(os.path.join(sd, "wscript")).st_mtime for sd in subdirs])
if bld.env.NEWEST_WSCRIPT_SUBDIR and newest > bld.env.NEWEST_WSCRIPT_SUBDIR:
bld.fatal("You need to run waf configure")
raise SystemExit(1)
bld.add_subdirs(subdirs)
bld.add_post_fun(shutdown)
####
## Configuration
####
def configure(conf):
prefix = os.environ.get('PKG_CONFIG_PREFIX', None)
if prefix:
if not os.path.isabs(prefix):
prefix = os.path.abspath(prefix)
cond.env.PKG_CONFIG_DEFINES = dict(prefix=prefix)
conf.env.S4_SUBDIRS = [lib_dir, test_dir]
if conf.options.build_tools:
conf.env.append_value("S4_SUBDIRS", tool_dirs)
conf.check_tool('misc gnu_dirs')
conf.check_tool('gcc')
conf.env.append_value('CFLAGS', ['-Wall', '-g'])
if conf.options.target_platform:
Options.platform = conf.options.target_platform
conf.env.VERSION = BASEVERSION
conf.env.PKGCONFIGDIR = conf.options.pkgconfigdir or \
os.path.join(conf.env.PREFIX, 'lib', 'pkgconfig')
if conf.options.enable_gcov:
conf.env.enable_gcov = True
conf.env.append_unique('CFLAGS', ['--coverage', '-pg'])
conf.env.append_unique('LINKFLAGS', ['--coverage', '-pg'])
if conf.options.config_prefix:
for d in conf.options.config_prefix:
if not os.path.isabs(d):
d = os.path.abspath(d)
conf.env.prepend_value("LIBPATH", os.path.join(d, "lib"))
conf.env.prepend_value("CPPPATH", os.path.join(d, "include"))
# Our static libraries may link to dynamic libraries
if Options.platform != 'win32':
conf.env.CFLAGS_cstlib += ['-fPIC', '-DPIC']
else:
# As we have to change target platform after the tools
# have been loaded there are a few variables that needs
# to be initiated if building for win32.
# Make sure we don't have -fPIC and/or -DPIC in our CCFLAGS
conf.env.CFLAGS_cshlib = []
# Setup various prefixes
conf.env.cshlib_PATTERN = 'lib%s.dll'
conf.env.cprogram_PATTERN = '%s.exe'
# Add some specific OSX things
if Options.platform == 'darwin':
conf.env["LINKFLAGS"] += ['-multiply_defined suppress']
conf.env["explicit_install_name"] = True
else:
conf.env["explicit_install_name"] = False
# Check for support for the generic platform
has_platform_support = os.name in ('nt', 'posix')
conf.msg('Platform code for %s' % os.name, has_platform_support)
if not has_platform_support:
conf.fatal("s4 only has platform support for Windows "
"and POSIX operating systems.")
raise SystemExit(1)
# Check sunOS socket support
if Options.platform == 'sunos':
conf.env.append_unique('CFLAGS', '-D_POSIX_PTHREAD_SEMANTICS')
conf.env.append_unique('CFLAGS', '-D_REENTRANT')
conf.env.append_unique('CFLAGS', '-std=gnu99')
# Glib is required by everyone, so check for it here and let them
# assume its presence.
conf.check_cfg(package='glib-2.0', atleast_version='2.32.0',
uselib_store='glib2', args='--cflags --libs')
conf.recurse(conf.env.S4_SUBDIRS)
newest = max([os.stat(os.path.join(sd, "wscript")).st_mtime for sd in conf.env.S4_SUBDIRS])
conf.env.NEWEST_WSCRIPT_SUBDIR = newest
return True
####
## Options
####
def _list_cb(option, opt, value, parser):
"""Callback that lets you specify lists of targets."""
vals = value.split(',')
if vals == ['']:
vals = []
if getattr(parser.values, option.dest):
vals += getattr(parser.values, option.dest)
setattr(parser.values, option.dest, vals)
def options(opt):
opt.tool_options('gnu_dirs')
opt.tool_options('gcc')
opt.add_option('--with-custom-version', type='string',
dest='customversion', help="Override git commit hash version")
opt.add_option('--conf-prefix', action="callback", callback=_list_cb,
type='string', dest='config_prefix',
help="Specify a directory to prepend to configuration prefix")
opt.add_option('--with-pkgconfigdir', type='string', dest='pkgconfigdir',
help="Specify directory where to install pkg-config files")
opt.add_option('--with-target-platform', type='string',
dest='target_platform',
help="Force a target platform (cross-compilation)")
opt.add_option('--with-windows-version', type='string', dest='winver',
help="Force a specific Windows version (cross-compilation)")
opt.add_option('--build-tests', action='store_true', default=False,
dest='build_tests', help="Build test suite")
opt.add_option('--enable-gcov', action='store_true', default=False,
dest='enable_gcov', help="Enable code coverage analysis")
opt.add_option("--build-tools", action="store_true", default=False,
dest="build_tools",
help="Build S4 tools to verify and recover databases.")
opt.add_option('--without-ldconfig', action='store_false', default=True,
dest='ldconfig', help="Don't run ldconfig after install")
opt.sub_options(tool_dirs)
opt.sub_options(test_dir)
def shutdown(ctx):
if ctx.cmd != 'install':
return
# explicitly avoid running ldconfig on --without-ldconfig
if ctx.options.ldconfig is False:
return
# implicitly run ldconfig when running as root if not told otherwise
if ctx.options.ldconfig is None and os.geteuid() != 0:
return
if not os.path.isfile('/sbin/ldconfig'):
return
libprefix = Utils.subst_vars('${LIBDIR}', ctx.env)
Logs.info("- ldconfig '%s'" % libprefix)
ctx.exec_command('/sbin/ldconfig %s' % libprefix)