Please note:The SCons wiki is in read-only mode due to ongoing spam/DoS issues. Also, new account creation is currently disabled. We are looking into alternative wiki hosts.
Differences between revisions 17 and 18
Revision 17 as of 2006-11-08 01:42:20
Size: 5456
Comment:
Revision 18 as of 2008-03-12 02:47:10
Size: 5456
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

Line 5: Set your environment! Lots of people get burned by the fact that SCons erases most of the environment variables.

Line 12: A very basic Builder. Note that single_source is set to True. This means that a set of sources [ "foo1.scm", "foo2.scm", "foo3.scm" ] will get converted to [ "foo1.c", "foo2.c", "foo3.c" ] rather than all being piled into [ "foo1.c" ].

Line 15: Add the new builder to the Environment for later use

Line 19: A fairly basic Emitter. This was used because of the previously mentioned issue that I wanted a suffix of "_.c" and the suffixes are tied to being only after a ".". Also, the default for when single_source is False is to take the first mentioned source and convert it into the target. This is different from the default behavior of gsc which uses the last source file. Since I wanted to emulate that as well, I created a custom emitter.

Line 32: Another simple Builder. This time single_source is set to False. This means that all of the sources get compiled into a single file. In this instance, that is what we want.

Line 36: Add the new builder to the Environment for later use

Line 43: Note that I make a Copy() (soon to be Clone()) of environments so that I can mangle them later.

Line 44: This is a basic override of the default C compilation flags. I'm a bit verbose here because I am going to do cross-compiling later.

Line 48: Call the SConscript which will build the main library. Interesting things to note here:

  • You have to explicitly export an environment in order to use it in the subsidiary SConscript. This does catch people.
  • I am explicitly returning a reference to the library itself which I will use later. This is in keeping with the whole idea of avoiding strings for referencing targets.

Line 60: Call the SConscript which will build the main interpreter. Note that I am passing in both "env" and "libgambc" references. Those will show up again in the subsidiary SConscript files.

Line 65: Call the SConscript which will build the main compiler. Note that I am passing in both "env" and "libgambc" references. Those will show up again in the subsidiary SConscript files.

   1 # -*-python-*-
   2 
   3 import SCons
   4 
   5 rootEnv = Environment(BUILDROOT="build",
   6                       ENV = {"PATH": ["/bin", "/usr/bin",
   7                                       "/opt/bin", "/usr/local/bin", "/sw/bin"]})
   8 
   9 
  10 # Add the Gambit compiler builder to the main Environment
  11 # FIXME: Should probably find some way to make /home/gambit/4.0b20 a variable
  12 gambitCompilerBuilder = Builder(action = '/home/gambit/4.0b20/bin/gsc -:="/home/gambit/4.0b20" -f -o $TARGET -c -check $SOURCE',
  13                                 suffix = ".c", src_suffix = ".scm",
  14                                 single_source=True)
  15 rootEnv.Append(BUILDERS = {"GambitCompiler" : gambitCompilerBuilder})
  16 
  17 
  18 # Add the Gambit library builder to the main Environment
  19 def gambitLinkerEmitter(target, source, env):
  20     # target and source are always lists--makes keywords more descriptive
  21     # for the next time I actually touch the SConstruct
  22     (targets, sources) = (target, source)
  23 
  24     # Grab the last source file the way a gsc without -o would
  25     # ARGGGGHHH!  Is this really the only way to get the base name?
  26     baseName = SCons.Util.splitext(str(sources[-1].name))[0]
  27 
  28     targets = [SCons.Util.adjustixes(baseName, None, "_.c")]
  29 
  30     return (targets, sources)
  31 
  32 gambitLinkerBuilder = Builder(action = '/home/gambit/4.0b20/bin/gsc -:="/home/gambit/4.0b20" -f -link -o $TARGET $SOURCES',
  33                               emitter=gambitLinkerEmitter,
  34                               src_suffix = ".scm",
  35                               single_source=False)
  36 rootEnv.Append(BUILDERS = {"GambitLinker" : gambitLinkerBuilder})
  37 
  38 
  39 
  40 # Compile the main Gambit library
  41 gambitLibCCFLAGS = '-no-cpp-precomp -Wall -W -Wno-unused -O1 -fno-math-errno -fschedule-insns2 -fno-trapping-math -fno-strict-aliasing -fwrapv -fexpensive-optimizations -fforce-addr -fpeephole2 -falign-jumps -falign-functions -fno-function-cse -ftree-copyrename -ftree-fre -ftree-dce -fregmove -fgcse-las -freorder-functions -fcaller-saves -fno-if-conversion2 -foptimize-sibling-calls -fcse-skip-blocks -funit-at-a-time -finline-functions -fomit-frame-pointer -fPIC -fno-common -mieee-fp -DHAVE_CONFIG_H -D___PRIMAL -D___LIBRARY -D___GAMBCDIR=\\\"/home/gambit/4.0b20\\\"'
  42 
  43 libEnv = rootEnv.Copy()
  44 libEnv.Replace(CCFLAGS=gambitLibCCFLAGS)
  45 
  46 env = libEnv
  47 Export("env")
  48 libgambc = libEnv.SConscript("lib/SConscript", build_dir="$BUILDROOT/lib", exports="env")
  49 
  50 
  51 # Compile the Gambit gsi and gsc executables
  52 gambitExecutableCCFLAGS = '-no-cpp-precomp -Wall -W -Wno-unused -O1 -fno-math-errno -fschedule-insns2 -fno-trapping-math -fno-strict-aliasing -fwrapv -fexpensive-optimizations -fforce-addr -fpeephole2 -falign-jumps -falign-functions -fno-function-cse -ftree-copyrename -ftree-fre -ftree-dce -fregmove -fgcse-las -freorder-functions -fcaller-saves -fno-if-conversion2 -foptimize-sibling-calls -fcse-skip-blocks -funit-at-a-time -finline-functions -fomit-frame-pointer -fPIC -fno-common -mieee-fp -DHAVE_CONFIG_H'
  53 
  54 gsiCCFLAGS = gambitExecutableCCFLAGS
  55 gsiEnv = rootEnv.Copy()
  56 gsiEnv.Replace(CCFLAGS=gsiCCFLAGS)
  57 
  58 env = gsiEnv
  59 Export("env")
  60 gsi = env.SConscript("gsi/SConscript", build_dir="$BUILDROOT/gsi", exports=["env", "libgambc"])
  61 
  62 # Compile the Gambit gsc executable
  63 env = gsiEnv
  64 Export("env")
  65 gsc = env.SConscript("gsc/SConscript", build_dir="$BUILDROOT/gsc", exports=["env", "libgambc"])

APLSConstruct01-top (last edited 2008-03-12 02:47:10 by localhost)