http://andylin02./blog/850341 1. 基本使用
ort os.path
program_list = Program('hello.c') program_name = str(program_list[0]) if not os.path.exists(program_name): print program_name, "does not exist!" 此例判断了文件是否存在 6. 依赖关系 6.1 Decider函数,确定文件是否被修改 6.1.1 默认使用MD5检查源文件内容而不是时间戳,用touch不算修改过 显示调用 Program('hello.c') Decider('MD5') 6.1.2 使用时间戳 Program('hello.c') Decider('timestamp-newer') 与下面语句等价 Program('hello.c') Decider('make') 更详细的检查 Program('hello.c') Decider('timestamp-match') 6.1.3 两者同时使用 Program('hello.c') Decider('MD5-timestamp') 6.3 $CPPPATH 隐含依赖关系 Program('hello.c', CPPPATH = ['include', '/home/project/inc']) 会在编译时加 -I 6.4 缓冲隐式依赖关系 % scons -Q --implicit-cache hello 运行选项 SetOption('implicit_cache', 1) 写在脚本里 这样下次就不用从头开始找依赖关系了 % scons -Q --implicit-deps-changed hello 再打开 6.5 显式依赖关系: Depends函数 当Scons没有找到关系时 hello = Program('hello.c') Depends(hello, 'other_file') 6.9 总是编译 hello = Program('hello.c') AlwaysBuild(hello) 7. 环境 7.2 创建环境 7.2.1 imp ort os env = Environment(CC = 'gcc', CCFLAGS = '-O2') env.Program('foo.c') % scons -Q 7.2.2 获取环境变量 env = Environment() print "CC is:", env['CC'] % scons -Q CC is: cc scons: `.' is up to date. env = Environment(FOO = 'foo', BAR = 'bar') dict = env.Dictionary() for key in ['OBJSUFFIX', 'LIBSUFFIX', 'PROGSUFFIX']: print "key = %s, value = %s" % (key, dict[key]) This SConstruct file will print the specified dictionary items for us on POSIX systems as follows: % scons -Q key = OBJSUFFIX, value = .o key = LIBSUFFIX, value = .a key = PROGSUFFIX, value = scons: `.' is up to date. 13. Install安装文件至其他文件夹 env = Environment() hello = env.Program('hello.c') env.Install('/usr/bin', hello) 13.1 在目录里安装多个文件 env = Environment() hello = env.Program('hello.c') goodbye = env.Program('goodbye.c') env.Install('/usr/bin', [hello, goodbye]) env.Alias('install', '/usr/bin') 13.2 一个文件不同存放 env = Environment() hello = env.Program('hello.c') env.InstallAs('/usr/bin/hello-new', hello) env.Alias('install', '/usr/bin') % scons -Q install cc -o hello.o -c hello.c cc -o hello hello.o Install file: "hello" as "/usr/bin/hello-new" 14 平台独立的文件系统操作 14.1 复制 Command("file.out", "file.in", Copy("$TARGET", "$SOURCE")) 或者 Command("file.out", [], Copy("$TARGET", "file.in")) 16. 多层目录构建 Sconconstruct在最顶层 16.1 SConscript文件可以层层包含 SConscript(['drivers/SConscript', 'parser/SConscript', 'utilities/SConscript']) 在drivers下: SConscript(['display/SConscript', 'mouse/SConscript']) 16.2 对文件SConscript的相对目录 SConscript(['prog1/SConscript', 'prog2/SConscript']) |
|
来自: 心不留意外尘 > 《compile build》