Bring CVS back in sync.
[scons.git] / SConstruct
index 9b9ce9543c59445f1213a187a70e9d388aa37524..7dfc9354dcbe97ae4a0ee0fc8913015c289441c8 100644 (file)
@@ -4,8 +4,10 @@
 # See the README file for an overview of how SCons is built and tested.
 #
 
+copyright_years = '2001, 2002, 2003, 2004'
+
 #
-# Copyright (c) 2001, 2002 Steven Knight
+# __COPYRIGHT__
 #
 # Permission is hereby granted, free of charge, to any person obtaining
 # a copy of this software and associated documentation files (the
@@ -30,6 +32,7 @@
 import distutils.util
 import os
 import os.path
+import re
 import socket
 import stat
 import string
@@ -37,10 +40,13 @@ import sys
 import time
 
 project = 'scons'
-default_version = '0.10'
+default_version = '0.96'
+copyright = "Copyright (c) %s The SCons Foundation" % copyright_years
 
 Default('.')
 
+SConsignFile()
+
 #
 # An internal "whereis" routine to figure out if a given program
 # is available on this system.
@@ -79,7 +85,7 @@ try:
     date = ARGUMENTS['date']
 except:
     date = time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(time.time()))
-    
+
 if ARGUMENTS.has_key('developer'):
     developer = ARGUMENTS['developer']
 elif os.environ.has_key('USERNAME'):
@@ -101,13 +107,14 @@ elif aesub:
 else:
     revision = default_version
 
-a = string.split(revision, '.')
-arr = [a[0]]
-for s in a[1:]:
-    if len(s) == 1:
-        s = '0' + s
-    arr.append(s)
-revision = string.join(arr, '.')
+# This is old code that adds an initial "0" to revision numbers < 10.
+#a = string.split(revision, '.')
+#arr = [a[0]]
+#for s in a[1:]:
+#    if len(s) == 1:
+#        s = '0' + s
+#    arr.append(s)
+#revision = string.join(arr, '.')
 
 # Here's how we'd turn the calculated $revision into our package $version.
 # This makes it difficult to coordinate with other files (debian/changelog
@@ -139,12 +146,10 @@ python_ver = sys.version[0:3]
 platform = distutils.util.get_platform()
 
 ENV = { 'PATH' : os.environ['PATH'] }
-for key in ['AEGIS_PROJECT', 'PYTHONPATH']:
+for key in ['AEGIS_PROJECT', 'LOGNAME', 'PYTHONPATH']:
     if os.environ.has_key(key):
         ENV[key] = os.environ[key]
 
-lib_project = os.path.join("lib", project)
-
 cwd_build = os.path.join(os.getcwd(), "build")
 
 test_deb_dir          = os.path.join(cwd_build, "test-deb")
@@ -161,16 +166,16 @@ unpack_zip_dir        = os.path.join(cwd_build, "unpack-zip")
 
 if platform == "win32":
     tar_hflag = ''
-    python_project_subinst_dir = None
+    python_project_subinst_dir = os.path.join("Lib", "site-packages", project)
     project_script_subinst_dir = 'Scripts'
 else:
     tar_hflag = 'h'
-    python_project_subinst_dir = lib_project
+    python_project_subinst_dir = os.path.join("lib", project)
     project_script_subinst_dir = 'bin'
 
 
 zcat = 'gzip -d -c'
-    
+
 #
 # Figure out if we can handle .zip files.
 #
@@ -218,42 +223,73 @@ except:
 
 def SCons_revision(target, source, env):
     """Interpolate specific values from the environment into a file.
-    
+
     This is used to copy files into a tree that gets packaged up
     into the source file package.
     """
     t = str(target[0])
     s = source[0].rstr()
