Penguin

Differences between current version and previous revision of MakeToSCons.

Other diffs: Previous Major Revision, Previous Author, or view the Annotated Edit History

Newer page: version 11 Last edited on Friday, September 16, 2005 4:29:28 pm by AristotlePagaltzis
Older page: version 10 Last edited on Friday, March 4, 2005 11:25:33 am by JohnMcPherson Revert
@@ -1,26 +1,27 @@
 SamJansen's work in progress. 
  
-  
- !!! What 
+!!! What?  
  
 This document describes moving from the traditional make(1) build system to the [Python]-based [SCons] replacement. 
  
-!!! Reason  
+!!! Why?  
  
 make(1) is not for everyone. I've had to maintain the build system for a reasonably large and complex project and using makefiles has been more and more of a headache as time has passed. I have found almost no redeeming features in make - the only thing I can say for it is that most people who wish to compile software will have it installed. 
  
-!!! Should I use [SCons] too
+!!! Who
  
-Maybe. [SCons] requires that whoever has to compile the software has both [Python] and [SCons] installed. If this is an acceptable requirement, then the answer is probably "yes". 
+Should you use [SCons] too? Maybe. [SCons] requires that whoever has to compile the software has both [Python] and [SCons] installed. If this is an acceptable requirement, then the answer is probably "yes". 
  
 The worst thing about [SCons] is that it does take some time to learn. It is not hard to learn; being based on the simple but powerful programming language [Python] helps here, but it can be hard to make the leap from a system you already know to a new one, even if the old system is inferior, simply because of the extra time it takes to learn the new system. However, I recommend learning modern build systems that don't employ make. 
  
 !!! The simple stuff 
  
-[SCons] does a few things for free. Dependency tracking is the first one that springs to mind. Consider the following makefile and its [SCons] equivalent:: 
+[SCons] does a few things for free. Dependency tracking is the first one that springs to mind. Consider the following makefile and its [SCons] equivalent:  
+  
+''''
  
- <br> MakeFile:: 
+ MakeFile:: 
  <verbatim> 
  program: main.o sam.o johno.o 
  gcc -o $@ $^ 
  </verbatim> 
@@ -29,25 +30,25 @@
  <verbatim> 
  Program(source = ["main.c", "sam.c", "johno.c"], target = "program") 
  </verbatim> 
  
-Both of these work the same at the first glance, though I believe the SConstruct (yes, SConstruct is the name of the file that replaces your Makefile ) file a lot more readable. However the [SCons] file has the following extra features: 
+Both of these work the same at the first glance, though I believe the SConstruct file (yes, SConstruct is the name of the file that replaces your MakeFile ) to be a lot more readable. However the [SCons] file has the following extra features: 
  
 * Proper dependency tracking. [SCons] scans the source file for headers so it knows when each file needs to be compiled. Make has no knowledge of this by default, and doing proper dependency tracking in make is quite a nightmare (but possible). 
-* MD5Sum based checking of the source files to see which ones need to be recompiled. Make uses timestamps, which is also an option for [SCons]. 
+* [MD5] checksum based checking of the source files to see which ones need to be recompiled. Make uses timestamps, which is also an option for [SCons]. 
 * No explicit rules needed for this simple example. In this particular MakeFile the linking line is still necessary, along with strange syntax: a casual reader has no idea what <tt>$@</tt> and <tt>$^</tt> mean. To be fair, make has a lot of implicit rules, and the command wouldn't be necessary here if there was a dependency with the same basename as the target, ie something like <tt>foo: foo.o bar.o</tt>. 
 * You can automatically clean the build with <tt>scons -c</tt>. This cleans only the files generated in the build. Clean rules have to be specified by the programmer in MakeFile~s. 
-* Even works in [Windows] with the MicrosoftVisualStudio C Compiler. 
+* Even works in [Windows] with the MicrosoftVisualStudio [ C] Compiler. 
  
 !! Setting <tt>CFLAGS</tt> and similar 
  
 You generally create an construction environment to set environment variables in [SCons] like so: 
  
-<verbatim>  
-env = Environment(CCFLAGS = '-Wall -pipe', LIBS = [ ['m', 'jpeg'])  
-env.Program('sam', [ ["lib.c", "sam.cc"], CPPPATH = [ ['include', 'common/include'])  
-env.SharedLibrary('testlib', [ ["source1.cc", "source2.c"])  
-</verbatim> 
+ <verbatim>  
+ env = Environment(CCFLAGS = '-Wall -pipe', LIBS = ['m', 'jpeg'])  
+ env.Program('sam', ["lib.c", "sam.cc"], CPPPATH = ['include', 'common/include'])  
+ env.SharedLibrary('testlib', ["source1.cc", "source2.c"])  
+ </verbatim> 
  
 This also sets the variable <tt>CPPPATH</tt>, which specifies which directories are to be searched for include files that are scanned during depency tracking. These are also passed to the compiler with the <tt>-I</tt> flag in the case of [GCC]. The flags can also be passed in the <tt>Program</tt> or <tt>Library</tt> line, constructing and <tt>Environment</tt> is usually done so multiple things can be built with the same environment. 
  
 A full list of the possible options can be found in [the SCons manual | http://www.scons.org/doc/HTML/scons-man.html]. 
@@ -59,12 +60,12 @@
 !! Globbing multiple source files 
  
 It is simplicity itself to include multiple files in the build. Remember that [SCons] is [Python]-based? 
  
-<verbatim>  
-import glob  
-Library(glob.glob('*.c') + glob.glob('source_dir_2/*.cc'), 'sam')  
-</verbatim> 
+ <verbatim>  
+ import glob  
+ Library(glob.glob('*.c') + glob.glob('source_dir_2/*.cc'), 'sam')  
+ </verbatim> 
  
 [Python]'s <tt>glob</tt> module does all the hard work. Again, full dependency tracking and all other features of [SCons] work correctly. 
  
 !! Hierarchical builds 
@@ -72,10 +73,10 @@
 [SCons] supports hierarchical builds with the use of the <tt>SConscript</tt> directive. These scripts will be read and their information processed. No new [SCons] is forked for the <tt>SConscript</tt> directives, unlike the usual recursive make solution. 
  
 Including other directories in the build is as simple as: 
  
-<verbatim>  
-SConscript("dir1/")  
-SConscript("dir2/")  
-</verbatim> 
+ <verbatim>  
+ SConscript("dir1/")  
+ SConscript("dir2/")  
+ </verbatim> 
  
 This will read in the <tt>SConscript</tt> files in <tt>dir1</tt> and <tt>dir2</tt>. It is possible to export environments to these other scripts if need be.