Permalink
Browse files

Radical change. Now we are more sconish, we use the standard Program …

…and SharedLibrary, chicken.py is smaller and cleaner, SConstructs are only a bit longer and it is positive.

darcs-hash:20051115055341-71b0c-53595ba0ff5ad3b6a3700d48501dfb965338bff7.gz
  • Loading branch information...
1 parent 24530ab commit 1a440e4533c32df56c9cd4df36045325e1f81065 @pupeno committed Nov 15, 2005
Showing with 150 additions and 174 deletions.
  1. +55 −152 chicken.py
  2. +35 −8 examples/sc-lap/SConstruct
  3. +14 −5 examples/sc-mfl/SConstruct
  4. +11 −4 examples/sc-mfp/SConstruct
  5. +14 −2 examples/sc-ofl/SConstruct
  6. +10 −1 examples/sc-ofp/SConstruct
  7. +11 −2 examples/sc-sap/SConstruct
View
@@ -9,160 +9,63 @@
import SCons.Tool
import os
-import os.path
-from SCons.Builder import Builder
from SCons.Node.FS import File
-from string import strip, split
+from string import strip
def generate(env):
env["CHICKEN"] = env.Detect("chicken") or "chicken"
- env["CHICKENPROFLAGS"] = ""
- env["CHICKENEXTFLAGS"] = "-dynamic -feature chicken-compile-shared -feature compiling-extension"
+ env["CHICKENFLAGS"] = "-dynamic -feature chicken-compile-shared -feature compiling-extension"
env["CHICKENREPOSITORY"] = strip(os.popen("chicken-setup -repository").read()) + "/"
+ env["CHICKENCOM"] = "$CHICKEN $SOURCE -output-file $TARGET $CHICKENFLAGS"
- # Builder to compile a .scm to a .c for programs.
- env.ChickenPro = Builder(action = "$CHICKEN $SOURCE -output-file $TARGET $CHICKENPROFLAGS",
- sufix = ".c",
- src_sufix = ".scm")
+ # The .scm to .c builders.
+ c_file, cxx_file = SCons.Tool.createCFileBuilders(env)
+ c_file.add_action(".scm", SCons.Action.Action(env["CHICKENCOM"]))
- # Builder to compile a .scm to a .c for extensions.
- env.ChickenExt = Builder(action = "$CHICKEN $SOURCE -output-file $TARGET $CHICKENEXTFLAGS",
- sufix = ".c",
- src_sufix = ".scm")
+ def ChickenSetup(target = None, source = None, env = None):
+ """ Function that works as a builder action wrapping chickenSetup. """
- def ChickenProgram(env, target, source = None, *args, **kw):
- """Pseudo builder to make a Chicken program."""
-
- # Check if we have Chiken instaled.
- conf = env.Configure()
- if not conf.CheckLibWithHeader("chicken",
- "chicken.h",
- "c",
- "C_alloc(C_SIZEOF_LIST(3));"):
- print "It seems you don't have Chicken installed or it is not"
- print "installed correctly. For more information:"
- print "http://www.call-with-current-continuation.org/"
- exit(1)
- env = conf.Finish()
-
- # If no source provided, source is what is on target and target should be generated.
- if not source:
- source = target
- if isinstance(source, list):
- target = split(source[0], ".")[0]
- else:
- target = split(source, ".")[0]
-
- # Separate Scheme sources from the rest
- schemeSources, schemeAsCSources, otherSources = groupSources(source)
-
- # Compile Scheme sources into C using Chicken (for programs).
- for t, s in zip(schemeAsCSources, schemeSources):
- env.ChickenPro(env, t, s)
-
- # Add the needed compilation flags. They are added in this way because ParseConfig adds it to the environment and the same environment might be used for both, programs and extensions, and their cflags are conflicting.
- ccflags = strip(os.popen("chicken-config -cflags").read())
- if kw.has_key("CCFLAGS"):
- kw["CCFLAGS"] += ccflags
- else:
- kw["CCFLAGS"] = ccflags
-
- # Add the needed libraries.
- env.ParseConfig("chicken-config -libs")
-
- return apply(env.Program, (target, schemeAsCSources + otherSources) + args, kw)
-
- def ChickenExtension(env, target, source = None, *args, **kw):
- """Pseudo builder to make a Chicken extension."""
-
- # If no source provided, source is what is on target and target should be generated.
- if not source:
- source = target
- if isinstance(source, list):
- target = split(source[0], ".")[0]
- else:
- target = split(source, ".")[0]
- target = [target, target + ".setup"]
-
- # Separate Scheme sources from the rest
- schemeSources, schemeAsCSources, otherSources = groupSources(source)
-
- # Compile Scheme sources into C using Chicken (for extension).
- for t, s in zip(schemeAsCSources, schemeSources):
- env.ChickenExt(env, t, s)
-
- # Add the needed compilation flags. They are added in this way because ParseConfig adds it to the environment and the same environment might be used for both, programs and extensions, and their cflags are conflicting.
- ccflags = strip(os.popen("chicken-config -cflags").read())
- if kw.has_key("CCFLAGS"):
- kw["CCFLAGS"] += ccflags
- else:
- kw["CCFLAGS"] = ccflags
-
- # Add the needed libraries.
- env.ParseConfig("chicken-config -libs")
-
- kw["SHLIBPREFIX"] = ""
- lib = apply(env.SharedLibrary, (target, schemeAsCSources + otherSources) + args, kw)
-
- if kw.has_key("DOCUMENTATION"):
- documentation = kw["DOCUMENTATION"]
+ # Do we have documentation ?
+ if env._dict.has_key("DOCUMENTATION"):
+ documentation = env._dict["DOCUMENTATION"]
else:
documentation = ""
- if kw.has_key("SYNTAX"):
- syntax = kw["SYNTAX"]
+ # Is this a syntax extension ?
+ if env._dict.has_key("SYNTAX"):
+ syntax = env._dict["SYNTAX"]
else:
syntax = False
- if kw.has_key("REQUIRES"):
- requires = kw["REQUIRES"]
+ # What should we require ?
+ if env._dict.has_key("REQUIRES"):
+ requires = env._dict["REQUIRES"]
else:
requires = []
- # Generate the .setup file.
- setup = chickenSetup(os.path.splitext(str(lib[0]))[0] + ".setup", lib[0], documentation, syntax, requires)
+ # Open the .setup file for writing.
+ setupFile = open(str(target[0]), "w")
- # Clean the .setup file when cleaning the library.
- env.Clean(lib, setup)
+ # Generate and write its content.
+ setupFile.write(chickenSetup(source, documentation, syntax, requires))
- return lib, setup
-
- # Attach the pseudo-Builders to the Environment so they can be called like a real Builder.
- env.ChickenProgram = ChickenProgram
- env.ChickenExtension = ChickenExtension
-
- def groupSources(sources):
- """ Separate the Scheme sources from the rest and generate the file names that the compiled-to-c sources are going to have. """
-
- if not isinstance(sources, list):
- sources = [sources]
+ # Close it.
+ setupFile.close()
- # Lists for the names of the scheme sources and others respectively.
- schemeSources = []
- schemeAsCSources = []
- otherSources = []
-
- # Separate sources into scheme, generated and other sources
- for s in sources:
- if os.path.splitext(s)[1] == ".scm":
- schemeSources.append(s)
- schemeAsCSources.append(os.path.splitext(s)[0]+".c")
- else:
- otherSources.append(s)
+ return None
- return schemeSources, schemeAsCSources, otherSources
+ env["BUILDERS"]["ChickenSetup"] = SCons.Builder.Builder(action = ChickenSetup,
+ suffix = ".setup")
- def chickenSetup(setup, files, documentation = None, syntax = False, requires = None):
+ def chickenSetup(files, documentation = None, syntax = False, requires = None):
""" This procedure works like a builder and it builds the .setup files.
Parameters:
- 1. env (any way to fix this ?)
- 2. Name of the .setup file to generate.
- 3. Name or list of names of the .so files that will be linked from the setup file.
+ 1. Name or list of names of the .so files that will be linked from the setup file.
Optional parameters:
documentation = Where is the HTML documentation.
syntax = Whether (true or false) this contain syntax extensions.
requires = other or list of other required extensions."""
-
+
def makeLispList(head, items, prefix = ""):
""" This procedure builds a string that resembles a Lisp list of strings.
The first parameter is the header of the Lisp-like list.
@@ -218,32 +121,32 @@ def buildPath(item):
# Close the list.
content += ")\n"
- # Write the list (being hold as a string on setup) to the file.
- setupFile = open(setup, "w")
- setupFile.write(content)
- setupFile.close()
-
- # Return an object representing the file for further handling.
- return env.File(setup)
-
- def findLibs(output, initialFlags = None):
- """ Parse the output of a config command, like chicken-config, and finds the libs and libpaths. """
- flags = {"LIBPATH":[],
- "LIBS":[]}
-
- print output
-
- if initialFlags:
- flags.update(initialFlags)
-
- output = split(output)
- for item in output:
- if item[:2] == "-L":
- flags["LIBPATH"].append(item[2:])
- elif item[:2] == "-l":
- flags["LIBS"].append(item[2:])
-
- return flags
+ # Return the generated content.
+ return content
+ def CheckChickenProgram(context):
+ """ Check if a Chicken program can be built and run. If not, try adding the libraries. """
+ context.Message("Checking for building Chicken programs... ")
+ result = context.TryRun("(display (+ 1 2))", ".scm")
+ if not result[0]:
+ context.env.ParseConfig("chicken-config -cflags -libs")
+ result = context.TryRun("(display (+ 1 2))", ".scm")
+
+ context.Result(result[0])
+ return result[0]
+
+ def CheckChickenLibrary(context):
+ """ Check if a Chicken library can be built after adding the libraries. """
+ context.Message("Checking for building Chicken libraries... ")
+ # A library compiles correctly even without the right flags (in that case, it compiles, but it can't be used. So, we just add the flags.
+ context.env.ParseConfig("chicken-config -shared -cflags -libs")
+ result = context.TryBuild(context.env.SharedLibrary, "(display (+ 1 2))", ".scm")
+ context.Result(result)
+ return result
+
+ # Export the checkers.
+ env.CheckChickenProgram = CheckChickenProgram
+ env.CheckChickenLibrary = CheckChickenLibrary
+
def exists(env):
return env.Detect(["chicken"])
View
@@ -8,18 +8,45 @@
# You should have received a copy of the GNU General Public License along with scons-chicken; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
# Create an environment including the scons-chicken tool.
-env = Environment(tools = ["default", "chicken"], toolpath=["../../"])
+lib = Environment(tools = ["default", "chicken"], toolpath=["../../"])
# The previous line is to use the non-installed scons-chicken. In your project use:
# env = Environment(tools = ["default", "chicken"])
+# Copy the lib environment before altering it for only building libraries. This new environment, prg, will be altered for building programs.
+prg = lib.Copy()
+
+# Check if a Chicken library can be built (and try to alter the environment for that porpouse).
+conf = Configure(lib, custom_tests = {"CheckChickenLibrary" : lib.CheckChickenLibrary})
+if not conf.CheckChickenLibrary():
+ print "It seems you don't have Chicken installed or it is not"
+ print "installed correctly. For more information:"
+ print "http://www.call-with-current-continuation.org/"
+ Exit(1)
+lib = conf.Finish()
+
# sc-ofl.so made of sc-ofl.scm.
-sc_lapl, sc_lapl_setup = env.ChickenExtension(env, "sc-lapl.scm")
-env.Install(env["CHICKENREPOSITORY"], sc_lapl)
-env.Install(env["CHICKENREPOSITORY"], sc_lapl_setup)
+sc_lapl = lib.SharedLibrary("sc-lapl.scm")
+lib.Install(lib["CHICKENREPOSITORY"], sc_lapl)
+
+# setup file for sc-lapl.
+sc_lapl_setup = lib.ChickenSetup(sc_lapl)
+lib.Install(lib["CHICKENREPOSITORY"], sc_lapl_setup)
+
+# Install alias
+#lib.Alias("install", env["CHICKENREPOSITORY"])
+
+
+# Check if a Chicken program can be built (and try to alter the environment for that porpouse).
+conf = Configure(prg, custom_tests = {"CheckChickenProgram" : prg.CheckChickenProgram})
+if not conf.CheckChickenProgram():
+ print "It seems you don't have Chicken installed or it is not"
+ print "installed correctly. For more information:"
+ print "http://www.call-with-current-continuation.org/"
+ Exit(1)
+prg = conf.Finish()
-sc_lapp = env.ChickenProgram(env, "sc-lapp.scm")
-env.Install("/usr/bin/", sc_lapp)
+sc_lapp = prg.Program("sc-lapp.scm")
+prg.Install("/usr/bin/", sc_lapp)
# Install alias
-env.Alias("install", env["CHICKENREPOSITORY"])
-env.Alias("install", "/usr/bin/")
+#prg.Alias("install", "/usr/bin/")
View
@@ -12,13 +12,22 @@ env = Environment(tools = ["default", "chicken"], toolpath=["../../"])
# The previous line is to use the non-installed scons-chicken. In your project use:
# env = Environment(tools = ["default", "chicken"])
+# Check if a Chicken library can be built (and try to alter the environment for that porpouse).
+conf = Configure(env, custom_tests = {"CheckChickenLibrary" : env.CheckChickenLibrary})
+if not conf.CheckChickenLibrary():
+ print "It seems you don't have Chicken installed or it is not"
+ print "installed correctly. For more information:"
+ print "http://www.call-with-current-continuation.org/"
+ Exit(1)
+env = conf.Finish()
+
# sc-mfl.so composed of sc-mfl1.scm y sc-mfl2.scm.
-sc_mfl, sc_mfl_setup = env.ChickenExtension(env,
- "sc-mfl",
- ["sc-mfl1.scm", "sc-mfl2.scm"],
- REQUIRES=["sc-ofl"])
+sc_mfl = env.SharedLibrary("sc-mfl", ["sc-mfl1.scm", "sc-mfl2.scm"])
env.Install(env['CHICKENREPOSITORY'], sc_mfl)
+
+# setup file for sc-mfl.
+sc_mfl_setup = env.ChickenSetup(sc_mfl, REQUIRES=["sc-ofl"])
env.Install(env['CHICKENREPOSITORY'], sc_mfl_setup)
# Install alias.
-env.Alias('install', env['CHICKENREPOSITORY'])
+#env.Alias('install', env['CHICKENREPOSITORY'])
View
@@ -12,11 +12,18 @@ env = Environment(tools = ["default", "chicken"], toolpath=["../../"])
# The previous line is to use the non-installed scons-chicken. In your project use:
# env = Environment(tools = ["default", "chicken"])
+# Check if a Chicken program can be built (and try to alter the environment for that porpouse).
+conf = Configure(env, custom_tests = {"CheckChickenProgram" : env.CheckChickenProgram})
+if not conf.CheckChickenProgram():
+ print "It seems you don't have Chicken installed or it is not"
+ print "installed correctly. For more information:"
+ print "http://www.call-with-current-continuation.org/"
+ Exit(1)
+env = conf.Finish()
+
# sc-mfp composed of sc-mfp1.scm y sc-mfp2.scm.
-sc_mfp = env.ChickenProgram(env,
- "sc-mfp",
- ["sc-mfp1.scm", "sc-mfp2.scm"])
+sc_mfp = env.Program("sc-mfp", ["sc-mfp1.scm", "sc-mfp2.scm"])
env.Install("/usr/bin", sc_mfp)
# Install alias.
-env.Alias("install", "/usr/bin")
+#env.Alias("install", "/usr/bin")
View
@@ -12,10 +12,22 @@ env = Environment(tools = ["default", "chicken"], toolpath=["../../"])
# The previous line is to use the non-installed scons-chicken. In your project use:
# env = Environment(tools = ["default", "chicken"])
+# Check if a Chicken library can be built (and try to alter the environment for that porpouse).
+conf = Configure(env, custom_tests = {"CheckChickenLibrary" : env.CheckChickenLibrary})
+if not conf.CheckChickenLibrary():
+ print "It seems you don't have Chicken installed or it is not"
+ print "installed correctly. For more information:"
+ print "http://www.call-with-current-continuation.org/"
+ Exit(1)
+env = conf.Finish()
+
# sc-ofl.so made of sc-ofl.scm.
-sc_ofl, sc_ofl_setup = env.ChickenExtension(env, "sc-ofl.scm")
+sc_ofl = env.SharedLibrary("sc-ofl.scm", SHLIBPREFIX="")
env.Install(env['CHICKENREPOSITORY'], sc_ofl)
+
+# Setup file for sc-ofl.
+sc_ofl_setup = env.ChickenSetup(sc_ofl)
env.Install(env['CHICKENREPOSITORY'], sc_ofl_setup)
# Install alias
-env.Alias('install', env['CHICKENREPOSITORY'])
+#env.Alias('install', env['CHICKENREPOSITORY'])
View
@@ -12,8 +12,17 @@ env = Environment(tools = ["default", "chicken"], toolpath=["../../"])
# The previous line is to use the non-installed scons-chicken. In your project use:
# env = Environment(tools = ["default", "chicken"])
+# Check if a Chicken program can be built (and try to alter the environment for that porpouse).
+conf = Configure(env, custom_tests = {"CheckChickenProgram" : env.CheckChickenProgram})
+if not conf.CheckChickenProgram():
+ print "It seems you don't have Chicken installed or it is not"
+ print "installed correctly. For more information:"
+ print "http://www.call-with-current-continuation.org/"
+ Exit(1)
+env = conf.Finish()
+
# sc-ofp (executable binary) made of sc-ofp.scm.
-sc_ofp = env.ChickenProgram(env, "sc-ofp.scm")
+sc_ofp = env.Program("sc-ofp.scm")
env.Install('/usr/bin/', sc_ofp)
# Install alias.
Oops, something went wrong.

0 comments on commit 1a440e4

Please sign in to comment.