使用
这里通过一个简单的示例来说明。
一个hello.c源文件,一个SConsturct文件
hello.c:
#include <stdio.h>
int main(void)
{
printf("hello,scons!\n");
return 0;
}
SConstruct
Program("hello.c")
运行Scons,得到结果如下:
liujianhuadeiMac:myscons liujianhua$ cat SConstruct
Program("hello.c")
liujianhuadeiMac:myscons liujianhua$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
gcc -o hello.o -c hello.c
gcc -o hello hello.o
scons: done building targets.
liujianhuadeiMac:myscons liujianhua$ ./hello
hello,scons!
liujianhuadeiMac:myscons liujianhua$ ls
SConstruct hello hello.c hello.o
liujianhuadeiMac:myscons liujianhua$
在上面的运行结果里面我们看到,程序的编译与make没有什么两样,同样的操作,只是把scons换成make,SConstruct换成Makefile。Scons相比Makefile简单很多。
Sconstruct以Python脚本的语法编写,你可以像编写Python肚子本一样来编写他。其中的Program是编译的类弄,说明你准备想建一个可执行的二进制程序,它由hello.c文件来生成。
在这里,没有指定生成的可扩行程序的名字,SCons会把源代码文件名字的后缀去掉,用来作为可执行文件的名字。
我们甚至不需要像Makefile那样指定清理的动作,就可以扩行清理任务。在SCons中,执行清理任务由参数-c指定,如下:
liujianhuadeiMac:myscons liujianhua$ scons -c
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Cleaning targets ...
Removed hello.o
Removed hello
scons: done cleaning targets.
liujianhuadeiMac:myscons liujianhua$ ls
SConstruct hello.c
liujianhuadeiMac:myscons liujianhua$
|