SCons is a python-written automated build tool that has obvious advantages over GNU make:
1, portability: Python can run the place, you can run SCons
2, extensibility: Theoretically scons just provides the Python class, scons the user can do all the things that Python can do on the basis of this class. For example, if you want to switch a large project that already uses Makefile to SCons, you can keep the original makefile, and use Python to parse the compilation options in makefile, source/destination files, and so on, and pass them as parameters to SCons to complete the compilation.
3, Intelligent: scons inherited the function of Autoconf/automake, automatic parsing system include path, TypeDef, etc. "All dependencies in a global perspective"
Design principles of SCons
correctly, this is evident from the use of MD5 as a file update checking algorithm. To know that make uses a timestamp, in the absence of an NTP server, it is very easy to create an unhealthy build due to the local time and the server being out of sync.
Efficient, can only be said to meet the right premise to achieve efficiency, after all, Python in performance or not compared to make, of course, the former can do more things.
Convenient, because some of the default basic principles have been set, so you just need to write very little code to complete a project build. This is better than make. Of course it is not difficult to make a generic makefile template.
1. Installing SCons
Because SCons is based on Python, the first thing to install is Python, which I installed is the official recommended Python 2.5.1. SCons can be run on a variety of OS, and the version of Windows can be found in http://www.scons.org/download.php.
2.hello World
Write a Hello World in C, as follows
int main ()
{
printf ("Hello, world!\n");
}
Save file name is hello.c, want to build this file with scons, just need,
A. Under the same directory, create a name ofsconstructof the file
B. Add a row to the file,
Program (' hello.c ')
If just want to compile objects, do not do link, can change,
Object (' hello.c ')
C. Executing scons in the current directory
% SCons
scons:reading sconscript Files ...
Scons:done reading sconscript files.
Scons:building targets ...
Cc-o hello.o-c hello.c
Cc-o Hello hello.o
Scons:done building targets.
3.make Clean
Makefile loyal users will generally add clean in the makefile, the role is to delete the generated objects, executables, etc., SCons has built-in this feature, no need to add additional code,Execute scons–c.
% scons-c
scons:reading sconscript Files ...
Scons:done reading sconscript files.
Scons:cleaning targets ...
Removed hello.o
Removed hello
Scons:done cleaning targets.
4. Sconstruct and Makefile
Sconstruct and makefile are fundamentally different, but they have striking similarities.the difference is that sconstruct is a typical Python script with all the features of a Python scriptSimilarly, like Makefile, it's d.eclarative (non-imperative) scripts, that is, program, object These definitions do not immediately trigger the compilationFor
5. Build Multiple Files
Program ([' Prog.c ', ' file1.c ', ' file2.c ')
Specifies that the target file name is Myprog,
Program (' Myprog ', [' prog.c ', ' file1.c ', ' file2.c '])
Note that compiling multiple files and specifying the target file may have semantic ambiguity, so use the file list with brackets.
Here are some common examples for easy use later.
Compile each. c file as a separate program |
Src=split ("" "Foo.c bar.c" "") For x in SRC: Program (x) |
Compile all the. c Files as a program |
Program (' Program ', Glob (' *.c ')) |
Working with environment variables |
ENV = Environment (linkflags= '-PTHREAD-LM ') Env. Program ("FOO.C")
ENV = Environment (ccflags= '-G ', linkflags= '-pthread-lm ') env. Program ("FOO.C") |
Compiling MPI Programs |
Import OS ENV = Environment (env = {' path ': os.environ[' path '}, CC = ' MPICC ') Env. Program ("ALLTOALLV.C")
ENV = Environment (CC = '/OPT/MPICH2/BIN/MPICC ') Env. Program ("ALLTOALLV.C") |
Resources:
1. User manual, Http://www.scons.org/doc/production/HTML/scons-user/index.html
Reference: http://andylin02.iteye.com/blog/849665
The SCons build tool uses