-    # Note:  We don't use $VERSION from the environment so that
-    # this routine will change when the version number changes
-    # and things will get rebuilt properly.
-    global version
-    print "SCons_revision() < %s > %s" % (s, t)
-    inf = open(s, 'rb')
-    outf = open(t, 'wb')
-    for line in inf.readlines():
-        # Note:  We construct the __*__ substitution strings here
-        # so that they don't get replaced when this file gets
-        # copied into the tree for packaging.
-        line = string.replace(line, '__BUILD'     + '__', env['BUILD'])
-        line = string.replace(line, '__BUILDSYS'  + '__', env['BUILDSYS'])
-        line = string.replace(line, '__DATE'      + '__', env['DATE'])
-        line = string.replace(line, '__DEVELOPER' + '__', env['DEVELOPER'])
-        line = string.replace(line, '__FILE'      + '__', s)
-        line = string.replace(line, '__REVISION'  + '__', env['REVISION'])
-        line = string.replace(line, '__VERSION'   + '__',  version)
-        outf.write(line)
-    inf.close()
-    outf.close()
+    contents = open(s, 'rb').read()
+    # Note:  We construct the __*__ substitution strings here
+    # so that they don't get replaced when this file gets
+    # copied into the tree for packaging.
+    contents = string.replace(contents, '__BUILD'     + '__', env['BUILD'])
+    contents = string.replace(contents, '__BUILDSYS'  + '__', env['BUILDSYS'])
+    contents = string.replace(contents, '__COPYRIGHT' + '__', env['COPYRIGHT'])
+    contents = string.replace(contents, '__DATE'      + '__', env['DATE'])
+    contents = string.replace(contents, '__DEVELOPER' + '__', env['DEVELOPER'])
+    contents = string.replace(contents, '__FILE'      + '__', str(source[0]))
+    contents = string.replace(contents, '__REVISION'  + '__', env['REVISION'])
+    contents = string.replace(contents, '__VERSION'   + '__', env['VERSION'])
+    contents = string.replace(contents, '__NULL'      + '__', '')
+    open(t, 'wb').write(contents)
     os.chmod(t, os.stat(s)[0])
 
