Fast conversion of Makefile and SCons
Makefile is the most commonly used engineering management tool in a traditional C + + development project, and now with the growing popularity of Python, Python-based code-compiling tools SCons used more and more widely. In some relatively large projects, may need to convert makefile to SCons, or in turn, based on scons conversion to makefile, this article combined with some of the projects I met, summed up some of the common patterns in two different tools to achieve.
1. Include header file
Implementation in Makefile:
specified by-I, for example:-i./-i/usr/include
Implementation in SCons:
specified by Cpppath, for example:
Cpppath= Split ('.. /include ')
Cpppath= env[' Cpppath ' + cpppath
Env. Cpppath=split ('.. /include ')
2. Modify compilation options
Implementation in Makefile:
Direct with compile options: such as-wall-o3
Implementation in SCons:
ccflags= env[' ccflags ' + ccflags
Env. Ccflags=split ('-wall-o3 ')
To modify a macro definition:
Implementation in Makefile:
-ddebug-drelease
Implementation in SCons:
cppdefines=env[' Cppdefines ']+ local_cppdefines
3. File installation and deletion
Makefile in the implementation, by definition. Phonyclean,. Phony Install implementation:
. Phony:clean
Clean
-rm$ (TARGET) $ (TESTCASE)
. Phony:install
Install
-cpdesmon/bin/
-cplibdes.a/lib/user64/
echo "Install done!"
Implementation in SCons:
Env. Install ('/bin ', Source = [' Desmon '])
Env. Clean ('/bin ', [' Desmon])
4. Link Static Library
Implementation in Makefile:
Put it in the object file dependency list, Depobj=target.olibdep.a
Implementation in SCons:
Put in the. o File dependency list: For example depobj=split (' Target.olibdep.a ')
5. Link the dynamic Library
Implementation in Makefile:
Specify the name of the library at the link stage, such as-lpthread, which indicates dependency libpthread.so
Implementation in SCons:
On the Libs list, such as specifying dynamic link libpthread.so:
Env. Libs=split (' pthread ')
6. Specify the generated. o File
Implementation in Makefile:
Gcc-c-O name.o name.c
Implementation in SCons:
Env. Staticobject ()
7. Specify the build static library
Implementation in Makefile:
Arrcs-o libtest.a name1.o name2.o name3.o
Implementation in SCons:
Env. Staticlibrary (target= ' libtest ', Source = [' name1.o name2.o name3.o '], Cpppath =env[' cpppath ') + cpppath, ccflags = env[' C CFLAGS '] + ccflags)
8. Specify the build dynamic library
Implementation in Makefile :
Gcc-shared-o libtest.so name1.o name2.o name3.o
Implementation in SCons :
Env.sharedlibrary ('libtest', ['name1.o', 'name2.o', 'name3.c '])
9. Specify the build executable file:
Implementation in Makefile:
Gcc-o dest.o name1.o name2.o name3.o, again such as:
$ (TESTCASE):%:%.O
$ (CC)-o [email protected] $^ $ (CFLAGS) $ (LIBS) $ (Includepath)
Implementation in SCons:
Env. Program (target= item, Source = [item + (". O")] + Split (' libsms.a '), Cpppath = env[' Cpppath '] + cpppath, ccflags = env[' CCFL AGS '] +ccflags, LIBS = locallibs)
10. Compile Multiple directories:
Implementation in Makefile:
subdirs= \
SUB1 \
Sub2
All: $ (subdirs)
Fori in $ (subdirs); Do $ (make)-C $ $i all; Sleep 2; Done
@echo
Implementation in SCons:
Implement the corresponding sconscript in each subdirectory, implement the sconsctruct in the top-level directory, include the sconscript of each subdirectory inside
11. Compiling multiple Files
In makefile, the principle of self-multiple derivation is used makefile:
Testcase=a_testb_test c_event
$ (TESTCASE):%:%.O
$ (CC)-o [email protected] $^ $ (CFLAGS) $ (LIBS) $ (Includepath)
SCons, use the Pythonfor statement:
testapps= Split (' a_test b_test c_event ')
Foritem in Testapps:
Itemsrc= Item + (". C")
Env. Staticobject (itemsrc,cppdefines = ccflags)
Env. Program (target= item, Source = [item + (". O")] + Split (' libsms.a '), Cpppath = env[' Cpppath '] + cpppath, ccflags = env[' CCFL AGS '] +ccflags, LIBS = locallibs)
12. Import Environment variables
Implementation in Makefile:
You can export an environment variable under the shell such as: Export wkdir= ' pwd ', after export in makefile, after the makefile of subdirectories can be used by $ (wkdir)
Implementation in SCons: Taking Wkdir as an example
When you define env at the top, add Wkdir to the Env list and then exportenv. When the subdirectory needs to be used, the Wkdir can be used after using the import (' env ')
Call Makefile Mix in 13.scons
Use the Sys in Python. Execute () system command, which executes the makefile inside.
This article is from the "Store Chef" blog, so be sure to keep this source http://xiamachao.blog.51cto.com/10580956/1865648
Makefile and SCons Conversion Quick reference