-
Notifications
You must be signed in to change notification settings - Fork 72
/
SConstruct
138 lines (108 loc) · 4.25 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
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
# -*- python -*-
import os
import os.path
import platform
import sys
vars = Variables(None, ARGUMENTS)
vars.Add(PathVariable('DESTDIR', "Root directory to install in (useful for packaging scripts)", None, PathVariable.PathIsDirCreate))
vars.Add(PathVariable('prefix', "Where to install in the FHS", "/usr/local", PathVariable.PathAccept))
vars.Add(ListVariable('bindings', 'Language bindings to build', 'none', ['cpp', 'dotnet', 'perl', 'php', 'python', 'ruby']))
tools = ['default', 'scanreplace']
if 'dotnet' in ARGUMENTS.get('bindings', []):
tools.append('csharp/mono')
envvars = {'PATH' : os.environ['PATH']}
if 'PKG_CONFIG_PATH' in os.environ:
envvars['PKG_CONFIG_PATH'] = os.environ['PKG_CONFIG_PATH']
env = Environment(ENV = envvars,
variables = vars,
tools=tools,
toolpath=['tools'])
if not 'bindings' in env:
env['bindings'] = []
def calcInstallPath(*elements):
path = os.path.abspath(os.path.join(*map(env.subst, elements)))
if 'DESTDIR' in env:
path = os.path.join(env['DESTDIR'], os.path.relpath(path, start="/"))
return path
rel_prefix = not os.path.isabs(env['prefix'])
env['prefix'] = os.path.abspath(env['prefix'])
if 'DESTDIR' in env:
env['DESTDIR'] = os.path.abspath(env['DESTDIR'])
if rel_prefix:
print >>sys.stderr, "--!!-- You used a relative prefix with a DESTDIR. This is probably not what you"
print >>sys.stderr, "--!!-- you want; files will be installed in"
print >>sys.stderr, "--!!-- %s" % (calcInstallPath("$prefix"),)
env['libpath'] = calcInstallPath("$prefix", "lib")
env['incpath'] = calcInstallPath("$prefix", "include", "hammer")
env['parsersincpath'] = calcInstallPath("$prefix", "include", "hammer", "parsers")
env['backendsincpath'] = calcInstallPath("$prefix", "include", "hammer", "backends")
env['pkgconfigpath'] = calcInstallPath("$prefix", "lib", "pkgconfig")
env.ScanReplace('libhammer.pc.in')
env.MergeFlags("-std=gnu11 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-attributes -Wno-unused-variable")
if env['PLATFORM'] == 'darwin':
env.Append(SHLINKFLAGS = '-install_name ' + env["libpath"] + '/${TARGET.file}')
elif os.uname()[0] == "OpenBSD":
pass
else:
env.MergeFlags("-lrt")
AddOption("--variant",
dest="variant",
nargs=1, type="choice",
choices=["debug", "opt"],
default="opt",
action="store",
help="Build variant (debug or opt)")
AddOption("--coverage",
dest="coverage",
default=False,
action="store_true",
help="Build with coverage instrumentation")
AddOption("--in-place",
dest="in_place",
default=False,
action="store_true",
help="Build in-place, rather than in the build/<variant> tree")
dbg = env.Clone(VARIANT='debug')
dbg.Append(CCFLAGS=['-g'])
opt = env.Clone(VARIANT='opt')
opt.Append(CCFLAGS=["-O3"])
if GetOption("variant") == 'debug':
env = dbg
else:
env = opt
env["CC"] = os.getenv("CC") or env["CC"]
env["CXX"] = os.getenv("CXX") or env["CXX"]
if GetOption("coverage"):
env.Append(CFLAGS=["--coverage"],
CXXFLAGS=["--coverage"],
LDFLAGS=["--coverage"])
if env["CC"] == "gcc":
env.Append(LIBS=['gcov'])
else:
env.ParseConfig('llvm-config --ldflags')
if os.getenv("CC") == "clang" or env['PLATFORM'] == 'darwin':
env.Replace(CC="clang",
CXX="clang++")
env["ENV"].update(x for x in os.environ.items() if x[0].startswith("CCC_"))
#rootpath = env['ROOTPATH'] = os.path.abspath('.')
#env.Append(CPPPATH=os.path.join('#', "hammer"))
testruns = []
targets = ["$libpath",
"$incpath",
"$parsersincpath",
"$backendsincpath",
"$pkgconfigpath"]
Export('env')
Export('testruns')
Export('targets')
if not GetOption("in_place"):
env['BUILD_BASE'] = 'build/$VARIANT'
lib = env.SConscript(["src/SConscript"], variant_dir='$BUILD_BASE/src')
env.Alias("examples", env.SConscript(["examples/SConscript"], variant_dir='$BUILD_BASE/examples'))
else:
env['BUILD_BASE'] = '.'
lib = env.SConscript(["src/SConscript"])
env.Alias(env.SConscript(["examples/SConscript"]))
for testrun in testruns:
env.Alias("test", testrun)
env.Alias("install", targets)