ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

【2016-03-02】scons初步学习笔记

【2016-03-02】scons初步学习笔记 [历史归档]本文原发布于 cstriker1407.info 个人博客内容为历史存档仅供参考。发布时间2016-03-02 标题scons初步学习笔记分类编程 标签sconsscons初步学习笔记最近项目上用到了scons这里笔记下学习记录吧。百度百科中对于scons的介绍如下:scons是一个Python写的自动化构建工具从构建这个角度说它跟GNU make是同一类的工具。它是一种改进并跨平台的gnu make替代工具其集成功能类似于autoconf/automake 。scons是一个更简便更可靠更高效的编译软件。简单来说scons是一个跨平台的自动化构建工具使用python编写可以非常方便的在不同的平台间进行移植。相对于其他的跨平台编译工具scons使用python编写可读性和可维护性更好更容易学习。scons官方网站http://scons.org/根据scons的官方介绍scons一共有3中获取方式1 安装版****SCons Packages这种版本类似于windows上的常用的安装版本。2 绿色版scons-local Packages这种版本类似于windows上的绿色版本它的用途是scons可以和自己编写的软件一起发布这样在发布机器上就不需要额外的安装scons了。3 源码版scons-src Packages这个不用多说了就是scons开发环境了。作者一般使用scons-local。这里就用它来简单学习下。当前最新版本是2.4.1对应的在线文档地址http://scons.org/documentation.html一般分为3个文档man page: http://scons.org/doc/production/HTML/scons-man.htmluser doc: http://scons.org/doc/production/HTML/scons-user.htmlapi doc: http://scons.org/doc/latest/HTML/scons-api/index.html验证本地环境cstriker1407cstriker1407-x64:~/scons$ python--version#首先看下python的版本scons需要python2.x版本Python2.7.9 cstriker1407cstriker1407-x64:~/scons$tar-zxfscons-local-2.4.1.tar.gz#解压缩下载的压缩文件cstriker1407cstriker1407-x64:~/scons$lssconsign.py scons-LICENSE scons-local-2.4.1 scons-local-2.4.1.tar.gz scons.py scons-README scons-time.py cstriker1407cstriker1407-x64:~/scons$ python scons.py-v#最基本的命令可以发现打印出scons的版本了。SCons by Steven Knight et al.: script: v2.4.1.rel_2.4.1:3453:73fefd3ea0b0,2015/11/09 03:25:05, by bdbaddog on ubuntu1404-32bit engine: v2.4.1.rel_2.4.1:3453:73fefd3ea0b0,2015/11/09 03:25:05, by bdbaddog on ubuntu1404-32bit engine path:[/home/cstriker1407/scons/scons-local-2.4.1/SCons]Copyright(c)2001-2015The SCons Foundation cstriker1407cstriker1407-x64:~/scons$最基本的使用方式:首先建立两个文件hellow****orld.c#includestdio.hintmain(void){printf(Hello World );return0;}Scon****structProgram(helloworld.c);scons的使用方式其实就是读取特定的Sconstruct文件然后根据文件来进行特定的编译。假如上述的两个文件的位置为cstriker1407cstriker1407-x64:~/scons$lsexamples sconsign.py scons-LICENSE scons-local-2.4.1 scons-local-2.4.1.tar.gz scons.py scons-README scons-time.py cstriker1407cstriker1407-x64:~/scons$cdexamples/helloworld/ cstriker1407cstriker1407-x64:~/scons/examples/helloworld$lshelloworld.c SConstruct那么我们可以尝试编译一下cstriker1407cstriker1407-x64:~/scons$ python scons.py-Cexamples/helloworld/#可以使用C来指定工作目录如果没有指定默认为当前目录scons: Entering directory/home/cstriker1407/scons/examples/helloworld scons: Reading SConscript files... scons:donereading SConscript files. scons: Building targets... gcc-ohelloworld.o-chelloworld.c gcc-ohelloworld helloworld.o scons:donebuilding targets.#可以看到我们什么都没做就在LINUX下编译了。cstriker1407cstriker1407-x64:~/scons$ cstriker1407cstriker1407-x64:~/scons$ python scons.py-Cexamples/helloworld/#如果什么都没有修改会保持上次的编译状态scons: Entering directory/home/cstriker1407/scons/examples/helloworld scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... scons: .is up to date. scons:donebuilding targets. cstriker1407cstriker1407-x64:~/scons/examples/helloworld$ ./helloworld#可以执行下看看效果Hello World cstriker1407cstriker1407-x64:~/scons$ python scons.py-Cexamples/helloworld/-c#c是用来清理cleanscons: Entering directory /home/cstriker1407/scons/examples/helloworld scons: Reading SConscript files... scons:donereading SConscript files. scons: Cleaning targets... Removed helloworld.o Removed helloworld scons:donecleaning targets. cstriker1407cstriker1407-x64:~/scons/examples/helloworld$ls#可以看到清理干净了helloworld.c SConstruct
返回列表