Use scons instead of makefile to quickly build applications
- Author: Liu Da-poechant
- Blog: blog.csdn.net/poechant
- Email: zhongchao.ustc@gmail.com
- Copyright · poechant
0 Introduction
Writing building rules for make tools is not easy. Its Complex Configuration Rules are daunting for experienced developers. Many alternatives to the Make tool were born. scons is one of them. Scons is a program written in Python similar to the Make tool. Compared with the make tool, the scons configuration file is simpler and clearer. In addition, it has many advantages.
Scons supports a variety of operating system platforms to achieve program building portability.
1 install
$ tar -xvf scons-2.0.1.tar$ cd scons-2.0.1 $ sudo python setup.py install
2 Hello world2.1 source file
#include <stdio.h> #include <stdlib.h> int main(int argc, char* argv[]) { printf("Hello, SCons!\n"); return 0; }
2.2 Config File
Program('helloscons.c')
2.3 build
$ ls helloscons helloscons.c SConstruct$ cd helloscons/ $ scons scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... gcc -o helloscons.o -c helloscons.c gcc -o helloscons helloscons.o scons: done building targets. $ ls helloscons helloscons.c helloscons.o SConstruct$ ./helloscons Hello, SCons!
2.4 run
$ ./helloscons Hello, SCons!
2.5 clean
$ scons -c scons: Reading SConscript files ... scons: done reading SConscript files. scons: Cleaning targets ... Removed helloscons.o Removed helloscons scons: done cleaning targets.$ ls -ahelloscons.c SConstruct .sconsign.dblite
3 improve your skills! 3.1 specify your Executable File Name
Program('myscons, 'helloscons.c')
3.2 be quiet when building!
$ scons -Q
3.3 a little more complicated program
Program('helloscons2', ['helloscons2.c', 'file1.c', 'file2.c'], LIBS = 'm', LIBPATH = ['/usr/lib', '/usr/local/lib'], CCFLAGS = '-DHELLOSCONS')$ scons -Q gcc -o file1.o -c -DHELLOSCONS file1.c gcc -o file2.o -c -DHELLOSCONS file2.c gcc -o helloscons2.o -c -DHELLOSCONS helloscons2.c gcc -o helloscons2 helloscons2.o file1.o file2.o -L/usr/lib -L/usr/local/lib -lm
3.4 Regular Expression
Program('helloscons2', Glob('*.c')
4 reference
- Http://www.ibm.com/developerworks/cn/linux/l-cn-scons/index.html? CA = Drs-
-
For more information, see "LIU Da's csdn blog": blog.csdn.net/poechant
-