2014-01-30 14:08:11 -08:00
|
|
|
# SConstruct
|
|
|
|
# vim: set ft=python:
|
|
|
|
#
|
2014-01-30 15:42:25 -08:00
|
|
|
# Toplevel Scons build script. This should be mostly complete and generic enough
|
|
|
|
# for most builds.
|
2014-01-30 14:08:11 -08:00
|
|
|
#
|
|
|
|
# Eryn Wells <eryn@erynwells.me>
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# DEFAULT CONFIGURATION VALUES
|
|
|
|
#
|
|
|
|
|
2014-01-30 20:43:09 -08:00
|
|
|
# Settings for the default toolchain binaries. Setting these overrides the
|
|
|
|
# defaults, provided your the given binary exists.
|
2014-01-30 20:36:38 -08:00
|
|
|
CC = None
|
|
|
|
CXX = None
|
|
|
|
AS = None
|
2014-01-30 20:43:09 -08:00
|
|
|
LINK = None
|
2014-01-30 20:36:38 -08:00
|
|
|
|
|
|
|
# Same as above but for default CFLAGS. These are appended to both CFLAGS and
|
|
|
|
# CXXFLAGS.
|
|
|
|
CFLAGS = '-Wall -Wextra -pedantic'
|
|
|
|
|
2014-01-30 14:08:11 -08:00
|
|
|
|
|
|
|
#
|
|
|
|
# BUILD STUFF BELOW HERE
|
|
|
|
#
|
|
|
|
|
2014-01-30 15:09:28 -08:00
|
|
|
import os
|
2014-01-30 14:08:11 -08:00
|
|
|
import os.path
|
2014-01-30 21:01:20 -08:00
|
|
|
import SCons.Errors
|
2014-01-30 14:08:11 -08:00
|
|
|
|
2014-01-30 15:09:28 -08:00
|
|
|
|
2014-03-05 23:18:46 -08:00
|
|
|
if not GetOption('build_cmds'):
|
|
|
|
def comstr(action):
|
|
|
|
return '{:>18}: $TARGET'.format(action)
|
|
|
|
default_env = DefaultEnvironment()
|
|
|
|
default_env['ARCOMSTR'] = comstr('Archiving')
|
|
|
|
default_env['ASCOMSTR'] = comstr('Assembling')
|
|
|
|
default_env['ASPPCOMSTR'] = comstr('Assembling')
|
|
|
|
default_env['CCCOMSTR'] = comstr('Building (C)')
|
|
|
|
default_env['CXXCOMSTR'] = comstr('Building (C++)')
|
|
|
|
default_env['LINKCOMSTR'] = comstr('Linking')
|
|
|
|
default_env['RANLIBCOMSTR'] = comstr('Indexing')
|
|
|
|
default_env['SHCCCOMSTR'] = comstr('Building (C)')
|
|
|
|
default_env['SHCXXCOMSTR'] = comstr('Building (C++)')
|
|
|
|
default_env['SHLINKCOMSTR'] = comstr('Linking (Shared)')
|
2014-01-30 14:08:11 -08:00
|
|
|
|
2014-02-28 17:39:41 -08:00
|
|
|
build_dir = Dir('#build')
|
|
|
|
lib_dir = Dir('#lib')
|
2014-01-30 15:09:28 -08:00
|
|
|
src_dir = Dir('#src')
|
2014-02-28 17:39:41 -08:00
|
|
|
test_dir = Dir('#test')
|
2014-01-30 15:09:28 -08:00
|
|
|
|
2014-01-31 08:42:41 -08:00
|
|
|
|
2014-02-28 17:39:41 -08:00
|
|
|
def create_env(name, src_dirs, appends=None):
|
|
|
|
output_dir = build_dir.Dir(name)
|
2014-03-05 23:18:46 -08:00
|
|
|
env = DefaultEnvironment().Clone()
|
2014-02-28 17:39:41 -08:00
|
|
|
env['__name'] = name
|
|
|
|
env['__build_dir'] = output_dir
|
|
|
|
env['__src_dirs'] = []
|
|
|
|
env['__output_dirs'] = []
|
|
|
|
for d in src_dirs:
|
|
|
|
out_dir = output_dir.Dir(d.path)
|
|
|
|
env['__src_dirs'].append(d)
|
|
|
|
env['__output_dirs'].append(out_dir)
|
|
|
|
env.VariantDir(out_dir, d.path, duplicate=0)
|
|
|
|
env.Clean('.', out_dir)
|
|
|
|
if appends:
|
|
|
|
for k, v in appends.iteritems():
|
|
|
|
if k.startswith('='):
|
|
|
|
env[k[1:]] = v
|
|
|
|
else:
|
|
|
|
env.Append(**{k: v})
|
2014-01-31 08:42:41 -08:00
|
|
|
return env
|
|
|
|
|
|
|
|
|
2014-01-30 14:08:11 -08:00
|
|
|
debug_cflags = ' -O0 -g'
|
2014-02-28 17:39:41 -08:00
|
|
|
debug_env = create_env('debug', [src_dir], {
|
2014-01-31 08:42:41 -08:00
|
|
|
'CPPDEFINES': ['DEBUG'],
|
|
|
|
'CFLAGS': debug_cflags,
|
|
|
|
'CXXFLAGS': debug_cflags,
|
|
|
|
})
|
2014-01-30 14:08:11 -08:00
|
|
|
|
2014-01-30 15:42:25 -08:00
|
|
|
release_cflags = ' -O2'
|
2014-02-28 17:39:41 -08:00
|
|
|
release_env = create_env('release', [src_dir], {
|
2014-01-31 08:42:41 -08:00
|
|
|
'CPPDEFINES': ['RELEASE'],
|
|
|
|
'CFLAGS': release_cflags,
|
|
|
|
'CXXFLAGS': release_cflags,
|
|
|
|
})
|
2014-01-30 14:08:11 -08:00
|
|
|
|
2014-02-28 17:40:49 -08:00
|
|
|
test_gtest_dir = Dir('#lib/gtest')
|
2014-03-01 10:29:27 -08:00
|
|
|
test_gtest_include = test_gtest_dir.Dir('include')
|
2014-02-28 17:40:49 -08:00
|
|
|
test_env = create_env('test', [src_dir, test_dir, test_gtest_dir], {
|
|
|
|
'CPPDEFINES': ['DEBUG'],
|
2014-03-01 10:29:27 -08:00
|
|
|
'CPPPATH': [test_gtest_include],
|
2014-02-28 17:40:49 -08:00
|
|
|
'LIBPATH': [test_gtest_dir],
|
|
|
|
'CFLAGS': debug_cflags,
|
|
|
|
'CXXFLAGS': debug_cflags,
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2014-01-31 08:27:37 -08:00
|
|
|
modes = {
|
|
|
|
'debug': debug_env,
|
|
|
|
'release': release_env,
|
2014-02-28 17:40:49 -08:00
|
|
|
'test': test_env,
|
2014-01-31 08:27:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
mode = ARGUMENTS.get('MODE', None)
|
2014-02-28 17:39:41 -08:00
|
|
|
build_modes = []
|
2014-01-31 08:27:37 -08:00
|
|
|
if mode:
|
|
|
|
# If MODE=foo is specified, build only that mode.
|
2014-02-28 17:39:41 -08:00
|
|
|
build_modes.append(mode)
|
|
|
|
else:
|
|
|
|
build_modes = modes.keys()
|
|
|
|
|
|
|
|
for mode in build_modes:
|
2014-01-31 08:27:37 -08:00
|
|
|
try:
|
|
|
|
env = modes[mode]
|
|
|
|
except KeyError:
|
2014-02-28 17:39:41 -08:00
|
|
|
print 'Skipping invalid mode: {}'.format(mode)
|
|
|
|
for d in env['__output_dirs']:
|
|
|
|
env.SConscript(d.File('SConscript'), {'env': env})
|