import os, pdb
import StanfordUtils

_packagename = StanfordUtils.getPackageName(__name__)
_target = None
_includeSubdir = ''
_libDepends = ['CoastFoundation', 'testfwFoundation']

def generate(env, **kw):
    global _target, _packagename, _includeSubdir, _libDepends

    # this libraries dependencies
    StanfordUtils.setModuleDependencies(env, _libDepends)

    if _target:
        env.Tool('addLibrary', library=[_packagename])

    # flags / settings used by this library and users of it
#    env.AppendUnique(CPPDEFINES =['SOMEFLAG'])

    # specify public headers here
    StanfordUtils.setIncludePath(env, _packagename, _includeSubdir, internal=False)

    return _target

# create environment for target
targetEnv = StanfordUtils.CloneBaseEnv()

# update environment by adding dependencies to used modules
StanfordUtils.setModuleDependencies(targetEnv, _libDepends)

# win32 specific define to export all symbols when creating a DLL
##targetEnv.AppendUnique(CPPDEFINES=[_packagename.upper() + '_IMPL'])

# maybe we need to add this libraries local include path when building it (if different from .)
StanfordUtils.setIncludePath(targetEnv, _packagename, _includeSubdir)

# specify this modules target
_target = targetEnv.Program(_packagename, StanfordUtils.listFiles(['*.cpp']))

# either create a new environment to register this package with or use targetEnv when no real target gets created
registerEnv = targetEnv
registerEnv.Tool('registerObjects',
             package=_packagename,
             testApps=[_target],
             config=StanfordUtils.listFiles(['config/*.any', 'config/*.txt', 'config/*.tst', 'config/testscript.sh', 'config/prjconfig.sh', 'tmp/*.any', '*.any'])
             )

@@ -30,17 +30,16 @@
 dUtils%0A%0A
-_
 packagen
@@ -83,17 +83,16 @@
 name__)%0A
-_
 target =
@@ -101,582 +101,231 @@
 one%0A
-_includeSubdir = ''%0A_libDepends = %5B'CoastFoundation', 'testfwFoundation'%5D%0A%0Adef generate(env, **kw):%0A    global _target, _packagename, _includeSubdir, _libDepends%0A%0A    # this libraries dependencies%0A    StanfordUtils.setModuleDependencies(env, _libDepends)%0A%0A    if _target:%0A        env.Tool('addLibrary', library=%5B_packagename%5D)%0A%0A    # flags / settings used by this library and users of it%0A#    env.AppendUnique(CPPDEFINES =%5B'SOMEFLAG'%5D)%0A%0A    # specify public headers here%0A    StanfordUtils.setIncludePath(env, _packagename, _includeSubdir, internal=False)%0A%0A    return _target
+%0AbuildSettings = %7B%0A                 'includeSubdir'    : '',%0A                 'libDepends'       : %5B'CoastFoundation', 'testfwFoundation'%5D,%0A#                 'appendUnique'     : %7B 'CPPDEFINES' : 'fooX' %7D%0A                 %7D
 %0A%0A# 
@@ -503,17 +503,35 @@
 getEnv, 
-_
+buildSettings.get('
 libDepen
@@ -532,16 +532,22 @@
 bDepends
+', %5B%5D)
 )%0A%0A# win
@@ -613,30 +613,81 @@
 L%0A##
-targetEnv.AppendUnique
+newVars = buildSettings.get('appendUnique',%7B%7D) + StanfordUtils.EnvVarDict
 (CPP
@@ -695,17 +695,16 @@
 EFINES=%5B
-_
 packagen
@@ -726,16 +726,52 @@
 _IMPL'%5D)
+%0A##targetEnv.AppendUnique(**newVars)
 %0A%0A# mayb
@@ -900,17 +900,16 @@
 getEnv, 
-_
 packagen
@@ -913,17 +913,35 @@
 gename, 
-_
+buildSettings.get('
 includeS
@@ -945,16 +945,22 @@
 deSubdir
+', '')
 )%0A%0A# spe
@@ -984,17 +984,16 @@
  target%0A
-_
 target =
@@ -1011,17 +1011,16 @@
 Program(
-_
 packagen
@@ -1256,17 +1256,16 @@
 package=
-_
 packagen
@@ -1292,17 +1292,16 @@
 stApps=%5B
-_
 target%5D,

factored out generate mechanism into StanfordUtils