~eda-qa/leaflang/cleanup_factorial

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
# -*- coding: utf-8 -*-
import os
import subprocess

setupConfFile = 'setup.conf'
vars = Variables(setupConfFile)
vars.AddVariables(
	PathVariable('BOOST_PREFIX','Where boost was installed', '/usr/' ),
	PathVariable('BUILD_DIR','Intermediate build directory', 'build', PathVariable.PathIsDirCreate),
	PathVariable('LLVM_DIR','Where LLVM is installed', '/opt/llvm/install' ),
	PathVariable('GMP_DIR','Where GMP is installed', '/opt/gmp/install' ),
	EnumVariable('BUILD_TYPE','Optimization/debug build type',
		allowed_values=('release','debug'), default='release' )
	)

baseEnv = Environment(
	variables = vars,
	BUILD_LIB='$BUILD_DIR/lib',
	LIBPATH=['$BUILD_DIR/lib','$BOOST_PREFIX/lib'],
	CPPPATH=['#include','$BOOST_PREFIX/include'],
	tools=['default','textfile']
	)
	
# setup compiler flags
if baseEnv['BUILD_TYPE'] == 'release':
	baseEnv.Append(CPPFLAGS = ['-O3', '-g', '-ggdb3'])
else:
	baseEnv.Append(CPPFLAGS = ['-g3', '-ggdb3'])
# expose basic flags in case building foreign code
baseEnv['BASE_CPPFLAGS'] = baseEnv['CPPFLAGS']
# our own code has stricter requirements
baseEnv.Append(CPPFLAGS = ['-Wall', '-Wconversion','-Wextra'])

# Enable C++11 mode
baseEnv.Append(CPPFLAGS = ['-std=c++0x'] ) # -std=c++11

# Prevent unknowns to avoid surprises
unknown = vars.UnknownVariables()
if unknown:
	print "Unknown variables:", unknown.keys()
	Exit(1)

Help(vars.GenerateHelpText(baseEnv))

# setup libraries
conf = Configure(baseEnv)
for lib in ['boost_unit_test_framework','boost_program_options','rt']:
	if not conf.CheckLib(lib):
		Exit(1)

baseEnv = conf.Finish()

# It doesn't save variables which match the default!!!
#SCONS: http://scons.tigris.org/issues/show_bug.cgi?id=2827
vars.Save(setupConfFile,baseEnv)

# used to call unit test programs
def call_unit_test(target, source, env):
    app = str(source[0].abspath)
    test_env = { 'LD_LIBRARY_PATH': ':'.join( env.subst( env['LIBPATH'] ) ) }
    if subprocess.call([app], env=test_env) == 0:
        open(str(target[0]),'w').write("PASSED\n")
    else:
        return 1

# Adds the target as something that should be executed during a 'check' build
# The target is placed in the '.check' directory to prevent it from being built
# by default. All targets are then aliased to 'check' so a 'scons check' will do
# the check build.
def add_unit_test( env, node, alias = 'check' ):
	# TODO: support non-nodes ( see leaf/SConscript expr_tests)
	test_target = '#/.check/' + node[0].path
	test_node = env.Command( test_target, node, call_unit_test )
	env.Alias( alias, test_node )
	env.AlwaysBuild( test_node )
	
baseEnv.AddMethod( add_unit_test, 'AddUnitTest' )
baseEnv.Clean([], '#/.check/' )

# Call the ohter build files
Export('baseEnv')

baseEnv.VariantDir(baseEnv['BUILD_DIR'],'src',duplicate=0)
baseEnv.SConscript('$BUILD_DIR/SConscript')

# Only things in build directory get built, this excludes the .test directory
Default(baseEnv['BUILD_DIR'])