2013-07-11 23:44:28 +02:00
|
|
|
# -*- python -*-
|
|
|
|
|
import os
|
2013-10-28 09:35:44 -04:00
|
|
|
import os.path
|
2014-03-17 03:25:28 +01:00
|
|
|
import platform
|
2013-10-29 17:35:37 -04:00
|
|
|
import sys
|
|
|
|
|
|
2016-05-22 13:33:46 +02:00
|
|
|
default_install_dir='/usr/local'
|
2016-05-22 13:29:12 +02:00
|
|
|
if platform.system() == 'Windows':
|
2016-05-22 13:33:46 +02:00
|
|
|
default_install_dir = 'build' # no obvious place for installation on Windows
|
2016-05-22 13:29:12 +02:00
|
|
|
|
2013-10-29 17:35:37 -04:00
|
|
|
vars = Variables(None, ARGUMENTS)
|
2016-05-22 13:33:46 +02:00
|
|
|
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', default_install_dir, PathVariable.PathAccept))
|
2014-01-16 11:24:15 -05:00
|
|
|
vars.Add(ListVariable('bindings', 'Language bindings to build', 'none', ['cpp', 'dotnet', 'perl', 'php', 'python', 'ruby']))
|
2013-10-29 17:35:37 -04:00
|
|
|
|
2014-04-12 21:44:10 -07:00
|
|
|
tools = ['default', 'scanreplace']
|
|
|
|
|
if 'dotnet' in ARGUMENTS.get('bindings', []):
|
|
|
|
|
tools.append('csharp/mono')
|
|
|
|
|
|
2014-11-30 19:18:09 -05:00
|
|
|
envvars = {'PATH' : os.environ['PATH']}
|
|
|
|
|
if 'PKG_CONFIG_PATH' in os.environ:
|
|
|
|
|
envvars['PKG_CONFIG_PATH'] = os.environ['PKG_CONFIG_PATH']
|
2016-05-22 13:29:12 +02:00
|
|
|
if platform.system() == 'Windows':
|
|
|
|
|
# from the scons FAQ (keywords: LNK1104 TEMPFILE), needed by link.exe
|
|
|
|
|
envvars['TMP'] = os.environ['TMP']
|
2014-11-30 19:18:09 -05:00
|
|
|
|
|
|
|
|
env = Environment(ENV = envvars,
|
2013-12-09 13:22:43 +01:00
|
|
|
variables = vars,
|
2014-04-12 21:44:10 -07:00
|
|
|
tools=tools,
|
2013-12-09 13:22:43 +01:00
|
|
|
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:
|
2016-05-22 13:33:46 +02:00
|
|
|
path = os.path.join(env['DESTDIR'], os.path.relpath(path, start='/'))
|
2013-10-29 17:35:37 -04:00
|
|
|
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:
|
2016-05-22 13:33:46 +02:00
|
|
|
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'),)
|
2013-10-29 17:35:37 -04:00
|
|
|
|
|
|
|
|
|
2016-05-22 13:33:46 +02:00
|
|
|
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')
|
2013-11-20 13:04:07 -08:00
|
|
|
env.ScanReplace('libhammer.pc.in')
|
2013-10-29 17:35:37 -04:00
|
|
|
|
2016-05-22 13:33:46 +02:00
|
|
|
AddOption('--variant',
|
|
|
|
|
dest='variant',
|
|
|
|
|
nargs=1, type='choice',
|
|
|
|
|
choices=['debug', 'opt'],
|
|
|
|
|
default='opt',
|
|
|
|
|
action='store',
|
|
|
|
|
help='Build variant (debug or opt)')
|
2013-06-24 21:26:07 +02:00
|
|
|
|
2016-05-22 13:33:46 +02:00
|
|
|
AddOption('--coverage',
|
|
|
|
|
dest='coverage',
|
2013-09-13 01:14:40 -07:00
|
|
|
default=False,
|
2016-05-22 13:33:46 +02:00
|
|
|
action='store_true',
|
|
|
|
|
help='Build with coverage instrumentation')
|
2013-09-13 01:14:40 -07:00
|
|
|
|
2016-05-22 13:33:46 +02:00
|
|
|
AddOption('--in-place',
|
|
|
|
|
dest='in_place',
|
2013-11-22 19:44:30 -06:00
|
|
|
default=False,
|
2016-05-22 13:33:46 +02:00
|
|
|
action='store_true',
|
|
|
|
|
help='Build in-place, rather than in the build/<variant> tree')
|
2013-11-22 19:44:30 -06:00
|
|
|
|
2016-05-22 13:33:46 +02:00
|
|
|
AddOption('--tests',
|
|
|
|
|
dest='with_tests',
|
2016-05-22 13:29:12 +02:00
|
|
|
default=env['PLATFORM'] != 'win32',
|
2016-05-22 13:33:46 +02:00
|
|
|
action='store_true',
|
|
|
|
|
help='Build tests')
|
2016-05-22 13:29:12 +02:00
|
|
|
|
2016-05-22 13:33:46 +02:00
|
|
|
env['CC'] = os.getenv('CC') or env['CC']
|
|
|
|
|
env['CXX'] = os.getenv('CXX') or env['CXX']
|
2013-06-24 21:26:07 +02:00
|
|
|
|
2016-05-22 13:33:46 +02:00
|
|
|
if os.getenv('CC') == 'clang' or env['PLATFORM'] == 'darwin':
|
|
|
|
|
env.Replace(CC='clang',
|
|
|
|
|
CXX='clang++')
|
2013-06-24 21:26:07 +02:00
|
|
|
|
2016-05-22 13:18:19 +02:00
|
|
|
# Language standard and warnings
|
2016-05-22 13:33:46 +02:00
|
|
|
if env['CC'] == 'cl':
|
|
|
|
|
env.MergeFlags('-W3 -WX')
|
2016-05-22 13:29:12 +02:00
|
|
|
env.Append(
|
|
|
|
|
CPPDEFINES=[
|
2016-05-22 13:33:46 +02:00
|
|
|
'_CRT_SECURE_NO_WARNINGS' # allow uses of sprintf
|
2016-05-22 13:29:12 +02:00
|
|
|
],
|
|
|
|
|
CFLAGS=[
|
2016-05-22 13:33:46 +02:00
|
|
|
'-wd4018', # 'expression' : signed/unsigned mismatch
|
|
|
|
|
'-wd4244', # 'argument' : conversion from 'type1' to 'type2', possible loss of data
|
|
|
|
|
'-wd4267', # 'var' : conversion from 'size_t' to 'type', possible loss of data
|
2016-05-22 13:29:12 +02:00
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
else:
|
2016-05-22 13:33:46 +02:00
|
|
|
env.MergeFlags('-std=gnu99 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-attributes -Wno-unused-variable')
|
2013-06-24 21:26:07 +02:00
|
|
|
|
2016-05-22 13:18:19 +02:00
|
|
|
# Linker options
|
|
|
|
|
if env['PLATFORM'] == 'darwin':
|
2016-05-22 13:33:46 +02:00
|
|
|
env.Append(SHLINKFLAGS = '-install_name ' + env['libpath'] + '/${TARGET.file}')
|
|
|
|
|
elif platform.system() == 'OpenBSD':
|
2016-05-22 13:18:19 +02:00
|
|
|
pass
|
2016-05-22 13:29:12 +02:00
|
|
|
elif env['PLATFORM'] == 'win32':
|
|
|
|
|
# no extra lib needed
|
|
|
|
|
pass
|
2013-06-24 21:26:07 +02:00
|
|
|
else:
|
2016-05-22 13:33:46 +02:00
|
|
|
env.MergeFlags('-lrt')
|
2015-10-04 02:53:54 +02:00
|
|
|
|
2016-05-22 13:33:46 +02:00
|
|
|
if GetOption('coverage'):
|
|
|
|
|
env.Append(CFLAGS=['--coverage'],
|
|
|
|
|
CXXFLAGS=['--coverage'],
|
|
|
|
|
LDFLAGS=['--coverage'])
|
|
|
|
|
if env['CC'] == 'gcc':
|
2015-10-04 02:53:54 +02:00
|
|
|
env.Append(LIBS=['gcov'])
|
|
|
|
|
else:
|
|
|
|
|
env.ParseConfig('llvm-config --ldflags')
|
2013-11-19 20:46:34 -06:00
|
|
|
|
2016-05-22 13:18:19 +02:00
|
|
|
dbg = env.Clone(VARIANT='debug')
|
2016-05-22 13:33:46 +02:00
|
|
|
if env['CC'] == 'cl':
|
|
|
|
|
dbg.Append(CCFLAGS=['/Z7'])
|
2016-05-22 13:29:12 +02:00
|
|
|
else:
|
|
|
|
|
dbg.Append(CCFLAGS=['-g'])
|
2016-05-22 13:18:19 +02:00
|
|
|
|
|
|
|
|
opt = env.Clone(VARIANT='opt')
|
2016-05-22 13:33:46 +02:00
|
|
|
if env['CC'] == 'cl':
|
|
|
|
|
opt.Append(CCFLAGS=['/O2'])
|
2016-05-22 13:29:12 +02:00
|
|
|
else:
|
2016-05-22 13:33:46 +02:00
|
|
|
opt.Append(CCFLAGS=['-O3'])
|
2016-05-22 13:18:19 +02:00
|
|
|
|
2016-05-22 13:33:46 +02:00
|
|
|
if GetOption('variant') == 'debug':
|
2016-05-22 13:18:19 +02:00
|
|
|
env = dbg
|
|
|
|
|
else:
|
|
|
|
|
env = opt
|
2013-09-12 10:39:50 -07:00
|
|
|
|
2016-05-22 13:33:46 +02:00
|
|
|
env['ENV'].update(x for x in os.environ.items() if x[0].startswith('CCC_'))
|
2013-11-19 20:46:34 -06:00
|
|
|
|
2013-09-12 10:39:50 -07:00
|
|
|
#rootpath = env['ROOTPATH'] = os.path.abspath('.')
|
2016-05-22 13:33:46 +02:00
|
|
|
#env.Append(CPPPATH=os.path.join('#', 'hammer'))
|
2013-09-12 10:39:50 -07:00
|
|
|
|
2013-11-26 15:29:28 -08:00
|
|
|
testruns = []
|
2013-11-23 16:07:19 -06:00
|
|
|
|
2016-05-22 13:33:46 +02: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
|
|
|
|
2016-05-22 13:33:46 +02:00
|
|
|
if not GetOption('in_place'):
|
2013-11-22 19:44:30 -06:00
|
|
|
env['BUILD_BASE'] = 'build/$VARIANT'
|
2016-05-22 13:33:46 +02: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'] = '.'
|
2016-05-22 13:33:46 +02:00
|
|
|
lib = env.SConscript(['src/SConscript'])
|
|
|
|
|
env.Alias(env.SConscript(['examples/SConscript']))
|
2013-11-26 15:29:28 -08:00
|
|
|
|
2013-12-05 08:41:28 +01:00
|
|
|
for testrun in testruns:
|
2016-05-22 13:33:46 +02:00
|
|
|
env.Alias('test', testrun)
|
2013-10-29 17:35:37 -04:00
|
|
|
|
2016-05-22 13:33:46 +02:00
|
|
|
env.Alias('install', targets)
|