From f21954eecd430ee3760366551ee2977d496335b0 Mon Sep 17 00:00:00 2001
From: "Meredith L. Patterson" <mlp@thesmartpolitenerd.com>
Date: Tue, 26 Nov 2013 15:29:28 -0800
Subject: [PATCH] everything's working for new-build except Clean()

---
 SConstruct                     | 19 ++++++++++++++-----
 src/SConscript                 | 25 ++++++++++++++-----------
 src/bindings/python/SConscript | 13 +++++++++----
 3 files changed, 37 insertions(+), 20 deletions(-)

diff --git a/SConstruct b/SConstruct
index 50c185be..e30f6df2 100644
--- a/SConstruct
+++ b/SConstruct
@@ -7,9 +7,13 @@ 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', ['python']))
 
 env = Environment(ENV = {'PATH' : os.environ['PATH']}, variables = vars, tools=['default', 'scanreplace'], 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:
@@ -90,18 +94,23 @@ 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 = []
+
 Export('env')
+Export('testruns')
 
 if not GetOption("in_place"):
     env['BUILD_BASE'] = 'build/$VARIANT'
-    env.SConscript(["src/SConscript"], variant_dir='$BUILD_BASE/src')
-    env.SConscript(["examples/SConscript"], variant_dir='$BUILD_BASE/examples')
+    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'] = '.'
-    env.SConscript(["src/SConscript"])
-    env.SConscript(["examples/SConscript"])
+    lib = env.SConscript(["src/SConscript"])
+    env.Alias(env.SConscript(["examples/SConscript"]))
+
+#env.Command('test', '$BUILD_BASE/src/test_suite', 'env LD_LIBRARY_PATH=$BUILD_BASE/src $SOURCE')
 
-env.Command('test', '$BUILD_BASE/src/test_suite', 'env LD_LIBRARY_PATH=$BUILD_BASE/src $SOURCE')
+env.Alias("test", testruns)
 
 env.Alias("install", "$libpath")
 env.Alias("install", "$incpath")
diff --git a/src/SConscript b/src/SConscript
index 0cb41af7..03883932 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -1,7 +1,6 @@
 # -*- python -*-
-Import('env')
-
-bindings = ['python']
+import os.path
+Import('env testruns')
 
 dist_headers = [
     "hammer.h",
@@ -62,15 +61,16 @@ misc_hammer_parts = [
     'registry.c',
     'system_allocator.c']
 
-tests = ['t_benchmark.c',
-         't_bitreader.c',
-         't_bitwriter.c',
-         't_parser.c',
-         't_grammar.c',
-         't_misc.c']
+ctests = ['t_benchmark.c',
+          't_bitreader.c',
+          't_bitwriter.c',
+          't_parser.c',
+          't_grammar.c',
+          't_misc.c']
 
 libhammer_shared = env.SharedLibrary('hammer', parsers + backends + misc_hammer_parts)
 libhammer_static = env.StaticLibrary('hammer', parsers + backends + misc_hammer_parts)
+Default(libhammer_shared, libhammer_static)
 
 env.Install("$libpath", [libhammer_static, libhammer_shared])
 env.Install("$incpath", dist_headers)
@@ -81,9 +81,12 @@ env.Install("$pkgconfigpath", "../../../libhammer.pc")
 testenv = env.Clone()
 testenv.ParseConfig('pkg-config --cflags --libs glib-2.0')
 testenv.Append(LIBS=['hammer'], LIBPATH=['.'])
-testenv.Program('test_suite', tests + ['test_suite.c'])
+ctestexec = testenv.Program('test_suite', ctests + ['test_suite.c'])
+ctest = Alias('testc', [ctestexec], "".join(["env LD_LIBRARY_PATH=", os.path.dirname(ctestexec[0].path), " ", ctestexec[0].path]))
+AlwaysBuild(ctest)
+testruns.append(ctest)
 
 Export("libhammer_static libhammer_shared")
 
-for b in bindings:
+for b in env['bindings']:
     env.SConscript(["bindings/%s/SConscript" % b])
diff --git a/src/bindings/python/SConscript b/src/bindings/python/SConscript
index fd03a3f3..5d788752 100644
--- a/src/bindings/python/SConscript
+++ b/src/bindings/python/SConscript
@@ -1,11 +1,12 @@
 # -*- python -*-
-import os.path
-Import('env libhammer_shared')
+import os, os.path
+Import('env libhammer_shared testruns')
 
 pythonenv = env.Clone(IMPLICIT_COMMAND_DEPENDENCIES = 0)
 
-pythonenv.Append(CPPPATH = ['../../', '/usr/include/python2.7'])
+pythonenv.Append(CPPPATH = ['../../'])
 pythonenv.Append(CCFLAGS = ['-fpic', '-DSWIG', '-Wno-all', '-Wno-extra', '-Wno-error'])
+pythonenv.ParseConfig("pkg-config --cflags python")
 pythonenv.Append(LIBS = ['hammer'])
 pythonenv.Append(LIBPATH = ['../../'])
 pythonenv.Append(SWIGFLAGS = ['-DHAMMER_INTERNAL__NO_STDARG_H', '-Isrc/', '-python'])
@@ -15,9 +16,13 @@ pythonenv.Command("hammer.i", "../swig/hammer.i", Copy("$TARGET", "$SOURCE"))
 swig = ['hammer.i']
 
 libhammer_python = pythonenv.SharedLibrary('hammer', swig, SHLIBPREFIX='_')
+Default(libhammer_python)
 
 pytestenv = pythonenv.Clone()
 pytestenv['ENV']['LD_LIBRARY_PATH'] = os.path.dirname(str(libhammer_shared[0]))
-pytestenv.Command(None, ['hammer_tests.py'] + libhammer_python, "nosetests -vv $SOURCE")
+pytestexec = pytestenv.Command(None, ['hammer_tests.py'] + libhammer_python, "nosetests -vv $SOURCE")
+pytest = Alias("testpython", [pytestexec], pytestexec)
+AlwaysBuild(pytest)
+testruns.append(pytest)
 
 Clean('.', ['hammer.pyc', 'hammer_tests.py', 'hammer_tests.pyc']) 
-- 
GitLab