forked from WithSecureOpenSource/fsdyn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSConstruct
More file actions
109 lines (96 loc) · 3.41 KB
/
SConstruct
File metadata and controls
109 lines (96 loc) · 3.41 KB
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
import os
DIRECTORIES = [
'src',
'test',
'components/avltree' ]
def target_architectures():
archs = os.getenv('FSARCHS', None)
if archs:
return archs.split(',')
arch_map = {
('Darwin', 'arm64'): ['darwin'],
('Darwin', 'x86_64'): ['darwin'],
('FreeBSD', 'amd64'): ['freebsd_amd64'],
('Linux', 'i686'): ['linux32'],
('Linux', 'x86_64'): ['linux64'],
('OpenBSD', 'amd64'): ['openbsd_amd64'],
}
uname_os, _, _, _, uname_cpu = os.uname()
assert (uname_os, uname_cpu) in arch_map
return arch_map[(uname_os, uname_cpu)]
TARGET_DEFINES = {
'freebsd_amd64': [],
'linux32': ['_FILE_OFFSET_BITS=64'],
'linux64': [],
'openbsd_amd64': [],
'darwin': []
}
TARGET_FLAGS = {
'freebsd_amd64': '',
'linux32': '-m32 ',
'linux64': '',
'openbsd_amd64': '',
'darwin': '-mmacosx-version-min=10.13 '
}
def libconfig_builder(env):
env.Install('.', '#fscomp-libconfig.json')
def libconfig_parser():
return '$ARCHBUILDDIR/components/avltree/.fscomp/libconfig'
def pkgconfig_builder(env):
pkgconfig = env.Substfile(
'lib/pkgconfig/fsdyn.pc',
'#fsdyn.pc.in',
SUBST_DICT={'@prefix@': env['PREFIX']},
)
env.Alias(
'install',
env.Install(os.path.join(env['PREFIX'], 'lib/pkgconfig'), pkgconfig),
)
def pkgconfig_parser(prefix):
return ''
def construct():
ccflags = (
' -g -O2 -Wall -Werror '
'-Wno-parentheses '
) + os.getenv('FSCCFLAGS', '')
linkflags = os.getenv('FSLINKFLAGS', '')
ar_override = os.getenv('FSAR', os.getenv('FSBTAR', None))
cc_override = os.getenv('FSCC', os.getenv('FSBTCC', None))
ranlib_override = os.getenv('FSRANLIB', os.getenv('FSBTRANLIB', None))
prefix = ARGUMENTS.get('prefix', '/usr/local')
if ARGUMENTS.get('fscomp', 0):
config_builder = libconfig_builder
config_parser = libconfig_parser()
else:
config_builder = pkgconfig_builder
config_parser = pkgconfig_parser(prefix)
for target_arch in target_architectures():
target_ccflags = TARGET_FLAGS[target_arch] + ccflags
target_cppdefines = TARGET_DEFINES[target_arch]
target_linkflags = TARGET_FLAGS[target_arch] + linkflags
build_dir = os.path.join('stage',
target_arch,
ARGUMENTS.get('builddir', 'build'))
for directory in DIRECTORIES:
env = Environment(ARCH=target_arch,
CCFLAGS=target_ccflags,
CPPDEFINES=target_cppdefines,
LINKFLAGS=target_linkflags,
CONFIG_BUILDER=config_builder,
CONFIG_PARSER=config_parser,
PREFIX=prefix,
tools=['default', 'textfile'])
env['ARCHBUILDDIR'] = env.Dir('#stage/$ARCH/build').abspath
if ar_override:
env['AR'] = ar_override
if cc_override:
env['CC'] = cc_override
if ranlib_override:
env['RANLIB'] = ranlib_override
SConscript(dirs=directory,
exports=['env'],
duplicate=False,
variant_dir=os.path.join(build_dir, directory))
Clean('.', build_dir)
if __name__ == 'SCons.Script':
construct()