-
Notifications
You must be signed in to change notification settings - Fork 37
/
SConstruct
90 lines (74 loc) · 2.33 KB
/
SConstruct
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
from __future__ import print_function
import os
from conftest import custom_tests
def quote(s, q='"'):
return q + s + q
# Set up base environment
base_env = Environment(
CCFLAGS = [
'-std=gnu99',
'-Wall', '-Werror',
'-Wmissing-prototypes', '-Wstrict-prototypes',
],
LINKFLAGS = [ # gcc is linker
'-Wl,--fatal-warnings',
],
BUILD_ROOT = '#scons_build',
BUILD_DIR = '$BUILD_ROOT/$MODE',
LIBDIR = '$BUILD_DIR/lib',
LIBPATH = '$LIBDIR',
STATICX_VERSION = ARGUMENTS.get('STATICX_VERSION', '<unknown>'),
CPPDEFINES = dict(
STATICX_VERSION = quote(quote('$STATICX_VERSION', '"'), "'"),
),
)
def get_anywhere(what, default=None):
return ARGUMENTS.get(what) or os.environ.get(what) or default
def tool_debug(env):
env['MODE'] = 'debug'
env.AppendUnique(
CPPDEFINES = {'DEBUG': 1},
CCFLAGS = ['-g'],
)
def tool_release(env):
env['MODE'] = 'release'
env.AppendUnique(
CPPDEFINES = {'NDEBUG': 1},
CCFLAGS = ['-Os'],
)
def ModeEnvs(env):
for t in (tool_debug, tool_release):
menv = env.Clone(tools=[t])
yield menv
base_env.AddMethod(ModeEnvs)
def BuildSubdir(env, dirname):
return env.SConscript(
dirs = dirname,
variant_dir = '$BUILD_DIR/' + dirname,
duplicate = False,
exports = dict(env=env.Clone()),
)
base_env.AddMethod(BuildSubdir)
###########
# Configure
conf = base_env.Configure(custom_tests=custom_tests)
# Does our default libc have NSS?
conf.env["HAS_NSS"] = conf.CheckNSS()
base_env = conf.Finish()
################################################################################
# Bootloader
bootloader_env = base_env.Clone()
cc = get_anywhere('BOOTLOADER_CC')
if cc:
bootloader_env['CC'] = cc
for env in bootloader_env.ModeEnvs():
env.Install('$LIBDIR', env.BuildSubdir('libtar'))
env.Install('$LIBDIR', env.BuildSubdir('libxz'))
env.InstallAs('#staticx/assets/$MODE/bootloader', env.BuildSubdir('bootloader'))
################################################################################
# nssfix
if env['HAS_NSS']:
for env in base_env.ModeEnvs():
env.InstallAs('#staticx/assets/$MODE/libnssfix.so', env.BuildSubdir('libnssfix'))
else:
print("WARNING: NSS not available; staticx will not include nssfix for GLIBC programs!")