SCons:Environment
DUMP
환경변수 정보는 Dump('ENV')
를 사용하여 확인할 수 있다.
또는 아래와 같은 방법으로 확인 가능하다.
Clone env
아래와 같은 방법으로 클론을 만들 수 있다.
Alias
아래와 같이 Alias를 설정할 수 있다.
env = Environment()
p = env.Program('foo.c')
l = env.Library('bar.c')
env.Install('/usr/bin', p)
env.Install('/usr/lib', l)
ib = env.Alias('install-bin', '/usr/bin')
il = env.Alias('install-lib', '/usr/lib')
env.Alias('install', [ib, il])
Depends
종속성 설정은 아래와 같이 적용할 수 있다.
Adding PATH
env = Environment(ENV = os.environ)
env.PrependENVPath('PATH', '/usr/local/bin')
env.AppendENVPath('LIB', '/usr/local/lib')
Default Targets
Ignoring Dependencies
Command
env.Command('foo.out', 'foo.in',
"$FOO_BUILD < $SOURCES > $TARGET")
## OR:
env.Command('bar.out', 'bar.in',
["rm -f $TARGET",
"$BAR_BUILD < $SOURCES > $TARGET"],
ENV = {'PATH' : '/usr/local/bin/'})
## OR:
def rename(env, target, source):
import os
os.rename('.tmp', str(target[0]))
env.Command('baz.out', 'baz.in',
["$BAZ_BUILD < $SOURCES > .tmp",
rename ])
Custom Builders
bld = Builder(action = 'foobuild < $SOURCE > $TARGET')
env = Environment(BUILDERS = {'Foo' : bld})
env.Foo('file.foo', 'file.input')
실행결과는 아래와 같다.
Example
#!/usr/bin/python
env = Environment()
hello = env.Program('hello', 'hello.c')
env.Default(hello)
env.Append(BUILDERS={'CreateLog':
Builder(action='$SOURCE.abspath > $TARGET', suffix='.log')})
log = env.CreateLog('hello', hello)
zipped_log = env.Zip('logs.zip', log)
env.Alias('cleanup', zipped_log)
Doxygen command
def setupDoxygenBuilder():
env = createEnvironment()
name = 'doxygen'
prefix = 'src'
config = 'Doxyfile'
source = findWithSuffix(prefix, CPP_SUFFIX_LIST)
target = 'doxygen.log'
output = 'html'
command = 'doxygen $SOURCE > $TARGET'
env.Command(target, config, [command])
env.Depends(target, source)
env.Clean(target, [output])
return env.Alias(name, target)
ctags command
def setupCtagsBuilder():
env = createEnvironment()
name = 'ctags'
target = 'tags'
prefix = 'src'
source = findWithSuffix(prefix, CPP_SUFFIX_LIST)
flags = ' --c++-kinds=+p'
flags += ' --fields=+iaS'
flags += ' --extra=+q'
flags += ' --tag-relative=no'
flags += ' -f $TARGET'
flags += ' $SOURCES'
command = 'ctags ' + flags
env.Command(target, source, [command])
return env.Alias(name, target)
cscope command
env = createEnvironment()
name = 'cscope'
files = 'cscope.files'
target = 'cscope.out'
prefix = 'src'
source = findWithSuffix(prefix, CPP_SUFFIX_LIST)
flags = ' -b'
flags += ' -i $SOURCE'
flags += ' -f $TARGET'
command = 'cscope ' + flags
def create_files(env, target, source):
result = str(target[0])
if os.path.isfile(result):
os.remove(result)
with open(result, 'wb') as f:
index = 0
while index < len(source):
f.write(str(source[index]) + '\n')
index += 1
env.Command(files, source, [create_files])
env.Command(target, files, [command])
return env.Alias(name, target)