2013-07-11 23:44:28 +02:00
|
|
|
# -*- python -*-
|
|
|
|
|
import os
|
2013-10-28 09:35:44 -04:00
|
|
|
import os.path
|
2013-10-29 17:35:37 -04:00
|
|
|
import sys
|
|
|
|
|
|
2013-06-24 21:26:07 +02:00
|
|
|
|
2013-10-29 17:35:37 -04:00
|
|
|
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))
|
2013-12-09 13:22:43 +01:00
|
|
|
vars.Add(ListVariable('bindings', 'Language bindings to build', 'none', ['dotnet', 'perl', 'php', 'python']))
|
2013-10-29 17:35:37 -04:00
|
|
|
|
2013-12-09 13:22:43 +01:00
|
|
|
env = Environment(ENV = {'PATH' : os.environ['PATH']},
|
|
|
|
|
variables = vars,
|
|
|
|
|
tools=['default', 'scanreplace', 'csharp/mono'],
|
|
|
|
|
toolpath=['tools'])
|
2013-10-29 17:35:37 -04:00
|
|
|
|
2013-11-26 15:29:28 -08:00
|
|
|
if not 'bindings' in env:
|
|
|
|
|
env['bindings'] = []
|
|
|
|
|
|
2013-10-29 17:35:37 -04:00
|
|
|
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")
|
2013-11-21 12:02:18 -08:00
|
|
|
env['parsersincpath'] = calcInstallPath("$prefix", "include", "hammer", "parsers")
|
|
|
|
|
env['backendsincpath'] = calcInstallPath("$prefix", "include", "hammer", "backends")
|
2013-11-20 13:04:07 -08:00
|
|
|
env['pkgconfigpath'] = calcInstallPath("$prefix", "lib", "pkgconfig")
|
|
|
|
|
env.ScanReplace('libhammer.pc.in')
|
2013-10-29 17:35:37 -04:00
|
|
|
|
2013-11-08 16:30:08 -08:00
|
|
|
env.MergeFlags("-std=gnu99 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-attributes")
|
2013-10-18 12:14:18 +02:00
|
|
|
|
2013-11-23 12:28:34 -06:00
|
|
|
if env['PLATFORM'] == 'darwin':
|
2013-12-03 13:28:56 -08:00
|
|
|
env.Append(SHLINKFLAGS = '-install_name ' + env["libpath"] + '/${TARGET.file}')
|
2013-11-23 12:28:34 -06:00
|
|
|
else:
|
2013-10-18 12:14:18 +02:00
|
|
|
env.MergeFlags("-lrt")
|
2013-06-24 21:26:07 +02:00
|
|
|
|
|
|
|
|
AddOption("--variant",
|
|
|
|
|
dest="variant",
|
|
|
|
|
nargs=1, type="choice",
|
|
|
|
|
choices=["debug", "opt"],
|
2013-07-10 21:32:05 +02:00
|
|
|
default="opt",
|
2013-06-24 21:26:07 +02:00
|
|
|
action="store",
|
|
|
|
|
help="Build variant (debug or opt)")
|
|
|
|
|
|
2013-09-13 01:14:40 -07:00
|
|
|
AddOption("--coverage",
|
|
|
|
|
dest="coverage",
|
|
|
|
|
default=False,
|
|
|
|
|
action="store_true",
|
|
|
|
|
help="Build with coverage instrumentation")
|
|
|
|
|
|
2013-11-22 19:44:30 -06:00
|
|
|
AddOption("--in-place",
|
|
|
|
|
dest="in_place",
|
|
|
|
|
default=False,
|
|
|
|
|
action="store_true",
|
|
|
|
|
help="Build in-place, rather than in the build/<variant> tree")
|
|
|
|
|
|
2013-06-24 21:26:07 +02:00
|
|
|
|
|
|
|
|
dbg = env.Clone(VARIANT='debug')
|
|
|
|
|
dbg.Append(CCFLAGS=['-g'])
|
|
|
|
|
|
|
|
|
|
opt = env.Clone(VARIANT='opt')
|
2013-12-18 14:25:52 +01:00
|
|
|
opt.Append(CCFLAGS=["-O3"])
|
2013-06-24 21:26:07 +02:00
|
|
|
|
|
|
|
|
if GetOption("variant") == 'debug':
|
|
|
|
|
env = dbg
|
|
|
|
|
else:
|
|
|
|
|
env = opt
|
2013-07-11 23:44:28 +02:00
|
|
|
|
2013-09-13 01:14:40 -07:00
|
|
|
if GetOption("coverage"):
|
|
|
|
|
env.Append(CFLAGS=["-fprofile-arcs", "-ftest-coverage"],
|
|
|
|
|
CXXFLAGS=["-fprofile-arcs", "-ftest-coverage"],
|
|
|
|
|
LDFLAGS=["-fprofile-arcs", "-ftest-coverage"],
|
|
|
|
|
LIBS=['gcov'])
|
|
|
|
|
|
2013-11-19 20:46:34 -06:00
|
|
|
env["CC"] = os.getenv("CC") or env["CC"]
|
|
|
|
|
env["CXX"] = os.getenv("CXX") or env["CXX"]
|
|
|
|
|
|
2013-10-18 12:14:18 +02:00
|
|
|
if os.getenv("CC") == "clang" or env['PLATFORM'] == 'darwin':
|
2013-07-11 23:44:28 +02:00
|
|
|
env.Replace(CC="clang",
|
|
|
|
|
CXX="clang++")
|
2013-09-12 10:39:50 -07:00
|
|
|
|
2013-11-19 20:46:34 -06:00
|
|
|
env["ENV"].update(x for x in os.environ.items() if x[0].startswith("CCC_"))
|
|
|
|
|
|
2013-09-12 10:39:50 -07:00
|
|
|
#rootpath = env['ROOTPATH'] = os.path.abspath('.')
|
|
|
|
|
#env.Append(CPPPATH=os.path.join('#', "hammer"))
|
|
|
|
|
|
2013-11-26 15:29:28 -08:00
|
|
|
testruns = []
|
2013-11-23 16:07:19 -06:00
|
|
|
|
2013-11-26 19:54:09 -08:00
|
|
|
targets = ["$libpath",
|
|
|
|
|
"$incpath",
|
|
|
|
|
"$parsersincpath",
|
|
|
|
|
"$backendsincpath",
|
|
|
|
|
"$pkgconfigpath"]
|
2013-11-26 15:29:28 -08:00
|
|
|
|
2013-06-24 21:26:07 +02:00
|
|
|
Export('env')
|
2013-11-26 15:29:28 -08:00
|
|
|
Export('testruns')
|
2013-11-26 19:54:09 -08:00
|
|
|
Export('targets')
|
2013-06-24 21:26:07 +02:00
|
|
|
|
2013-11-22 19:44:30 -06:00
|
|
|
if not GetOption("in_place"):
|
|
|
|
|
env['BUILD_BASE'] = 'build/$VARIANT'
|
2013-11-26 15:29:28 -08:00
|
|
|
lib = env.SConscript(["src/SConscript"], variant_dir='$BUILD_BASE/src')
|
|
|
|
|
env.Alias("examples", env.SConscript(["examples/SConscript"], variant_dir='$BUILD_BASE/examples'))
|
2013-11-22 19:44:30 -06:00
|
|
|
else:
|
|
|
|
|
env['BUILD_BASE'] = '.'
|
2013-11-26 15:29:28 -08:00
|
|
|
lib = env.SConscript(["src/SConscript"])
|
|
|
|
|
env.Alias(env.SConscript(["examples/SConscript"]))
|
|
|
|
|
|
2013-12-05 08:41:28 +01:00
|
|
|
for testrun in testruns:
|
|
|
|
|
env.Alias("test", testrun)
|
2013-10-29 17:35:37 -04:00
|
|
|
|
2013-11-26 19:54:09 -08:00
|
|
|
env.Alias("install", targets)
|