-revbuilder = Builder(action = SCons_revision)
+revbuilder = Builder(action = Action(SCons_revision,
+                                     varlist=['COPYRIGHT', 'VERSION']))
+
+def soelim(target, source, env):
+    """
+    Interpolate files included in [gnt]roff source files using the
+    .so directive.
+
+    This behaves somewhat like the soelim(1) wrapper around groff, but
+    makes us independent of whether the actual underlying implementation
+    includes an soelim() command or the corresponding command-line option
+    to groff(1).  The key behavioral difference is that this doesn't
+    recursively include .so files from the include file.  Not yet, anyway.
+    """
+    t = str(target[0])
+    s = str(source[0])
+    dir, f = os.path.split(s)
+    tfp = open(t, 'w')
+    sfp = open(s, 'r')
+    for line in sfp.readlines():
+        if line[:4] in ['.so ', "'so "]:
+            sofile = os.path.join(dir, line[4:-1])
+            tfp.write(open(sofile, 'r').read())
+        else:
+            tfp.write(line)
+    sfp.close()
+    tfp.close()
+
+def soscan(node, env, path):
+    c = node.get_contents()
+    return re.compile(r"^[\.']so\s+(\S+)", re.M).findall(c)
+
+soelimbuilder = Builder(action = Action(soelim),
+                        source_scanner = Scanner(soscan))
+
+# When copying local files from a Repository (Aegis),
+# just make copies, don't symlink them.
+SetOption('duplicate', 'copy')
 
 env = Environment(
                    ENV                 = ENV,
+
                    BUILD               = build_id,
                    BUILDSYS            = build_system,
+                   COPYRIGHT           = copyright,
                    DATE                = date,
                    DEVELOPER           = developer,
                    REVISION            = revision,
@@ -282,20 +318,24 @@ env = Environment(
                    UNPACK_TAR_GZ_DIR   = unpack_tar_gz_dir,
                    UNPACK_ZIP_DIR      = unpack_zip_dir,
 
-                   BUILDERS            = { 'SCons_revision' : revbuilder },
+                   BUILDERS            = { 'SCons_revision' : revbuilder,
+                                           'SOElim' : soelimbuilder },
 
-                   PYTHON              = sys.executable
+                   PYTHON              = sys.executable,
+                   PYTHONFLAGS         = '-tt',
                  )
 
+Version_values = [Value(version), Value(build_id)]
+
 #
 # Define SCons packages.
 #
 # In the original, more complicated packaging scheme, we were going
 # to have separate packages for:
 #
-#      python-scons    only the build engine
-#      scons-script    only the script
-#      scons           the script plus the build engine
+#       python-scons    only the build engine
+#       scons-script    only the script
+#       scons           the script plus the build engine
 #
 # We're now only delivering a single "scons" package, but this is still
 # "built" as two sub-packages (the build engine and the script), so
@@ -307,6 +347,7 @@ python_scons = {
         'pkg'           : 'python-' + project,
         'src_subdir'    : 'engine',
         'inst_subdir'   : os.path.join('lib', 'python1.5', 'site-packages'),
+        'rpm_dir'       : '/usr/lib/scons',
 
         'debian_deps'   : [
                             'debian/changelog',
@@ -328,6 +369,12 @@ python_scons = {
         'filemap'       : {
                             'LICENSE.txt' : '../LICENSE.txt'
                           },
+
+        'buildermap'    : {},
+
+        'explicit_deps' : {
+                            'SCons/__init__.py' : Version_values,
+                          },
 }
 
 #
@@ -341,7 +388,7 @@ python_scons = {
 #python2_scons = {
 #        'pkg'          : 'python2-' + project,
 #        'src_subdir'   : 'engine',
-#        'inst_subdir'  : os.path.join('lib', 'python2.1', 'site-packages'),
+#        'inst_subdir'  : os.path.join('lib', 'python2.2', 'site-packages'),
 #
 #        'debian_deps'  : [
 #                            'debian/changelog',
@@ -363,6 +410,7 @@ python_scons = {
 #        'filemap'      : {
 #                            'LICENSE.txt' : '../LICENSE.txt',
 #                          },
+#        'buildermap'    : {},
 #}
 #
 
@@ -370,6 +418,7 @@ scons_script = {
         'pkg'           : project + '-script',
         'src_subdir'    : 'script',
         'inst_subdir'   : 'bin',
+        'rpm_dir'       : '/usr/bin',
 
         'debian_deps'   : [
                             'debian/changelog',
@@ -390,15 +439,28 @@ scons_script = {
                           ],
 
         'filemap'       : {
-                            'LICENSE.txt' : '../LICENSE.txt',
-                            'scons'       : 'scons.py',
-                           }
+                            'LICENSE.txt'       : '../LICENSE.txt',
+                            'scons'             : 'scons.py',
+                            'sconsign'          : 'sconsign.py',
+                           },
+
+        'buildermap'    : {},
+
+        'extra_rpm_files' : [
+                            'scons-' + version,
+                            'sconsign-' + version,
+                          ],
+
+        'explicit_deps' : {
+                            'scons'       : Version_values,
+                            'sconsign'    : Version_values,
+                          },
 }
 
 scons = {
         'pkg'           : project,
 
-        'debian_deps'   : [ 
+        'debian_deps'   : [
                             'debian/changelog',
                             'debian/control',
                             'debian/copyright',
@@ -409,30 +471,39 @@ scons = {
                             'debian/rules',
                           ],
 
-        'files'         : [ 
+        'files'         : [
                             'CHANGES.txt',
                             'LICENSE.txt',
                             'README.txt',
                             'RELEASE.txt',
                             'os_spawnv_fix.diff',
                             'scons.1',
+                            'sconsign.1',
                             'script/scons.bat',
                             'setup.cfg',
                             'setup.py',
                           ],
 
         'filemap'       : {
-                            'scons.1' : '../doc/man/scons.1',
+                            'scons.1' : '../build/doc/man/scons.1',
+                            'sconsign.1' : '../build/doc/man/sconsign.1',
                           },
 
-        'subpkgs'      : [ python_scons, scons_script ],
+        'buildermap'    : {
+                            'scons.1' : env.SOElim,
+                            'sconsign.1' : env.SOElim,
+                          },
 
-        'subinst_dirs' : {
+        'subpkgs'       : [ python_scons, scons_script ],
+
+        'subinst_dirs'  : {
                              'python-' + project : python_project_subinst_dir,
                              project + '-script' : project_script_subinst_dir,
                            },
 }
 
+scripts = ['scons', 'sconsign']
+
 src_deps = []
 src_files = []
 
@@ -468,9 +539,9 @@ for p in [ scons ]:
     # to the directory in which setup.py exists.
     #
     setup_py = os.path.join(build, 'setup.py')
-    env.Update(PKG = pkg,
-               PKG_VERSION = pkg_version,
-               SETUP_PY = setup_py)
+    env.Replace(PKG = pkg,
+                PKG_VERSION = pkg_version,
+                SETUP_PY = setup_py)
     Local(setup_py)
 
     #
@@ -484,6 +555,7 @@ for p in [ scons ]:
                     open(manifest_in).readlines())
     raw_files = src_files[:]
     dst_files = src_files[:]
+    rpm_files = []
 
     MANIFEST_in_list = []
 
@@ -499,17 +571,26 @@ for p in [ scons ]:
             isubdir = p['subinst_dirs'][sp['pkg']]
             MANIFEST_in = File(os.path.join(src, ssubdir, 'MANIFEST.in')).rstr()
             MANIFEST_in_list.append(MANIFEST_in)
-            f = map(lambda x: x[:-1], open(MANIFEST_in).readlines())
-            raw_files.extend(f)
-            src_files.extend(map(lambda x, s=ssubdir: os.path.join(s, x), f))
-            if isubdir:
-                f = map(lambda x, i=isubdir: os.path.join(i, x), f)
-            dst_files.extend(f)
-            for k in sp['filemap'].keys():
-                f = sp['filemap'][k]
+            files = map(lambda x: x[:-1], open(MANIFEST_in).readlines())
+            raw_files.extend(files)
+            src_files.extend(map(lambda x, s=ssubdir: os.path.join(s, x), files))
+            for f in files:
+                r = os.path.join(sp['rpm_dir'], f)
+                rpm_files.append(r)
+                if f[-3:] == ".py":
+                    rpm_files.append(r + 'c')
+            for f in sp.get('extra_rpm_files', []):
+                r = os.path.join(sp['rpm_dir'], f)
+                rpm_files.append(r)
+            files = map(lambda x, i=isubdir: os.path.join(i, x), files)
+            dst_files.extend(files)
+            for k, f in sp['filemap'].items():
                 if f:
-                    k = os.path.join(sp['src_subdir'], k)
-                    p['filemap'][k] = os.path.join(sp['src_subdir'], f)
+                    k = os.path.join(ssubdir, k)
+                    p['filemap'][k] = os.path.join(ssubdir, f)
+            for f, deps in sp['explicit_deps'].items():
+                f = os.path.join(build, ssubdir, f)
+                env.Depends(f, deps)
 
     #
     # Now that we have the "normal" source files, add those files
@@ -525,7 +606,9 @@ for p in [ scons ]:
     #
     for b in src_files:
         s = p['filemap'].get(b, b)
-        env.SCons_revision(os.path.join(build, b), os.path.join(src, s))
+        builder = p['buildermap'].get(b, env.SCons_revision)
+        x = builder(os.path.join(build, b), os.path.join(src, s))
+        Local(x)
 
     #
     # NOW, finally, we can create the MANIFEST, which we do
@@ -538,7 +621,7 @@ for p in [ scons ]:
 
     def write_src_files(target, source, **kw):
         global src_files
-       src_files.sort()
+        src_files.sort()
         f = open(str(target[0]), 'wb')
         for file in src_files:
             f.write(file + "\n")
@@ -575,7 +658,7 @@ for p in [ scons ]:
         #
         # We'd like to replace the last three lines with the following:
         #
-        #      tar zxf $SOURCES -C $UNPACK_TAR_GZ_DIR
+        #       tar zxf $SOURCES -C $UNPACK_TAR_GZ_DIR
         #
         # but that gives heartburn to Cygwin's tar, so work around it
         # with separate zcat-tar-rm commands.
@@ -584,12 +667,12 @@ for p in [ scons ]:
                                          os.path.join(u, pv, x),
                                   src_files)
         env.Command(unpack_tar_gz_files, tar_gz, [
-                    "rm -rf %s" % os.path.join(unpack_tar_gz_dir, pkg_version),
+                    Delete(os.path.join(unpack_tar_gz_dir, pkg_version)),
                     "$ZCAT $SOURCES > .temp",
                     "tar xf .temp -C $UNPACK_TAR_GZ_DIR",
-                    "rm -f .temp",
+                    Delete(".temp"),
         ])
-    
+
         #
         # Run setup.py in the unpacked subdirectory to "install" everything
         # into our build/test subdirectory.  The runtest.py script will set
@@ -605,12 +688,42 @@ for p in [ scons ]:
         #
         dfiles = map(lambda x, d=test_tar_gz_dir: os.path.join(d, x), dst_files)
         env.Command(dfiles, unpack_tar_gz_files, [
-            "rm -rf %s" % os.path.join(unpack_tar_gz_dir, pkg_version, 'build'),
-            "rm -rf $TEST_TAR_GZ_DIR",
-            "$PYTHON %s install --prefix=$TEST_TAR_GZ_DIR" % \
+            Delete(os.path.join(unpack_tar_gz_dir, pkg_version, 'build')),
+            Delete("$TEST_TAR_GZ_DIR"),
+            '$PYTHON $PYTHONFLAGS "%s" install "--prefix=$TEST_TAR_GZ_DIR" --standalone-lib' % \
                 os.path.join(unpack_tar_gz_dir, pkg_version, 'setup.py'),
         ])
 
+        #
+        # Generate portage files for submission to Gentoo Linux.
+        #
+        gentoo = os.path.join('build', 'gentoo')
+        ebuild = os.path.join(gentoo, 'scons-%s.ebuild' % version)
+        digest = os.path.join(gentoo, 'files', 'digest-scons-%s' % version)
+        env.Command(ebuild, os.path.join('gentoo', 'scons.ebuild.in'), SCons_revision)
+        def Digestify(target, source, env):
+            import md5
+            def hexdigest(s):
+                """Return a signature as a string of hex characters.
+                """
+                # NOTE:  This routine is a method in the Python 2.0 interface
+                # of the native md5 module, but we want SCons to operate all
+                # the way back to at least Python 1.5.2, which doesn't have it.
+                h = string.hexdigits
+                r = ''
+                for c in s:
+                    i = ord(c)
+                    r = r + h[(i >> 4) & 0xF] + h[i & 0xF]
+                return r
+            src = source[0].rfile()
+            contents = open(str(src)).read()
+            sig = hexdigest(md5.new(contents).digest())
+            bytes = os.stat(str(src))[6]
+            open(str(target[0]), 'w').write("MD5 %s %s %d\n" % (sig,
+                                                                src.name,
+                                                                bytes))
+        env.Command(digest, tar_gz, Digestify)
+
     if zipit:
 
         distutils_formats.append('zip')
@@ -628,7 +741,10 @@ for p in [ scons ]:
                                       os.path.join(u, pv, x),
                                src_files)
 
-        env.Command(unpack_zip_files, zip, unzipit)
+        env.Command(unpack_zip_files, zip, [
+            Delete(os.path.join(unpack_zip_dir, pkg_version)),
+            unzipit,
+        ])
 
         #
         # Run setup.py in the unpacked subdirectory to "install" everything
@@ -645,9 +761,9 @@ for p in [ scons ]:
         #
         dfiles = map(lambda x, d=test_zip_dir: os.path.join(d, x), dst_files)
         env.Command(dfiles, unpack_zip_files, [
-            "rm -rf %s" % os.path.join(unpack_zip_dir, pkg_version, 'build'),
-            "rm -rf $TEST_ZIP_DIR",
-            "$PYTHON %s install --prefix=$TEST_ZIP_DIR" % \
+            Delete(os.path.join(unpack_zip_dir, pkg_version, 'build')),
+            Delete("$TEST_ZIP_DIR"),
+            '$PYTHON $PYTHONFLAGS "%s" install "--prefix=$TEST_ZIP_DIR" --standalone-lib' % \
                 os.path.join(unpack_zip_dir, pkg_version, 'setup.py'),
         ])
 
@@ -655,22 +771,42 @@ for p in [ scons ]:
         topdir = os.path.join(os.getcwd(), build, 'build',
                               'bdist.' + platform, 'rpm')
 
-       BUILDdir = os.path.join(topdir, 'BUILD', pkg + '-' + version)
-       RPMSdir = os.path.join(topdir, 'RPMS', 'noarch')
-       SOURCESdir = os.path.join(topdir, 'SOURCES')
-       SPECSdir = os.path.join(topdir, 'SPECS')
-       SRPMSdir = os.path.join(topdir, 'SRPMS')
+        buildroot = os.path.join(os.getcwd(), 'build', 'rpm-buildroot')
+
+        BUILDdir = os.path.join(topdir, 'BUILD', pkg + '-' + version)
+        RPMSdir = os.path.join(topdir, 'RPMS', 'noarch')
+        SOURCESdir = os.path.join(topdir, 'SOURCES')
+        SPECSdir = os.path.join(topdir, 'SPECS')
+        SRPMSdir = os.path.join(topdir, 'SRPMS')
 
+        specfile_in = os.path.join('rpm', "%s.spec.in" % pkg)
         specfile = os.path.join(SPECSdir, "%s-1.spec" % pkg_version)
         sourcefile = os.path.join(SOURCESdir, "%s.tar.gz" % pkg_version);
         noarch_rpm = os.path.join(RPMSdir, "%s-1.noarch.rpm" % pkg_version)
         src_rpm = os.path.join(SRPMSdir, "%s-1.src.rpm" % pkg_version)
 
-        env.InstallAs(specfile, os.path.join('rpm', "%s.spec" % pkg))
+        def spec_function(target, source, env):
+            """Generate the RPM .spec file from the template file.
+
+            This fills in the %files portion of the .spec file with a
+            list generated from our MANIFEST(s), so we don't have to
+            maintain multiple lists.
+            """
+            c = open(str(source[0]), 'rb').read()
+            c = string.replace(c, '__RPM_FILES__', env['RPM_FILES'])
+            open(str(target[0]), 'wb').write(c)
+
+        rpm_files.sort()
+        rpm_files_str = string.join(rpm_files, "\n") + "\n"
+        rpm_spec_env = env.Copy(RPM_FILES = rpm_files_str)
+        rpm_spec_action = Action(spec_function, varlist=['RPM_FILES'])
+        rpm_spec_env.Command(specfile, specfile_in, rpm_spec_action)
+
         env.InstallAs(sourcefile, tar_gz)
+        Local(sourcefile)
 
         targets = [ noarch_rpm, src_rpm ]
-        cmd = "$RPMBUILD --define '_topdir $(%s$)' -ba $SOURCES" % topdir
+        cmd = "$RPMBUILD --define '_topdir $(%s$)' --buildroot %s -ba $SOURCES" % (topdir, buildroot)
         if not os.path.isdir(BUILDdir):
             cmd = ("$( mkdir -p %s; $)" % BUILDdir) + cmd
         env.Command(targets, specfile, cmd)
@@ -697,7 +833,7 @@ for p in [ scons ]:
                     ])
 
         old = os.path.join('lib', 'scons', '')
-        new = os.path.join('lib', 'python2.1', 'site-packages', '')
+        new = os.path.join('lib', 'python2.2', 'site-packages', '')
         def xxx(s, old=old, new=new):
             if s[:len(old)] == old:
                 s = new + s[len(old):]
@@ -708,26 +844,27 @@ for p in [ scons ]:
                     deb,
                     "dpkg --fsys-tarfile $SOURCES | (cd $TEST_DEB_DIR && tar -xf -)")
 
+
     #
     # Use the Python distutils to generate the appropriate packages.
     #
     commands = [
-        "rm -rf %s" % os.path.join(build, 'build', 'lib'),
-        "rm -rf %s" % os.path.join(build, 'build', 'scripts'),
+        Delete(os.path.join(build, 'build', 'lib')),
+        Delete(os.path.join(build, 'build', 'scripts')),
     ]
 
     if distutils_formats:
-        commands.append("rm -rf %s" % os.path.join(build,
-                                                   'build',
-                                                   'bdist.' + platform,
-                                                   'dumb'))
+        commands.append(Delete(os.path.join(build,
+                                            'build',
+                                            'bdist.' + platform,
+                                            'dumb')))
         for format in distutils_formats:
-            commands.append("$PYTHON $SETUP_PY bdist_dumb -f %s" % format)
+            commands.append("$PYTHON $PYTHONFLAGS $SETUP_PY bdist_dumb -f %s" % format)
 
-        commands.append("$PYTHON $SETUP_PY sdist --formats=%s" %  \
+        commands.append("$PYTHON $PYTHONFLAGS $SETUP_PY sdist --formats=%s" %  \
                             string.join(distutils_formats, ','))
 
-    commands.append("$PYTHON $SETUP_PY bdist_wininst")
+    commands.append("$PYTHON $PYTHONFLAGS $SETUP_PY bdist_wininst")
 
     env.Command(distutils_targets, build_src_files, commands)
 
@@ -746,15 +883,20 @@ for p in [ scons ]:
     local_zip = os.path.join('build', 'dist', "%s.zip" % s_l_v)
 
     commands = [
-        "rm -rf %s" % local,
-        "$PYTHON $SETUP_PY install --install-script=%s --install-lib=%s" % \
+        Delete(local),
+        '$PYTHON $PYTHONFLAGS $SETUP_PY install "--install-script=%s" "--install-lib=%s" --no-install-man --no-compile --standalone-lib --no-version-script' % \
                                                 (cwd_local, cwd_local_slv),
-        "mv %s/scons %s/scons.py" % (local, local),
     ]
 
-    rf = filter(lambda x: x != "scons", raw_files)
+    for script in scripts:
+        #commands.append("mv %s/%s %s/%s.py" % (local, script, local, script))
+        local_script = os.path.join(local, script)
+        commands.append(Move(local_script + '.py', local_script))
+
+    rf = filter(lambda x: not x in scripts, raw_files)
     rf = map(lambda x, slv=s_l_v: os.path.join(slv, x), rf)
-    rf.append("scons.py")
+    for script in scripts:
+        rf.append("%s.py" % script)
     local_targets = map(lambda x, s=local: os.path.join(s, x), rf)
 
     env.Command(local_targets, build_src_files, commands)
@@ -775,25 +917,25 @@ for p in [ scons ]:
         unpack_targets = map(lambda x, d=test_local_tar_gz_dir:
                                     os.path.join(d, x),
                              rf)
-        commands = ["rm -rf %s" % test_local_tar_gz_dir,
-                    "mkdir %s" % test_local_tar_gz_dir,
+        commands = [Delete(test_local_tar_gz_dir),
+                    Mkdir(test_local_tar_gz_dir),
                     "cd %s && tar xzf $( ${SOURCE.abspath} $)" % test_local_tar_gz_dir]
 
         env.Command(unpack_targets, local_tar_gz, commands)
 
     if zipit:
-        zipenv = env.Copy(CD = local, PSV = '.')
-        zipenv.Command(local_zip, local_targets, zipit)
+        env.Command(local_zip, local_targets, zipit,
+                    CD = local, PSV = '.')
 
         unpack_targets = map(lambda x, d=test_local_zip_dir:
                                     os.path.join(d, x),
                              rf)
-        commands = ["rm -rf %s" % test_local_zip_dir,
-                    "mkdir %s" % test_local_zip_dir,
+        commands = [Delete(test_local_zip_dir),
+                    Mkdir(test_local_zip_dir),
                     unzipit]
 
-        zipenv = env.Copy(UNPACK_ZIP_DIR = test_local_zip_dir)
-        zipenv.Command(unpack_targets, local_zip, unzipit)
+        env.Command(unpack_targets, local_zip, unzipit,
+                    UNPACK_ZIP_DIR = test_local_zip_dir)
 
     #
     # And, lastly, install the appropriate packages in the
@@ -812,11 +954,9 @@ SConscript('etc/SConscript')
 #
 # Documentation.
 #
-BuildDir('build/doc', 'doc')
-
 Export('env', 'whereis')
 
-SConscript('build/doc/SConscript')
+SConscript('doc/SConscript')
 
 #
 # If we're running in the actual Aegis project, pack up a complete
@@ -834,14 +974,19 @@ if change:
 
     cmd = "aegis -list -terse pf 2>/dev/null"
     pf = map(lambda x: x[:-1], os.popen(cmd, "r").readlines())
-    cmd = "aegis -list -terse cf 2>/dev/null"
+    cmd = "aegis -list -terse -c %s cf 2>/dev/null" % change
     cf = map(lambda x: x[:-1], os.popen(cmd, "r").readlines())
     u = {}
     for f in pf + cf:
         u[f] = 1
     for f in df:
-        del u[f]
-    sfiles = filter(lambda x: x[-9:] != '.aeignore' and x[-9:] != '.sconsign',
+        try:
+            del u[f]
+        except KeyError:
+            pass
+    sfiles = filter(lambda x: x[-9:] != '.aeignore' and
+                              x[-9:] != '.sconsign' and
+                              x[-10:] != '.cvsignore',
                     u.keys())
 
     if sfiles:
@@ -861,10 +1006,9 @@ if change:
 
         b_ps_files = map(lambda x, d=b_ps: os.path.join(d, x), sfiles)
         cmds = [
-            "rm -rf %s" % b_psv,
-            "cp -rp %s %s" % (b_ps, b_psv),
-            "find %s -name .sconsign -exec rm {} \\;" % b_psv,
-            "touch $TARGET",
+            Delete(b_psv),
+            Copy(b_psv, b_ps),
+            Touch("$TARGET"),
         ]
 
         env.Command(b_psv_stamp, src_deps + b_ps_files, cmds)
@@ -875,28 +1019,28 @@ if change:
 
             env.Command(src_tar_gz, b_psv_stamp,
                         "tar cz${TAR_HFLAG} -f $TARGET -C build %s" % psv)
-    
+
             #
             # Unpack the archive into build/unpack/scons-{version}.
             #
             unpack_tar_gz_files = map(lambda x, u=unpack_tar_gz_dir, psv=psv:
                                              os.path.join(u, psv, x),
                                       sfiles)
-    
+
             #
             # We'd like to replace the last three lines with the following:
             #
-            #  tar zxf $SOURCES -C $UNPACK_TAR_GZ_DIR
+            #   tar zxf $SOURCES -C $UNPACK_TAR_GZ_DIR
             #
             # but that gives heartburn to Cygwin's tar, so work around it
             # with separate zcat-tar-rm commands.
             env.Command(unpack_tar_gz_files, src_tar_gz, [
-                "rm -rf %s" % os.path.join(unpack_tar_gz_dir, psv),
+                Delete(os.path.join(unpack_tar_gz_dir, psv)),
                 "$ZCAT $SOURCES > .temp",
                 "tar xf .temp -C $UNPACK_TAR_GZ_DIR",
-                "rm -f .temp",
+                Delete(".temp"),
             ])
-    
+
             #
             # Run setup.py in the unpacked subdirectory to "install" everything
             # into our build/test subdirectory.  The runtest.py script will set
@@ -912,42 +1056,47 @@ if change:
             #
             dfiles = map(lambda x, d=test_src_tar_gz_dir: os.path.join(d, x),
                             dst_files)
-            ENV = env.Dictionary('ENV')
-            ENV['SCONS_LIB_DIR'] = os.path.join(unpack_tar_gz_dir, psv, 'src', 'engine')
+            scons_lib_dir = os.path.join(unpack_tar_gz_dir, psv, 'src', 'engine')
+            ENV = env.Dictionary('ENV').copy()
+            ENV['SCONS_LIB_DIR'] = scons_lib_dir
             ENV['USERNAME'] = developer
-            env.Copy(ENV = ENV).Command(dfiles, unpack_tar_gz_files, [
-                "rm -rf %s" % os.path.join(unpack_tar_gz_dir,
-                                           psv,
-                                           'build',
-                                           'scons',
-                                           'build'),
-                "rm -rf $TEST_SRC_TAR_GZ_DIR",
-                "cd %s && $PYTHON %s %s" % \
+            env.Command(dfiles, unpack_tar_gz_files,
+                [
+                Delete(os.path.join(unpack_tar_gz_dir,
+                                    psv,
+                                    'build',
+                                    'scons',
+                                    'build')),
+                Delete("$TEST_SRC_TAR_GZ_DIR"),
+                'cd "%s" && $PYTHON $PYTHONFLAGS "%s" "%s"' % \
                     (os.path.join(unpack_tar_gz_dir, psv),
                      os.path.join('src', 'script', 'scons.py'),
                      os.path.join('build', 'scons')),
-                "$PYTHON %s install --prefix=$TEST_SRC_TAR_GZ_DIR" % \
+                '$PYTHON $PYTHONFLAGS "%s" install "--prefix=$TEST_SRC_TAR_GZ_DIR" --standalone-lib' % \
                     os.path.join(unpack_tar_gz_dir,
                                  psv,
                                  'build',
                                  'scons',
                                  'setup.py'),
-            ])
+                ],
+                ENV = ENV)
 
         if zipit:
 
-            zipenv = env.Copy(CD = 'build', PSV = psv)
-            zipenv.Command(src_zip, b_psv_stamp, zipit)
-    
+            env.Command(src_zip, b_psv_stamp, zipit, CD = 'build', PSV = psv)
+
             #
             # Unpack the archive into build/unpack/scons-{version}.
             #
             unpack_zip_files = map(lambda x, u=unpack_zip_dir, psv=psv:
                                              os.path.join(u, psv, x),
                                       sfiles)
-    
-            env.Command(unpack_zip_files, src_zip, unzipit)
-    
+
+            env.Command(unpack_zip_files, src_zip, [
+                Delete(os.path.join(unpack_zip_dir, psv)),
+                unzipit
+            ])
+
             #
             # Run setup.py in the unpacked subdirectory to "install" everything
             # into our build/test subdirectory.  The runtest.py script will set
@@ -963,24 +1112,27 @@ if change:
             #
             dfiles = map(lambda x, d=test_src_zip_dir: os.path.join(d, x),
                             dst_files)
-            ENV = env.Dictionary('ENV')
-            ENV['SCONS_LIB_DIR'] = os.path.join(unpack_zip_dir, psv, 'src', 'engine')
+            scons_lib_dir = os.path.join(unpack_zip_dir, psv, 'src', 'engine')
+            ENV = env.Dictionary('ENV').copy()
+            ENV['SCONS_LIB_DIR'] = scons_lib_dir
             ENV['USERNAME'] = developer
-            env.Copy(ENV = ENV).Command(dfiles, unpack_zip_files, [
-                "rm -rf %s" % os.path.join(unpack_zip_dir,
-                                           psv,
-                                           'build',
-                                           'scons',
-                                           'build'),
-                "rm -rf $TEST_SRC_ZIP_DIR",
-                "cd %s && $PYTHON %s %s" % \
+            env.Command(dfiles, unpack_zip_files,
+                [
+                Delete(os.path.join(unpack_zip_dir,
+                                    psv,
+                                    'build',
+                                    'scons',
+                                    'build')),
+                Delete("$TEST_SRC_ZIP_DIR"),
+                'cd "%s" && $PYTHON $PYTHONFLAGS "%s" "%s"' % \
                     (os.path.join(unpack_zip_dir, psv),
                      os.path.join('src', 'script', 'scons.py'),
                      os.path.join('build', 'scons')),
-                "$PYTHON %s install --prefix=$TEST_SRC_ZIP_DIR" % \
+                '$PYTHON $PYTHONFLAGS "%s" install "--prefix=$TEST_SRC_ZIP_DIR" --standalone-lib' % \
                     os.path.join(unpack_zip_dir,
                                  psv,
                                  'build',
                                  'scons',
                                  'setup.py'),
-            ])
+                ],
+                ENV = ENV)