build: Make it easier to change command line macros

I store release and debug options in a list so that env.Replace() can be
used to set, modify, and restore values.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2013-07-05 20:37:51 -04:00 committed by Anna Schumaker
parent cf7f1f726f
commit 7c67d062df
3 changed files with 16 additions and 12 deletions

8
config
View File

@ -15,13 +15,15 @@ def get_env(flags):
e.Append(LINKCOMSTR = "Linking $TARGET")
return e
release = get_env([ "-O2" ])
debug = get_env([ "-Wall", "-Werror", "-g", "-DCONFIG_DEBUG" ])
CONFIG_RELEASE = [ "-O2" ]
CONFIG_DEBUG = [ "-Wall", "-Werror", "-g", "-DCONFIG_DEBUG" ]
release = get_env(CONFIG_RELEASE)
debug = get_env(CONFIG_DEBUG)
env = release
if CONFIG_DEBUG == True:
env = debug
Export("release", "debug", "env")
Export("release", "debug", "env", "CONFIG_RELEASE", "CONFIG_DEBUG")

View File

@ -1,5 +1,8 @@
#!/usr/bin/python
Import("CONFIG_VERSION", "release", "debug")
Import("release", "debug", "CONFIG_VERSION", "CONFIG_RELEASE", "CONFIG_DEBUG")
release.Append(CCFLAGS = [ "-DCONFIG_VERSION=%s" % CONFIG_VERSION ])
debug.Append(CCFLAGS = ["-DCONFIG_VERSION=%s-debug" % CONFIG_VERSION ])
CONFIG_RELEASE += [ "-DCONFIG_VERSION='\"%s\"'" % CONFIG_VERSION ]
CONFIG_DEBUG += [ "-DCONFIG_VERSION='\"%s-debug\"'" % CONFIG_VERSION ]
release.Replace(CCFLAGS = CONFIG_RELEASE)
debug.Replace(CCFLAGS = CONFIG_DEBUG)

View File

@ -2,18 +2,17 @@
Import("release", "debug")
def make_test(group, src, name, env):
o = env.StaticObject(name, src)
p = env.Program("%s.test" % name, o)
Alias("tests", [o, p])
Alias("tests/%s" % group, [o, p])
Alias("tests/%s/%s" % (group, name), [o, p])
obj = env.StaticObject(name, src)
prog = env.Program("%s.test" % name, obj)
Alias("tests", [obj, prog])
Alias("tests/%s" % group, [obj, prog])
Alias("tests/%s/%s" % (group, name), [obj, prog])
def Test(group, src):
name, extension = src.rsplit(".", 1)
make_test(group, src, name, release)
make_test(group, src, "%s-debug" % name, debug)
Export("Test")