scons实践笔记(2)--带选项的编译
2013-03-31 19:10
197 查看
(1)如果想要生成两个编译器版本的代码,比如在PC机上的GCC编译和ARM linux gcc交叉编译,并且在编译的时候可以选择,SConstruct内容如下,源代码测试文件还是前一个hello world程序:
第二条语句指定了若platform缺省时为pc,故执行scons 与scons platform=pc效果一样。运行如下:
(2)同样,这个方法还可以用来编译器生成不同版本的代码(如release版本和debug版本),如下:
这样,便可控制debug版本和release版本的生成,另外SConstruct 脚本中第3、4、5、6句用来产生帮助信息,可以加上-h参数以运行使用:
这样便可提示用户使用命令。
(3)变量(如debug=1,platform=pc)还可以从文件中引入,详细在用户手册(10.2.3. Reading Build Variables From a File)一节,预编译定义也可由这种方法定义
> vim SConstruct src = Glob('*.c') platform = ARGUMENTS.get('platform','pc') if platform == 'arm': EXE_PATH = '/opt/arm-2007q1/bin' PREFIX = 'arm-none-linux-gnueabi-' ARMCC = PREFIX + 'gcc' ARMAS = PREFIX + 'gcc' ARMAR = PREFIX + 'ar' ARMLINK = PREFIX + 'gcc' ARMSIZE = PREFIX + 'size' ARMOBJDUMP = PREFIX + 'objdump' ARMOBJCPY = PREFIX + 'objcpy' env = Environment (AS = ARMAS, CC = ARMCC, AR = ARMAR, LINK = ARMLINK) env.PrependENVPath ('PATH',EXE_PATH) elif platform == 'pc': env = Environment() else: pass env.Program(source = src, target = 'hello_world')
第二条语句指定了若platform缺省时为pc,故执行scons 与scons platform=pc效果一样。运行如下:
> ls main.c SConstruct > scons platform=arm scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... arm-none-linux-gnueabi-gcc -o main.o -c main.c arm-none-linux-gnueabi-gcc -o hello_world main.o scons: done building targets. > scons platform=pc scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... gcc -o main.o -c main.c gcc -o hello_world main.o scons: done building targets. > scons -c scons: Reading SConscript files ... scons: done reading SConscript files. scons: Cleaning targets ... Removed main.o Removed hello_world scons: done cleaning targets. > scons scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... gcc -o main.o -c main.c gcc -o hello_world main.o scons: done building targets.
(2)同样,这个方法还可以用来编译器生成不同版本的代码(如release版本和debug版本),如下:
> vim SConstruct src = Glob('*.c') debug = ARGUMENTS.get('debug',0) vars = Variables(None,ARGUMENTS) vars.Add('debug','Set to 1 to build for debug', 0) env = Environment(variables = vars) Help(vars.GenerateHelpText(env)) if int(debug) == 1: env.Append( CCFLAGS = '-g') env.Program(source = src, target = 'hello_world') > ls main.c SConstruct > scons debug=1 scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... gcc -o main.o -c -g main.c gcc -o hello_world main.o scons: done building targets. > scons debug=0 scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... gcc -o main.o -c main.c gcc -o hello_world main.o scons: done building targets.
这样,便可控制debug版本和release版本的生成,另外SConstruct 脚本中第3、4、5、6句用来产生帮助信息,可以加上-h参数以运行使用:
> scons -h scons: Reading SConscript files ... scons: done reading SConscript files. debug: Set to 1 to build for debug default: 0 actual: 0 Use scons -H for help about command-line options.
这样便可提示用户使用命令。
(3)变量(如debug=1,platform=pc)还可以从文件中引入,详细在用户手册(10.2.3. Reading Build Variables From a File)一节,预编译定义也可由这种方法定义
相关文章推荐
- scons 实践笔记(3)--模块编译
- Go编译选项(笔记)
- C/C++实践笔记_002编译和链接
- Android开发实践:如何设置NDK的编译选项
- cc的编译选项(学习笔记)
- Android开发实践:如何设置NDK的编译选项
- Android开发实践:如何设置NDK的编译选项
- 安全编码实践一:GS编译选项和缓存溢出
- [ARM]【编译】【实践】 - 浮点编译选项NEON引发的Skia的库Illegal instruction运行错误和解决办法
- gcc 编译选项笔记
- Mingw32 编译选项笔记
- RT-Thread 学习笔记(三)---用SCons 构建编译环境
- 软件调试笔记57 - 调试符号 : 编译和链接选项
- hadoop2.5.2学习及实践笔记(二)—— 编译源代码及导入源码至eclipse
- CVM编译实践笔记
- CVM编译实践笔记
- scons实践笔记(1)--hello world
- VC编译选项(不常用)
- VC编译选项 MT MTd MD MDd 全面分析
- 【C++】学习笔记四十四——单独编译