Browse Source

Got lib and kernel building in the new mingen.

Updated the build.ck files for the lib and kernel directories. So now it's
a half-and-half mishmash of old build.ck files and new ones. Yay.
Evan Green 7 years ago
parent
commit
960e71ab77

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+# Ignore Chalk object files.
+*.cko

+ 202 - 82
build.ck

@@ -25,195 +25,315 @@ Environment:
 
 --*/
 
+import menv;
+from menv import setupEnv, group;
+
 function build() {
-    cflags_line = "$BASE_CPPFLAGS $CPPFLAGS $BASE_CFLAGS $CFLAGS " +
-                  "-MMD -MF $OUT.d ";
+    var allGroup;
+    var buildCflagsLine = "$BUILD_BASE_CPPFLAGS $CPPFLAGS " +
+                          "$BUILD_BASE_CFLAGS $CFLAGS -MMD -MF $OUT.d ";
+
+    var buildAsflagsLine = buildCflagsLine +
+                           "$BUILD_BASE_ASFLAGS $ASFLAGS ";
+
+    var buildLdflagsLine = "-Wl,-Map=$OUT.map $BUILD_BASE_LDFLAGS $LDFLAGS ";
+    var cflagsLine = "$BASE_CPPFLAGS $CPPFLAGS $BASE_CFLAGS $CFLAGS "
+                     "-MMD -MF $OUT.d ";
+
+    var asflagsLine = cflagsLine + "$BASE_ASFLAGS $ASFLAGS ";
+    var entries;
+    var ldflagsLine = "-Wl,-Map=$OUT.map $BASE_LDFLAGS $LDFLAGS ";
+    var mconfig;
+    var symlinkCommand = "ln -sf $SYMLINK_IN $OUT";
+    var buildLdLine = "$BUILD_CC " + buildLdflagsLine +
+                      "-o $OUT $IN -Bdynamic $DYNLIBS";
+
+    var tools;
+
+    setupEnv();
+    mconfig = menv.mconfig;
+    if (mconfig.build_os == "Windows") {
+        symlinkCommand = "cp $IN $OUT";
+    }
+
+    //
+    // On Mac OS there shouldn't be a -Bdynamic flag to indicate the start of
+    // the dynamic libraries section.
+    //
+
+    if (mconfig.build_os == "Darwin") {
+        buildLdLine = "$BUILD_CC " + buildLdflagsLine +
+                      "-o $OUT $IN $DYNLIBS";
+    }
+
+    //
+    // Define the tools used.
+    //
+
+    tools = [
+
+    //
+    // C compiler for target binaries.
+    //
 
-    cc = {
+    {
         "type": "tool",
         "name": "cc",
-        "command": "$CC " + cflags_line + "-c -o $OUT $IN",
+        "command": "$CC " + cflagsLine + "-c -o $OUT $IN",
         "description": "Compiling - $IN",
         "depsformat": "gcc",
         "depfile": "$OUT.d"
-    };
+    },
 
-    cxx = {
+    //
+    // C++ compiler for target binaries.
+    //
+
+    {
         "type": "tool",
         "name": "cxx",
-        "command": "$CXX " + cflags_line + "-c -o $OUT $IN",
+        "command": "$CXX " + cflagsLine + "-c -o $OUT $IN",
         "description": "Compiling - $IN",
         "depsformat": "gcc",
         "depfile": "$OUT.d"
-    };
+    },
+
+    //
+    // Linker for target binaries.
+    //
 
-    ldflags_line = "-Wl,-Map=$OUT.map $BASE_LDFLAGS $LDFLAGS ";
-    ld = {
+    {
         "type": "tool",
         "name": "ld",
-        "command": "$CC " + ldflags_line + "-o $OUT $IN -Bdynamic $DYNLIBS",
+        "command": "$CC " + ldflagsLine + "-o $OUT $IN -Bdynamic $DYNLIBS",
         "description": "Linking - $OUT",
-    };
+    },
 
-    ar = {
+    //
+    // Static archiver for target binaries.
+    //
+
+    {
         "type": "tool",
         "name": "ar",
         "command": "$AR rcs $OUT $IN",
         "description": "Building Library - $OUT",
-    };
+    },
+
+    //
+    // Assembler for target binaries.
+    //
 
-    asflags_line = cflags_line + "$BASE_ASFLAGS $ASFLAGS ";
-    as = {
+    {
         "type": "tool",
         "name": "as",
-        "command": "$CC " + asflags_line + "-c -o $OUT $IN",
+        "command": "$CC " + asflagsLine + "-c -o $OUT $IN",
         "description": "Assembling - $IN",
         "depsformat": "gcc",
         "depfile": "$OUT.d"
-    };
+    },
 
-    objcopy = {
+    //
+    // Objcopy for target binaries.
+    //
+
+    {
         "type": "tool",
         "name": "objcopy",
         "command": "$SHELL -c \"cd `dirname $IN` && $OBJCOPY $OBJCOPY_FLAGS `basename $IN` $OUT\"",
         "description": "Objectifying - $IN"
-    };
+    },
+
+    //
+    // Strip for target binaries.
+    //
 
-    strip_tool = {
+    {
         "type": "tool",
         "name": "strip",
         "command": "$STRIP $STRIP_FLAGS -o $OUT $IN",
         "description": "Stripping - $OUT",
-    };
+    },
 
-    build_cflags_line = "$BUILD_BASE_CPPFLAGS $CPPFLAGS $BUILD_BASE_CFLAGS " +
-                        "$CFLAGS -MMD -MF $OUT.d ";
+    //
+    // C compiler for the build machine.
+    //
 
-    build_cc = {
+    {
         "type": "tool",
         "name": "build_cc",
-        "command": "$BUILD_CC " + build_cflags_line + "-c -o $OUT $IN",
+        "command": "$BUILD_CC " + buildCflagsLine + "-c -o $OUT $IN",
         "description": "Compiling - $IN",
         "depsformat": "gcc",
         "depfile": "$OUT.d"
-    };
+    },
+
+    //
+    // C++ compiler for the build machine.
+    //
 
-    build_cxx = {
+    {
         "type": "tool",
         "name": "build_cxx",
-        "command": "$BUILD_CXX " + build_cflags_line + "-c -o $OUT $IN",
+        "command": "$BUILD_CXX " + buildCflagsLine + "-c -o $OUT $IN",
         "description": "Compiling - $IN",
         "depsformat": "gcc",
         "depfile": "$OUT.d"
-    };
+    },
 
-    build_ldflags_line = "-Wl,-Map=$OUT.map $BUILD_BASE_LDFLAGS $LDFLAGS ";
-    build_ld = {
+    //
+    // Linker for the build machine.
+    //
+
+    {
         "type": "tool",
         "name": "build_ld",
-        "command": "$BUILD_CC " + build_ldflags_line + "-o $OUT $IN -Bdynamic $DYNLIBS",
+        "command": "$BUILD_CC " + buildLdflagsLine + "-o $OUT $IN -Bdynamic $DYNLIBS",
         "description": "Linking - $OUT",
-    };
+    },
+
+    //
+    // Static archiver for the build machine.
+    //
 
-    build_ar = {
+    {
         "type": "tool",
         "name": "build_ar",
         "command": "$BUILD_AR rcs $OUT $IN",
         "description": "Building Library - $OUT",
-    };
+    },
 
-    build_asflags_line = build_cflags_line + "$BUILD_BASE_ASFLAGS $ASFLAGS ";
-    build_as = {
+    //
+    // Assembler for the build machine.
+    //
+
+    {
         "type": "tool",
         "name": "build_as",
-        "command": "$BUILD_CC " + build_asflags_line + "-c -o $OUT $IN",
+        "command": "$BUILD_CC " + buildAsflagsLine + "-c -o $OUT $IN",
         "description": "Assembling - $IN",
         "depsformat": "gcc",
         "depfile": "$OUT.d"
-    };
+    },
+
+    //
+    // Strip for the build machine.
+    //
 
-    build_strip = {
+    {
         "type": "tool",
         "name": "build_strip",
         "command": "$BUILD_STRIP $STRIP_FLAGS -o $OUT $IN",
         "description": "Stripping - $OUT",
-    };
+    },
 
-    build_rcc = {
+    //
+    // Windows resource compiler for the build machine.
+    //
+
+    {
         "type": "tool",
         "name": "build_rcc",
         "command": "$RCC -o $OUT $IN",
         "description": "Compiling Resource - $IN",
-    };
+    },
+
+    //
+    // ACPI assembler used to build firmware images.
+    //
 
-    iasl = {
+    {
         "type": "tool",
         "name": "iasl",
         "command": "$SHELL -c \"$IASL $IASL_FLAGS -p $OUT $IN > $OUT.stdout\"",
         "description": "Compiling ASL - $IN"
-    };
+    },
 
-    cp = {
+    //
+    // Copy files from one location to another.
+    //
+
+    {
         "type": "tool",
         "name": "copy",
         "command": "$SHELL -c \"cp $CPFLAGS $IN $OUT && [ -z $CHMOD_FLAGS ] || chmod $CHMOD_FLAGS $OUT\"",
         "description": "Copying - $IN -> $OUT"
-    };
+    },
 
-    if (build_os == "Windows") {
-        symlink_command = "cp $IN $OUT";
+    //
+    // Create symbolic links (or just copy on Windows).
+    //
 
-    } else {
-        symlink_command = "ln -sf $SYMLINK_IN $OUT";
-    }
-
-    symlink = {
+    {
         "type": "tool",
         "name": "symlink",
-        "command": symlink_command,
+        "command": symlinkCommand,
         "description": "Symlinking - $OUT"
-    };
+    },
+
+    //
+    // Touch a file with the date.
+    //
 
-    stamp = {
+    {
         "type": "tool",
         "name": "stamp",
         "command": "$SHELL -c \"date > $OUT\"",
         "description": "Stamp - $OUT"
-    };
+    },
 
-    touch = {
+    //
+    // Touch to create a timestamped empty file.
+    //
+
+    {
         "type": "tool",
         "name": "touch",
         "command": "touch $OUT",
         "description": "Touch - $OUT"
-    };
+    },
+
+    //
+    // Generate a version.h.
+    //
 
-    gen_version = {
+    {
         "type": "tool",
         "name": "gen_version",
-        "command": "$SHELL $//tasks/build/print_version.sh $OUT $FORM $MAJOR $MINOR $REVISION $RELEASE $SERIAL $BUILD_STRING",
+        "command": "$SHELL $S/tasks/build/print_version.sh $OUT $FORM $MAJOR $MINOR $REVISION $RELEASE $SERIAL $BUILD_STRING",
         "description": "Versioning - $OUT"
-    };
-
-    config_entry = {
-        "type": "global_config",
-        "config": global_config
-    };
-
-    entries = [cc, cxx, ld, ar, as, objcopy, strip_tool,
-               build_cc, build_cxx, build_ld, build_ar, build_as, build_rcc,
-               build_strip, iasl, cp, symlink, stamp, touch, gen_version,
-               config_entry];
-
-    all = [
-        "//lib:test_apps",
-        "//images:"
+    }];
+
+    entries = [
+        "lib/basevid:basevid",
+        "lib/basevid:build_basevid",
+        "lib/bconflib:bconf",
+        "lib/bconflib:build_bconf",
+        "lib/crypto:crypto",
+        "lib/crypto:build_crypto",
+        "lib/crypto/ssl:ssl",
+        "lib/crypto/testcryp:build_testcryp",
+        "lib/rtl/testrtl:build_testrtl",
+        "lib/fatlib:fat",
+        "lib/fatlib/fattest:build_fattest",
+        "lib/im:im",
+        "lib/im:build_im",
+        "lib/partlib:partlib",
+        "lib/partlib:build_partlib",
+        "lib/termlib:termlib",
+        "lib/termlib:build_termlib",
+        "lib/yy:yy",
+        "lib/yy:build_yy",
+        "lib/yy/yytest:build_yytest",
+        "lib/yy/gen:yygen",
+        "lib/yy/gen:build_yygen",
+        "lib:test_apps",
+        "kernel:kernel"
     ];
 
-    all_group = group("all", all);
-    all_group[0]["default"] = TRUE;
-    entries += all_group;
+    allGroup = group("all", entries);
+    allGroup[0].default = true;
+    entries = allGroup + tools;
     return entries;
 }
 
-return build();

+ 7 - 2
kernel/acpi/build.ck

@@ -27,7 +27,13 @@ Environment:
 
 --*/
 
+from menv import staticLibrary;
+
 function build() {
+    var entries;
+    var lib;
+    var sources;
+
     sources = [
         "tables.c"
     ];
@@ -37,8 +43,7 @@ function build() {
         "inputs": sources,
     };
 
-    entries = static_library(lib);
+    entries = staticLibrary(lib);
     return entries;
 }
 
-return build();

+ 62 - 46
kernel/build.ck

@@ -25,14 +25,32 @@ Environment:
 
 --*/
 
+from menv import staticLibrary, copy, driver, createVersionHeader, mconfig;
+
 function build() {
-    base_sources = [
+    var arch = mconfig.arch;
+    var archSources;
+    var armSources;
+    var baseSources;
+    var binroot = mconfig.binroot;
+    var bootArchLib;
+    var bootArchSources;
+    var entries;
+    var kernel;
+    var kernelConfig;
+    var kernelLibs;
+    var versionConfig;
+    var versionFile;
+    var versionMajor;
+    var versionMinor;
+    var versionRevision;
+
+    baseSources = [
         "init.c"
     ];
 
-    boot_arch_sources = [];
     if ((arch == "armv7") || (arch == "armv6")) {
-        arm_sources = [
+        armSources = [
             "armv7/commsup.S",
             "armv7/inttable.S",
             "armv7/prochw.c",
@@ -41,22 +59,22 @@ function build() {
             "armv7/vfp.c"
         ];
 
-        boot_arch_sources = [":armv7/sstep.o"];
+        bootArchSources = [":armv7/sstep.o"];
         if (arch == "armv7") {
-            arch_sources = arm_sources + [
+            archSources = armSources + [
                 "armv7/archsup.S",
                 "armv7/archsupc.c"
             ];
 
         } else {
-            arch_sources = arm_sources + [
+            archSources = armSources + [
                 "armv6/archsup.S",
                 "armv6/archsupc.c"
             ];
         }
 
     } else if (arch == "x86") {
-        arch_sources = [
+        archSources = [
             "x86/archsup.S",
             "x86/archsupc.c",
             "x86/prochw.c",
@@ -64,45 +82,45 @@ function build() {
         ];
     }
 
-    kernel_libs = [
-        "//kernel/acpi:acpi",
-        "//lib/crypto:crypto",
-        "//kernel/ob:ob",
-        "//lib/rtl/base:basertl",
-        "//lib/rtl/kmode:krtl",
-        "//lib/im:im",
-        "//lib/basevid:basevid",
-        "//lib/termlib:termlib",
-        "//kernel/kd:kd",
-        "//kernel/kd/kdusb:kdusb",
-        "//kernel/ps:ps",
-        "//kernel/ke:ke",
-        "//kernel/io:io",
-        "//kernel/hl:hl",
-        "//kernel/mm:mm",
-        "//kernel/sp:sp"
+    kernelLibs = [
+        "kernel/acpi:acpi",
+        "lib/crypto:crypto",
+        "kernel/ob:ob",
+        "lib/rtl/base:basertl",
+        "lib/rtl/kmode:krtl",
+        "lib/im:im",
+        "lib/basevid:basevid",
+        "lib/termlib:termlib",
+        "kernel/kd:kd",
+        "kernel/kd/kdusb:kdusb",
+        "kernel/ps:ps",
+        "kernel/ke:ke",
+        "kernel/io:io",
+        "kernel/hl:hl",
+        "kernel/mm:mm",
+        "kernel/sp:sp"
     ];
 
-    kernel_config = {
+    kernelConfig = {
         "LDFLAGS": ["-Wl,--whole-archive"]
     };
 
     kernel = {
         "label": "kernel",
-        "inputs": base_sources + arch_sources + kernel_libs,
+        "inputs": baseSources + archSources + kernelLibs,
         "implicit": [":kernel-version"],
         "entry": "KepStartSystem",
-        "config": kernel_config
+        "config": kernelConfig
     };
 
-    boot_arch_lib = {
+    bootArchLib = {
         "label": "archboot",
-        "inputs": boot_arch_sources
+        "inputs": bootArchSources
     };
 
     entries = driver(kernel);
-    if (boot_arch_sources) {
-        entries += static_library(boot_arch_lib);
+    if (bootArchSources) {
+        entries += staticLibrary(bootArchLib);
     }
 
     //
@@ -137,35 +155,33 @@ function build() {
     // Create the version header.
     //
 
-    version_major = "0";
-    version_minor = "2";
-    version_revision = "0";
-    entries += create_version_header(version_major,
-                                     version_minor,
-                                     version_revision);
+    versionMajor = "0";
+    versionMinor = "3";
+    versionRevision = "1";
+    entries += createVersionHeader(versionMajor,
+                                   versionMinor,
+                                   versionRevision);
 
     //
     // Also create a version file in the binroot.
     //
 
-    version_config = {
-        "MAJOR": version_major,
-        "MINOR": version_minor,
-        "REVISION": version_revision,
+    versionConfig = {
+        "MAJOR": versionMajor,
+        "MINOR": versionMinor,
+        "REVISION": versionRevision,
         "FORM": "simple"
     };
 
-    version_file = {
+    versionFile = {
         "type": "target",
         "label": "kernel-version",
         "output": binroot + "/kernel-version",
         "tool": "gen_version",
-        "config": version_config
+        "config": versionConfig
     };
 
-    entries += [version_file];
+    entries += [versionFile];
     return entries;
 }
 
-return build();
-

+ 24 - 14
kernel/hl/build.ck

@@ -30,8 +30,19 @@ Environment:
 
 --*/
 
+from menv import staticLibrary, mconfig;
+
 function build() {
-    base_sources = [
+    var arch = mconfig.arch;
+    var archBootSources;
+    var archSources;
+    var baseSources;
+    var bootLib;
+    var bootSources;
+    var entries;
+    var lib;
+
+    baseSources = [
         "cache.c",
         "calendar.c",
         "clock.c",
@@ -50,14 +61,14 @@ function build() {
         "timer.c"
     ];
 
-    boot_sources = [
+    bootSources = [
         "boot/hmodapi.c",
         ":dbgdev.o",
         ":ns16550.o"
     ];
 
     if (arch == "armv7") {
-        arch_sources = [
+        archSources = [
             "armv7/am335int.c",
             "armv7/am335pwr.c",
             "armv7/am335tmr.c",
@@ -91,7 +102,7 @@ function build() {
             "armv7/b2709tmr.c"
         ];
 
-        arch_boot_sources = [
+        archBootSources = [
             ":armv7/archdbg.o",
             ":armv7/regacces.o",
             ":armv7/uartpl11.o",
@@ -99,7 +110,7 @@ function build() {
         ];
 
     } else if (arch == "armv6") {
-        arch_sources = [
+        archSources = [
             "armv6/archcach.c",
             "armv6/archdbg.c",
             "armv6/archintr.c",
@@ -115,14 +126,14 @@ function build() {
             "armv7/uartpl11.c",
         ];
 
-        arch_boot_sources = [
+        archBootSources = [
             ":armv6/archdbg.o",
             ":armv7/regacces.o",
             ":armv7/uartpl11.o",
         ];
 
     } else if ((arch == "x86") || (arch == "x64")) {
-        arch_sources = [
+        archSources = [
             "x86/apic.c",
             "x86/apictimr.c",
             "x86/apinit.c",
@@ -140,7 +151,7 @@ function build() {
             "x86/tsc.c"
         ];
 
-        arch_boot_sources = [
+        archBootSources = [
             ":x86/archdbg.o",
             ":x86/ioport.o",
             ":x86/regacces.o"
@@ -149,17 +160,16 @@ function build() {
 
     lib = {
         "label": "hl",
-        "inputs": base_sources + arch_sources,
+        "inputs": baseSources + archSources,
     };
 
-    boot_lib = {
+    bootLib = {
         "label": "hlboot",
-        "inputs": boot_sources + arch_boot_sources
+        "inputs": bootSources + archBootSources
     };
 
-    entries = static_library(lib);
-    entries += static_library(boot_lib);
+    entries = staticLibrary(lib);
+    entries += staticLibrary(bootLib);
     return entries;
 }
 
-return build();

+ 13 - 6
kernel/io/build.ck

@@ -28,8 +28,16 @@ Environment:
 
 --*/
 
+from menv import staticLibrary, mconfig;
+
 function build() {
-    base_sources = [
+    var arch = mconfig.arch;
+    var archSources;
+    var baseSources;
+    var entries;
+    var lib;
+
+    baseSources = [
         "arb.c",
         "cachedio.c",
         "cstate.c",
@@ -68,13 +76,13 @@ function build() {
     ];
 
     if ((arch == "armv7") || (arch == "armv6")) {
-        arch_sources = [
+        archSources = [
             "armv7/archio.c",
             "armv7/archpm.c"
         ];
 
     } else if ((arch == "x86") || (arch == "x64")) {
-        arch_sources = [
+        archSources = [
             "x86/archio.c",
             "x86/archpm.c",
             "x86/intelcst.c"
@@ -83,11 +91,10 @@ function build() {
 
     lib = {
         "label": "io",
-        "inputs": base_sources + arch_sources,
+        "inputs": baseSources + archSources,
     };
 
-    entries = static_library(lib);
+    entries = staticLibrary(lib);
     return entries;
 }
 
-return build();

+ 22 - 12
kernel/kd/build.ck

@@ -27,24 +27,35 @@ Environment:
 
 --*/
 
+from menv import staticLibrary, mconfig;
+
 function build() {
-    base_sources = [
+    var arch = mconfig.arch;
+    var archSources;
+    var baseSources;
+    var bootArchSources;
+    var bootLib;
+    var bootSources;
+    var entries;
+    var lib;
+
+    baseSources = [
         "kdebug.c"
     ];
 
-    boot_sources = [
+    bootSources = [
         ":kdebug.o",
     ];
 
     if ((arch == "armv7") || (arch == "armv6")) {
-        arch_sources = [
+        archSources = [
             "armv7/kdarch.c",
             "armv7/kdatomic.S",
             "armv7/kdsup.S",
             "armv7/kdsupc.c"
         ];
 
-        boot_arch_sources = [
+        bootArchSources = [
             ":armv7/kdarch.o",
             "boot/armv7/kdatomic.S",
             ":armv7/kdsup.o",
@@ -52,12 +63,12 @@ function build() {
         ];
 
     } else if ((arch == "x86") || (arch == "x64")) {
-        arch_sources = [
+        archSources = [
             "x86/kdarch.c",
             "x86/kdsup.S"
         ];
 
-        boot_arch_sources = [
+        bootArchSources = [
             ":x86/kdarch.o",
             ":x86/kdsup.o"
         ];
@@ -65,17 +76,16 @@ function build() {
 
     lib = {
         "label": "kd",
-        "inputs": base_sources + arch_sources,
+        "inputs": baseSources + archSources,
     };
 
-    boot_lib = {
+    bootLib = {
         "label": "kdboot",
-        "inputs": boot_sources + boot_arch_sources,
+        "inputs": bootSources + bootArchSources,
     };
 
-    entries = static_library(lib);
-    entries += static_library(boot_lib);
+    entries = staticLibrary(lib);
+    entries += staticLibrary(bootLib);
     return entries;
 }
 
-return build();

+ 15 - 7
kernel/kd/kdusb/build.ck

@@ -25,7 +25,16 @@ Environment:
 
 --*/
 
+from menv import staticLibrary;
+
 function build() {
+    var entries;
+    var includes;
+    var lib;
+    var sources;
+    var stubLib;
+    var stubSources;
+
     sources = [
         "ftdi.c",
         "hub.c",
@@ -33,12 +42,12 @@ function build() {
         "kdusb.c"
     ];
 
-    stub_sources = [
+    stubSources = [
         "kdnousb/stubs.c"
     ];
 
     includes = [
-        "$//drivers/usb/ehci"
+        "$S/drivers/usb/ehci"
     ];
 
     lib = {
@@ -47,14 +56,13 @@ function build() {
         "includes": includes
     };
 
-    stub_lib = {
+    stubLib = {
         "label": "kdnousb",
-        "inputs": stub_sources
+        "inputs": stubSources
     };
 
-    entries = static_library(lib);
-    entries += static_library(stub_lib);
+    entries = staticLibrary(lib);
+    entries += staticLibrary(stubLib);
     return entries;
 }
 
-return build();

+ 14 - 7
kernel/ke/build.ck

@@ -27,7 +27,15 @@ Environment:
 
 --*/
 
+from menv import staticLibrary, addConfig, mconfig;
+
 function build() {
+    var arch = mconfig.arch;
+    var archSources;
+    var entries;
+    var lib;
+    var sources;
+
     sources = [
         "crash.c",
         "crashdmp.c",
@@ -52,7 +60,7 @@ function build() {
     ];
 
     if ((arch == "armv7") || (arch == "armv6")) {
-        arch_sources = [
+        archSources = [
             "armv7/archinit.c",
             "armv7/ctxswap.S",
             "armv7/ctxswapc.c",
@@ -61,7 +69,7 @@ function build() {
         ];
 
     } else if ((arch == "x86") || (arch == "x64")) {
-        arch_sources = [
+        archSources = [
             "x86/archinit.c",
             "x86/ctxswap.S",
             "x86/ctxswapc.c",
@@ -72,10 +80,10 @@ function build() {
 
     lib = {
         "label": "ke",
-        "inputs": sources + arch_sources,
+        "inputs": sources + archSources,
     };
 
-    entries = static_library(lib);
+    entries = staticLibrary(lib);
 
     //
     // Add the include and dependency for version.c.
@@ -83,8 +91,8 @@ function build() {
 
     for (entry in entries) {
         if (entry["output"] == "version.o") {
-            add_config(entry, "CPPFLAGS", "-I$^/kernel");
-            entry["implicit"] = ["//kernel:version.h", "//.git/HEAD"];
+            addConfig(entry, "CPPFLAGS", "-I$O/kernel/ke");
+            entry["implicit"] = ["kernel:version.h", "$S/.git/index"];
             break;
         }
     }
@@ -92,4 +100,3 @@ function build() {
     return entries;
 }
 
-return build();

+ 40 - 25
kernel/mm/build.ck

@@ -28,8 +28,24 @@ Environment:
 
 --*/
 
+from menv import staticLibrary, mconfig;
+
 function build() {
-    base_sources = [
+    var arch = mconfig.arch;
+    var archSources;
+    var armSources;
+    var armv6Sources;
+    var armv7Sources;
+    var baseSources;
+    var bootLib;
+    var bootSources;
+    var buildArchSources;
+    var buildLib;
+    var entries;
+    var lib;
+    var x86Sources;
+
+    baseSources = [
         "block.c",
         "imgsec.c",
         "info.c",
@@ -45,26 +61,26 @@ function build() {
         "fault.c"
     ];
 
-    boot_sources = [
+    bootSources = [
         ":mdl.o"
     ];
 
-    arm_sources = [
+    armSources = [
         "armv7/archcomc.c",
         "armv7/flush.c",
         "armv7/mapping.c",
         "armv7/usermem.S"
     ];
 
-    armv7_sources = arm_sources + [
+    armv7Sources = armSources + [
         "armv7/archsupc.c"
     ];
 
-    armv6_sources = arm_sources + [
+    armv6Sources = armSources + [
         "armv6/archsupc.c"
     ];
 
-    x86_sources = [
+    x86Sources = [
         "x86/archsupc.c",
         "x86/flush.c",
         "x86/mapping.c",
@@ -72,47 +88,46 @@ function build() {
     ];
 
     if (arch == "armv7") {
-        arch_sources = armv7_sources;
+        archSources = armv7Sources;
 
     } else if (arch == "armv6") {
-        arch_sources = armv6_sources;
+        archSources = armv6Sources;
 
     } else if (arch == "x86") {
-        arch_sources = x86_sources;
+        archSources = x86Sources;
     }
 
-    if (build_arch == "armv7") {
-        build_arch_sources = armv7_sources;
+    if (mconfig.build_arch == "armv7") {
+        buildArchSources = armv7Sources;
 
-    } else if (build_arch == "armv6") {
-        build_arch_sources = armv6_sources;
+    } else if (mconfig.build_arch == "armv6") {
+        buildArchSources = armv6Sources;
 
-    } else if (build_arch == "x86") {
-        build_arch_sources = x86_sources;
+    } else if (mconfig.build_arch == "x86") {
+        buildArchSources = x86Sources;
     }
 
     lib = {
         "label": "mm",
-        "inputs": base_sources + arch_sources,
+        "inputs": baseSources + archSources,
     };
 
-    boot_lib = {
+    bootLib = {
         "label": "mmboot",
-        "inputs": boot_sources
+        "inputs": bootSources
     };
 
-    build_lib = {
+    buildLib = {
         "label": "build_mm",
         "output": "mm",
-        "inputs": base_sources + build_arch_sources,
-        "build": TRUE,
+        "inputs": baseSources + buildArchSources,
+        "build": true,
         "prefix": "build"
     };
 
-    entries = static_library(lib);
-    entries += static_library(boot_lib);
-    entries += static_library(build_lib);
+    entries = staticLibrary(lib);
+    entries += staticLibrary(bootLib);
+    entries += staticLibrary(buildLib);
     return entries;
 }
 
-return build();

+ 15 - 10
kernel/mm/testmm/build.ck

@@ -26,7 +26,14 @@ Environment:
 
 --*/
 
+from menv import application;
+
 function build() {
+    var buildApp;
+    var buildLibs;
+    var entries;
+    var sources;
+
     sources = [
         "stubs.c",
         "testmm.c",
@@ -34,23 +41,21 @@ function build() {
         "testuva.c"
     ];
 
-    build_libs = [
-        "//kernel/mm:build_mm",
-        "//lib/rtl/rtlc:build_rtlc",
-        "//lib/rtl/base:build_basertl"
+    buildLibs = [
+        "kernel/mm:build_mm",
+        "lib/rtl/rtlc:build_rtlc",
+        "lib/rtl/base:build_basertl"
     ];
 
-    build_app = {
+    buildApp = {
         "label": "build_testmm",
         "output": "testmm",
-        "inputs": sources + build_libs,
-        "build": TRUE,
+        "inputs": sources + buildLibs,
+        "build": true,
         "prefix": "build"
     };
 
-    entries = application(build_app);
+    entries = application(buildApp);
     return entries;
 }
 
-return build();
-

+ 7 - 2
kernel/ob/build.ck

@@ -27,7 +27,13 @@ Environment:
 
 --*/
 
+from menv import staticLibrary;
+
 function build() {
+    var entries;
+    var lib;
+    var sources;
+
     sources = [
         "handles.c",
         "obapi.c"
@@ -38,8 +44,7 @@ function build() {
         "inputs": sources,
     };
 
-    entries = static_library(lib);
+    entries = staticLibrary(lib);
     return entries;
 }
 
-return build();

+ 13 - 6
kernel/ps/build.ck

@@ -27,8 +27,16 @@ Environment:
 
 --*/
 
+from menv import staticLibrary, mconfig;
+
 function build() {
-    base_sources = [
+    var arch = mconfig.arch;
+    var archSources;
+    var baseSources;
+    var entries;
+    var lib;
+
+    baseSources = [
         "env.c",
         "info.c",
         "init.c",
@@ -44,23 +52,22 @@ function build() {
     ];
 
     if ((arch == "armv7") || (arch == "armv6")) {
-        arch_sources = [
+        archSources = [
             "armv7/psarch.c"
         ];
 
     } else if (arch == "x86") {
-        arch_sources = [
+        archSources = [
             "x86/psarch.c"
         ];
     }
 
     lib = {
         "label": "ps",
-        "inputs": base_sources + arch_sources,
+        "inputs": baseSources + archSources,
     };
 
-    entries = static_library(lib);
+    entries = staticLibrary(lib);
     return entries;
 }
 
-return build();

+ 13 - 6
kernel/sp/build.ck

@@ -26,30 +26,37 @@ Environment:
 
 --*/
 
+from menv import staticLibrary, mconfig;
+
 function build() {
-    base_sources = [
+    var arch = mconfig.arch;
+    var archSources;
+    var baseSources;
+    var entries;
+    var lib;
+
+    baseSources = [
         "info.c",
         "profiler.c"
     ];
 
     if ((arch == "armv7") || (arch == "armv6")) {
-        arch_sources = [
+        archSources = [
             "armv7/archprof.c"
         ];
 
     } else if (arch == "x86") {
-        arch_sources = [
+        archSources = [
             "x86/archprof.c"
         ];
     }
 
     lib = {
         "label": "sp",
-        "inputs": base_sources + arch_sources,
+        "inputs": baseSources + archSources,
     };
 
-    entries = static_library(lib);
+    entries = staticLibrary(lib);
     return entries;
 }
 
-return build();

+ 11 - 5
lib/basevid/build.ck

@@ -27,7 +27,14 @@ Environment:
 
 --*/
 
+from menv import staticLibrary;
+
 function build() {
+    var buildLib;
+    var entries;
+    var lib;
+    var sources;
+
     sources = [
         "fontdata.c",
         "textvid.c"
@@ -38,17 +45,16 @@ function build() {
         "inputs": sources,
     };
 
-    build_lib = {
+    buildLib = {
         "label": "build_basevid",
         "output": "basevid",
         "inputs": sources,
-        "build": TRUE,
+        "build": true,
         "prefix": "build"
     };
 
-    entries = static_library(lib);
-    entries += static_library(build_lib);
+    entries = staticLibrary(lib);
+    entries += staticLibrary(buildLib);
     return entries;
 }
 
-return build();

+ 12 - 6
lib/bconflib/build.ck

@@ -25,27 +25,33 @@ Environment:
 
 --*/
 
+from menv import staticLibrary;
+
 function build() {
+    var bconfLib;
+    var buildBconfLib;
+    var entries;
+    var sources;
+
     sources = [
         "bconf.c"
     ];
 
-    bconf_lib = {
+    bconfLib = {
         "label": "bconf",
         "inputs": sources,
     };
 
-    build_bconf_lib = {
+    buildBconfLib = {
         "label": "build_bconf",
         "output": "bconf",
         "inputs": sources,
-        "build": TRUE,
+        "build": true,
         "prefix": "build"
     };
 
-    entries = static_library(bconf_lib);
-    entries += static_library(build_bconf_lib);
+    entries = staticLibrary(bconfLib);
+    entries += staticLibrary(buildBconfLib);
     return entries;
 }
 
-return build();

+ 12 - 8
lib/build.ck

@@ -26,17 +26,21 @@ Environment:
 
 --*/
 
+from menv import group;
+
 function build() {
-    test_apps = [
-        "//lib/crypto/testcryp:",
-        "//lib/fatlib/fattest:",
-        "//lib/rtl/testrtl:",
-        "//lib/yy/yytest:",
-        "//kernel/mm/testmm:",
+    var entries;
+    var testApps;
+
+    testApps = [
+        "lib/crypto/testcryp:",
+        "lib/fatlib/fattest:",
+        "lib/rtl/testrtl:",
+        "lib/yy/yytest:",
+        "kernel/mm/testmm:",
     ];
 
-    entries = group("test_apps", test_apps);
+    entries = group("test_apps", testApps);
     return entries;
 }
 
-return build();

+ 11 - 5
lib/crypto/build.ck

@@ -26,7 +26,14 @@ Environment:
 
 --*/
 
+from menv import staticLibrary;
+
 function build() {
+    var buildLib;
+    var entries;
+    var lib;
+    var sources;
+
     sources = [
         "aes.c",
         "fortuna.c",
@@ -42,17 +49,16 @@ function build() {
         "inputs": sources,
     };
 
-    build_lib = {
+    buildLib = {
         "label": "build_crypto",
         "output": "crypto",
         "inputs": sources,
-        "build": TRUE,
+        "build": true,
         "prefix": "build"
     };
 
-    entries = static_library(lib);
-    entries += static_library(build_lib);
+    entries = staticLibrary(lib);
+    entries += staticLibrary(buildLib);
     return entries;
 }
 
-return build();

+ 11 - 5
lib/crypto/ssl/build.ck

@@ -25,7 +25,14 @@ Environment:
 
 --*/
 
+from menv import staticLibrary;
+
 function build() {
+    var buildLib;
+    var entries;
+    var lib;
+    var sources;
+
     sources = [
         "asn1.c",
         "base64.c",
@@ -39,17 +46,16 @@ function build() {
         "inputs": sources,
     };
 
-    build_lib = {
+    buildLib = {
         "label": "build_ssl",
         "output": "ssl",
         "inputs": sources,
-        "build": TRUE,
+        "build": true,
         "prefix": "build"
     };
 
-    entries = static_library(lib);
-    entries += static_library(build_lib);
+    entries = staticLibrary(lib);
+    entries += staticLibrary(buildLib);
     return entries;
 }
 
-return build();

+ 16 - 11
lib/crypto/testcryp/build.ck

@@ -26,29 +26,34 @@ Environment:
 
 --*/
 
+from menv import application;
+
 function build() {
+    var buildLibs;
+    var buildApp;
+    var entries;
+    var sources;
+
     sources = [
         "testcryp.c"
     ];
 
-    build_libs = [
-        "//lib/crypto/ssl:build_ssl",
-        "//lib/crypto:build_crypto",
-        "//lib/rtl/rtlc:build_rtlc",
-        "//lib/rtl/base:build_basertl"
+    buildLibs = [
+        "lib/crypto/ssl:build_ssl",
+        "lib/crypto:build_crypto",
+        "lib/rtl/rtlc:build_rtlc",
+        "lib/rtl/base:build_basertl"
     ];
 
-    build_app = {
+    buildApp = {
         "label": "build_testcryp",
         "output": "testcryp",
-        "inputs": sources + build_libs,
-        "build": TRUE,
+        "inputs": sources + buildLibs,
+        "build": true,
         "prefix": "build"
     };
 
-    entries = application(build_app);
+    entries = application(buildApp);
     return entries;
 }
 
-return build();
-

+ 11 - 5
lib/fatlib/build.ck

@@ -25,7 +25,14 @@ Environment:
 
 --*/
 
+from menv import staticLibrary;
+
 function build() {
+    var buildLib;
+    var entries;
+    var lib;
+    var sources;
+
     sources = [
         "fat.c",
         "fatcache.c",
@@ -38,17 +45,16 @@ function build() {
         "inputs": sources,
     };
 
-    build_lib = {
+    buildLib = {
         "label": "build_fat",
         "output": "fat",
         "inputs": sources,
-        "build": TRUE,
+        "build": true,
         "prefix": "build"
     };
 
-    entries = static_library(lib);
-    entries += static_library(build_lib);
+    entries = staticLibrary(lib);
+    entries += staticLibrary(buildLib);
     return entries;
 }
 
-return build();

+ 15 - 10
lib/fatlib/fattest/build.ck

@@ -25,29 +25,34 @@ Environment:
 
 --*/
 
+from menv import application;
+
 function build() {
+    var buildApp;
+    var buildLibs;
+    var entries;
+    var sources;
+
     sources = [
         "fatdev.c",
         "fattest.c"
     ];
 
-    build_libs = [
-        "//lib/fatlib:build_fat",
-        "//lib/rtl/rtlc:build_rtlc",
-        "//lib/rtl/base:build_basertl"
+    buildLibs = [
+        "lib/fatlib:build_fat",
+        "lib/rtl/rtlc:build_rtlc",
+        "lib/rtl/base:build_basertl"
     ];
 
-    build_app = {
+    buildApp = {
         "label": "build_fattest",
         "output": "fattest",
-        "inputs": sources + build_libs,
-        "build": TRUE,
+        "inputs": sources + buildLibs,
+        "build": true,
         "prefix": "build"
     };
 
-    entries = application(build_app);
+    entries = application(buildApp);
     return entries;
 }
 
-return build();
-

+ 11 - 5
lib/im/build.ck

@@ -26,7 +26,14 @@ Environment:
 
 --*/
 
+from menv import staticLibrary;
+
 function build() {
+    var buildLib;
+    var entries;
+    var lib;
+    var sources;
+
     sources = [
         "elf.c",
         "elf64.c",
@@ -40,17 +47,16 @@ function build() {
         "inputs": sources,
     };
 
-    build_lib = {
+    buildLib = {
         "label": "build_im",
         "output": "im",
         "inputs": sources,
-        "build": TRUE,
+        "build": true,
         "prefix": "build"
     };
 
-    entries = static_library(lib);
-    entries += static_library(build_lib);
+    entries = staticLibrary(lib);
+    entries += staticLibrary(buildLib);
     return entries;
 }
 
-return build();

+ 11 - 5
lib/partlib/build.ck

@@ -25,7 +25,14 @@ Environment:
 
 --*/
 
+from menv import staticLibrary;
+
 function build() {
+    var buildLib;
+    var entries;
+    var lib;
+    var sources;
+
     sources = [
         "gpt.c",
         "partlib.c"
@@ -36,17 +43,16 @@ function build() {
         "inputs": sources,
     };
 
-    build_lib = {
+    buildLib = {
         "label": "build_partlib",
         "output": "partlib",
         "inputs": sources,
-        "build": TRUE,
+        "build": true,
         "prefix": "build"
     };
 
-    entries = static_library(lib);
-    entries += static_library(build_lib);
+    entries = staticLibrary(lib);
+    entries += staticLibrary(buildLib);
     return entries;
 }
 
-return build();

+ 68 - 44
lib/rtl/base/build.ck

@@ -26,7 +26,30 @@ Environment:
 
 --*/
 
+from menv import mconfig, staticLibrary;
+
 function build() {
+    var armv7BootSources;
+    var armv7Intrinsics;
+    var armv7Sources;
+    var baseRtlLib;
+    var bootLib;
+    var bootSources;
+    var buildBaseRtlLib;
+    var buildSources;
+    var entries;
+    var includes;
+    var intrinsics;
+    var intrinsicsLib;
+    var intrinsicsSourcesConfig;
+    var sources;
+    var targetSources;
+    var wideLib;
+    var wideSources;
+    var x64Sources;
+    var x86Intrinsics;
+    var x86Sources;
+
     sources = [
         "crc32.c",
         "heap.c",
@@ -42,28 +65,28 @@ function build() {
         "wchar.c"
     ];
 
-    wide_sources = [
+    wideSources = [
         "wprint.c",
         "wscan.c",
         "wstring.c",
         "wtime.c"
     ];
 
-    x86_intrinsics = [
+    x86Intrinsics = [
         "x86/intrinsc.c"
     ];
 
-    x86_sources = x86_intrinsics + [
+    x86Sources = x86Intrinsics + [
         "x86/rtlarch.S",
         "x86/rtlmem.S"
     ];
 
-    armv7_intrinsics = [
+    armv7Intrinsics = [
         "armv7/intrinsa.S",
         "armv7/intrinsc.c"
     ];
 
-    armv7_sources = armv7_intrinsics + [
+    armv7Sources = armv7Intrinsics + [
         "armv7/rtlarch.S",
         "armv7/rtlmem.S",
         "fp2int.c"
@@ -74,7 +97,7 @@ function build() {
     // library just so they get exercise.
     //
 
-    armv7_boot_sources = armv7_intrinsics + [
+    armv7BootSources = armv7Intrinsics + [
         "armv7/aeabisfp.c",
         "armv7/rtlmem.S",
         "boot/armv7/rtlarch.S",
@@ -82,7 +105,7 @@ function build() {
         "softfp.c"
     ];
 
-    x64_sources = [
+    x64Sources = [
         "x64/rtlarch.S",
         "x64/rtlmem.S"
     ];
@@ -91,19 +114,19 @@ function build() {
     // Put together the target sources by architecture.
     //
 
-    boot_sources = sources;
-    if (arch == "x86") {
-        target_sources = sources + x86_sources;
-        intrinsics = x86_intrinsics;
-        boot_sources = sources + x86_sources;
+    bootSources = sources;
+    if (mconfig.arch == "x86") {
+        targetSources = sources + x86Sources;
+        intrinsics = x86Intrinsics;
+        bootSources = sources + x86Sources;
 
-    } else if ((arch == "armv7") || (arch == "armv6")) {
-        target_sources = sources + armv7_sources;
-        intrinsics = armv7_intrinsics;
-        boot_sources = sources + armv7_boot_sources;
+    } else if ((mconfig.arch == "armv7") || (mconfig.arch == "armv6")) {
+        targetSources = sources + armv7Sources;
+        intrinsics = armv7Intrinsics;
+        bootSources = sources + armv7BootSources;
 
-    } else if (arch == "x64") {
-        target_sources = sources + x64_sources;
+    } else if (mconfig.arch == "x64") {
+        targetSources = sources + x64Sources;
         intrinsics = null;
     }
 
@@ -111,18 +134,20 @@ function build() {
     // Put together the build sources by architecture.
     //
 
-    build_sources = sources + wide_sources;
-    if (build_arch == "x86") {
-        build_sources += x86_sources + [
+    buildSources = sources + wideSources;
+    if (mconfig.build_arch == "x86") {
+        buildSources += x86Sources + [
             "fp2int.c",
             "softfp.c"
         ];
 
-    } else if ((build_arch == "armv7") || (build_arch == "armv6")) {
-        build_sources += armv7_sources;
+    } else if ((mconfig.build_arch == "armv7") ||
+               (mconfig.build_arch == "armv6")) {
+
+        buildSources += armv7Sources;
 
-    } else if (build_arch == "x64") {
-        build_sources += + x64_sources + [
+    } else if (mconfig.build_arch == "x64") {
+        buildSources += x64Sources + [
             "fp2int.c",
             "softfp.c"
         ];
@@ -130,7 +155,7 @@ function build() {
 
     entries = [];
     includes = [
-        "$//lib/rtl"
+        "$S/lib/rtl"
     ];
 
     //
@@ -145,19 +170,19 @@ function build() {
         // another binary.
         //
 
-        intrinsics_sources_config = {
+        intrinsicsSourcesConfig = {
             "CPPFLAGS": ["-DRTL_API=__DLLIMPORT"]
         };
 
-        intrinsics_lib = {
+        intrinsicsLib = {
             "label": "intrins",
             "inputs": intrinsics,
-            "sources_config": intrinsics_sources_config,
+            "sources_config": intrinsicsSourcesConfig,
             "includes": includes,
             "prefix": "intrins"
         };
 
-        entries += static_library(intrinsics_lib);
+        entries += staticLibrary(intrinsicsLib);
     }
 
     //
@@ -165,54 +190,53 @@ function build() {
     // version except on ARM it contains no ldrex/strex.
     //
 
-    boot_lib = {
+    bootLib = {
         "label": "basertlb",
-        "inputs": boot_sources,
+        "inputs": bootSources,
         "prefix": "boot",
         "includes": includes,
     };
 
-    entries += static_library(boot_lib);
+    entries += staticLibrary(bootLib);
 
     //
     // Compile the wide library support.
     //
 
-    wide_lib = {
+    wideLib = {
         "label": "basertlw",
-        "inputs": wide_sources,
+        "inputs": wideSources,
         "includes": includes,
     };
 
-    entries += static_library(wide_lib);
+    entries += staticLibrary(wideLib);
 
     //
     // Compile the main Rtl base library.
     //
 
-    basertl_lib = {
+    baseRtlLib = {
         "label": "basertl",
-        "inputs": target_sources,
+        "inputs": targetSources,
         "includes": includes,
     };
 
-    entries += static_library(basertl_lib);
+    entries += staticLibrary(baseRtlLib);
 
     //
     // Compile the build version of the Rtl base library.
     //
 
-    build_basertl_lib = {
+    buildBaseRtlLib = {
         "label": "build_basertl",
         "output": "basertl",
-        "inputs": build_sources,
+        "inputs": buildSources,
         "includes": includes,
         "prefix": "build",
-        "build": TRUE
+        "build": true
     };
 
-    entries += static_library(build_basertl_lib);
+    entries += staticLibrary(buildBaseRtlLib);
     return entries;
 }
 
-return build();

+ 9 - 3
lib/rtl/kmode/build.ck

@@ -25,14 +25,21 @@ Environment:
 
 --*/
 
+from menv import staticLibrary;
+
 function build() {
+    var entries;
+    var includes;
+    var lib;
+    var sources;
+
     sources = [
         "assert.c",
         "kprint.c"
     ];
 
     includes = [
-        "$//lib/rtl"
+        "$S/lib/rtl"
     ];
 
     lib = {
@@ -41,8 +48,7 @@ function build() {
         "includes": includes
     };
 
-    entries = static_library(lib);
+    entries = staticLibrary(lib);
     return entries;
 }
 
-return build();

+ 13 - 7
lib/rtl/rtlc/build.ck

@@ -26,13 +26,21 @@ Environment:
 
 --*/
 
+from menv import staticLibrary;
+
 function build() {
+    var buildLib;
+    var entries;
+    var includes;
+    var lib;
+    var sources;
+
     sources = [
         "stubs.c"
     ];
 
     includes = [
-        "$//lib/rtl"
+        "$S/lib/rtl"
     ];
 
     lib = {
@@ -41,19 +49,17 @@ function build() {
         "includes": includes,
     };
 
-    build_lib = {
+    buildLib = {
         "label": "build_rtlc",
         "output": "rtlc",
         "inputs": sources,
         "includes": includes,
-        "build": TRUE,
+        "build": true,
         "prefix": "build"
     };
 
-    entries = static_library(lib);
-    entries += static_library(build_lib);
+    entries = staticLibrary(lib);
+    entries += staticLibrary(buildLib);
     return entries;
 }
 
-return build();
-

+ 14 - 9
lib/rtl/testrtl/build.ck

@@ -25,7 +25,14 @@ Environment:
 
 --*/
 
+from menv import application;
+
 function build() {
+    var buildApp;
+    var buildLibs;
+    var entries;
+    var sources;
+
     sources = [
         "fpstest.c",
         "fptest.c",
@@ -34,22 +41,20 @@ function build() {
         "timetest.c"
     ];
 
-    build_libs = [
-        "//lib/rtl/rtlc:build_rtlc",
-        "//lib/rtl/base:build_basertl"
+    buildLibs = [
+        "lib/rtl/rtlc:build_rtlc",
+        "lib/rtl/base:build_basertl"
     ];
 
-    build_app = {
+    buildApp = {
         "label": "build_testrtl",
         "output": "testrtl",
-        "inputs": sources + build_libs,
-        "build": TRUE,
+        "inputs": sources + buildLibs,
+        "build": true,
         "prefix": "build"
     };
 
-    entries = application(build_app);
+    entries = application(buildApp);
     return entries;
 }
 
-return build();
-

+ 11 - 5
lib/termlib/build.ck

@@ -25,7 +25,14 @@ Environment:
 
 --*/
 
+from menv import staticLibrary;
+
 function build() {
+    var buildLib;
+    var entries;
+    var lib;
+    var sources;
+
     sources = [
         "term.c"
     ];
@@ -35,17 +42,16 @@ function build() {
         "inputs": sources,
     };
 
-    build_lib = {
+    buildLib = {
         "label": "build_termlib",
         "output": "termlib",
         "inputs": sources,
-        "build": TRUE,
+        "build": true,
         "prefix": "build"
     };
 
-    entries = static_library(lib);
-    entries += static_library(build_lib);
+    entries = staticLibrary(lib);
+    entries += staticLibrary(buildLib);
     return entries;
 }
 
-return build();

+ 11 - 5
lib/yy/build.ck

@@ -27,7 +27,14 @@ Environment:
 
 --*/
 
+from menv import staticLibrary;
+
 function build() {
+    var buildLib;
+    var entries;
+    var lib;
+    var sources;
+
     sources = [
         "lex.c",
         "parse.c"
@@ -38,17 +45,16 @@ function build() {
         "inputs": sources,
     };
 
-    build_lib = {
+    buildLib = {
         "label": "build_yy",
         "output": "yy",
         "inputs": sources,
-        "build": TRUE,
+        "build": true,
         "prefix": "build"
     };
 
-    entries = static_library(lib);
-    entries += static_library(build_lib);
+    entries = staticLibrary(lib);
+    entries += staticLibrary(buildLib);
     return entries;
 }
 
-return build();

+ 62 - 0
lib/yy/gen/build.ck

@@ -0,0 +1,62 @@
+/*++
+
+Copyright (c) 2017 Minoca Corp.
+
+    This file is licensed under the terms of the GNU General Public License
+    version 3. Alternative licensing terms are available. Contact
+    info@minocacorp.com for details. See the LICENSE file at the root of this
+    project for complete licensing information.
+
+Module Name:
+
+    Lex/Parse LALR(1) Library
+
+Abstract:
+
+    This module implements support for an LALR(1) grammar parser generator.
+
+Author:
+
+    Evan Green 3-Feb-2017
+
+Environment:
+
+    Any
+
+--*/
+
+from menv import staticLibrary;
+
+function build() {
+    var buildLib;
+    var entries;
+    var lib;
+    var sources;
+
+    sources = [
+        "lalr.c",
+        "lr0.c",
+        "output.c",
+        "parcon.c",
+        "verbose.c",
+        "yygen.c"
+    ];
+
+    lib = {
+        "label": "yygen",
+        "inputs": sources,
+    };
+
+    buildLib = {
+        "label": "build_yygen",
+        "output": "yy",
+        "inputs": sources,
+        "build": true,
+        "prefix": "build"
+    };
+
+    entries = staticLibrary(lib);
+    entries += staticLibrary(buildLib);
+    return entries;
+}
+

+ 15 - 10
lib/yy/yytest/build.ck

@@ -26,28 +26,33 @@ Environment:
 
 --*/
 
+from menv import application;
+
 function build() {
+    var buildApp;
+    var buildLibs;
+    var entries;
+    var sources;
+
     sources = [
         "yytest.c"
     ];
 
-    build_libs = [
-        "//lib/yy:build_yy",
-        "//lib/rtl/rtlc:build_rtlc",
-        "//lib/rtl/base:build_basertl"
+    buildLibs = [
+        "lib/yy:build_yy",
+        "lib/rtl/rtlc:build_rtlc",
+        "lib/rtl/base:build_basertl"
     ];
 
-    build_app = {
+    buildApp = {
         "label": "build_yytest",
         "output": "yytest",
-        "inputs": sources + build_libs,
-        "build": TRUE,
+        "inputs": sources + buildLibs,
+        "build": true,
         "prefix": "build"
     };
 
-    entries = application(build_app);
+    entries = application(buildApp);
     return entries;
 }
 
-return build();
-

+ 1369 - 0
menv.ck

@@ -0,0 +1,1369 @@
+/*++
+
+Copyright (c) 2017 Minoca Corp.
+
+    This file is licensed under the terms of the GNU General Public License
+    version 3. Alternative licensing terms are available. Contact
+    info@minocacorp.com for details. See the LICENSE file at the root of this
+    project for complete licensing information.
+
+Module Name:
+
+    env.ck
+
+Abstract:
+
+    This build module contains the environment and functions used throughout
+    the Minoca OS build.
+
+Author:
+
+    Evan Green 1-Feb-2017
+
+Environment:
+
+    Build
+
+--*/
+
+//
+// -------------------------------------------------------------------- Imports
+//
+
+from mingen import config;
+from os import getenv, basename;
+
+//
+// -------------------------------------------------------------------- Globals
+//
+
+var mconfig;
+
+//
+// ------------------------------------------------------------------ Functions
+//
+
+function
+initListFromEnvironment (
+    name,
+    default
+    )
+
+/*++
+
+Routine Description:
+
+    This routine gets an environment variable. It either returns that
+    environment variable wrapped in a list, or the given default.
+
+Arguments:
+
+    name - Supplies the name of the environment variable.
+
+    default - Supplies the default value to return if not set.
+
+Return Value:
+
+    Returns eithe the provided default or has the contents of the environment
+    variable wrapped in a list.
+
+--*/
+
+{
+
+    var value = getenv(name);
+
+    if (value != null) {
+        return [value];
+    }
+
+    return default;
+}
+
+function
+setupEnv (
+    )
+
+/*++
+
+Routine Description:
+
+    This routine is called once to set up the build environment.
+
+Arguments:
+
+    None.
+
+Return Value:
+
+    None.
+
+--*/
+
+{
+
+    var archVariant;
+
+    //
+    // Prefer Ninja files.
+    //
+
+    config.format ?= "ninja";
+
+    //
+    // Set up the Minoca config dictionary.
+    //
+
+    mconfig = {};
+    mconfig.build_os = config.build_os;
+    mconfig.build_machine = config.build_machine;
+    mconfig.build_variant = "";
+    if (mconfig.build_machine == "i686") {
+        mconfig.build_arch = "x86";
+
+    } else if (mconfig.build_machine == "i586") {
+        mconfig.build_arch = "x86";
+        mconfig.build_variant = "q";
+
+    } else if ((mconfig.build_machine == "armv7") ||
+               (mconfig.build_machine == "armv6")) {
+
+        mconfig.build_arch = mconfig.build_machine;
+
+    } else if (mconfig.build_machine == "x86_64") {
+        mconfig.build_arch = "x64";
+    }
+
+    mconfig.arch = getenv("ARCH");
+    mconfig.arch ?= mconfig.build_arch;
+    mconfig.arch ?= "x86";
+    mconfig.debug = getenv("DEBUG");
+    mconfig.debug ?= "dbg";
+    mconfig.variant = getenv("VARIANT");
+    mconfig.variant ?= mconfig.build_variant;
+    mconfig.release_level = "SystemReleaseDevelopment";
+    mconfig.cflags = initListFromEnvironment("CFLAGS",
+                                             ["-O2", "-Wall", "-Werror"]);
+
+    mconfig.cppflags = initListFromEnvironment("CPPFLAGS", []);
+    mconfig.ldflags = initListFromEnvironment("LDFLAGS", []);
+    mconfig.asflags = initListFromEnvironment("ASFLAGS", []);
+    mconfig.stripflags = initListFromEnvironment("STRIP_FLAGS", []);
+    mconfig.build_cc = getenv("BUILD_CC");
+    mconfig.build_cc ?= "gcc";
+    mconfig.build_ar = getenv("BUILD_AR");
+    mconfig.build_ar ?= "ar";
+    mconfig.build_strip = getenv("BUILD_STRIP");
+    mconfig.build_strip ?= "strip";
+    config.output ?= "$S/../" + mconfig.arch + mconfig.variant + mconfig.debug +
+                     "/obj/os";
+
+    mconfig.outroot = "$O/../..";
+    mconfig.binroot = mconfig.outroot + "/bin";
+    mconfig.stripped = mconfig.binroot + "/stripped";
+    mconfig.cc = getenv("CC");
+    mconfig.ar = getenv("AR");
+    mconfig.objcopy = getenv("OBJCOPY");
+    mconfig.strip = getenv("STRIP");
+    mconfig.rcc = getenv("RCC");
+    mconfig.rcc ?= "windres";
+    mconfig.iasl = getenv("IASL");
+    mconfig.iasl ?= "iasl";
+    mconfig.shell = getenv("SHELL");
+    mconfig.shell ?= "sh";
+    mconfig.target = null;
+
+    //
+    // Add in the command line variables, then define the derived variables.
+    //
+
+    for (key in config.cmdvars) {
+        mconfig[key] = config.cmdvars[key];
+    }
+
+    archVariant = mconfig.arch + mconfig.variant;
+    if (!mconfig.target) {
+        if (archVariant == "x86") {
+            mconfig.target = "i686-pc-minoca";
+
+        } else if (archVariant == "x86q") {
+            mconfig.target = "i586-pc-minoca";
+
+        } else if ((mconfig.arch == "armv7") || (mconfig.arch == "armv6")) {
+            mconfig.target = "arm-none-minoca";
+
+        } else if (mconfig.arch == "x64") {
+            mconfig.target = "x86_64-none-minoca";
+
+        } else {
+            Core.raise(ValueError("Unknown architecture" + mconfig.arch));
+        }
+    }
+
+    mconfig.native = false;
+    if ((mconfig.build_os == "Minoca") &&
+        (mconfig.arch == mconfig.build_arch)) {
+
+        mconfig.native = true;
+    }
+
+    if (mconfig.native) {
+        mconfig.cc ?= mconfig.build_cc;
+        mconfig.ar ?= mconfig.build_ar;
+        mconfig.strip ?= mconfig.build_strip;
+        mconfig.objcopy ?= "objcopy";
+
+    } else {
+        mconfig.cc ?= mconfig.target + "-gcc";
+        mconfig.ar ?= mconfig.target + "-ar";
+        mconfig.strip ?= mconfig.target + "-strip";
+        mconfig.objcopy ?= mconfig.target + "-objcopy";
+    }
+
+    if (mconfig.debug == "dbg") {
+        mconfig.cflags += ["-DDEBUG=1"];
+
+    } else {
+        mconfig.cflags += ["-Wno-unused-but-set-variable", "-DNDEBUG"];
+    }
+
+    mconfig.cflags += ["-fno-builtin",
+                       "-g",
+                       "-save-temps=obj",
+                       "-ffunction-sections",
+                       "-fdata-sections",
+                       "-fvisibility=hidden"];
+
+    mconfig.cppflags += ["-I$S/include"];
+    mconfig.build_cflags = [] + mconfig.cflags;
+    mconfig.build_cppflags = [] + mconfig.cppflags;
+    mconfig.cflags += ["-fpic"];
+
+    //
+    // Windows cannot handle -fpic, but everyone else can.
+    //
+
+    if (mconfig.build_os != "Windows") {
+        mconfig.build_cflags += ["-fpic"];
+    }
+
+    //
+    // Add some architecture variant flags.
+    //
+
+    if (archVariant == "x86q") {
+        mconfig.cppflags += ["-Wa,-momit-lock-prefix=yes", "-march=i586"];
+
+    } else if (archVariant == "armv6") {
+        mconfig.cflags += ["-march=armv6zk", "-marm", "-mfpu=vfp"];
+    }
+
+    mconfig.asflags += ["-Wa,-g"];
+    mconfig.build_ldflags = initListFromEnvironment("BUILD_LDFLAGS",
+                                                    [] + mconfig.ldflags);
+
+    mconfig.ldflags += ["-Wl,--gc-sections"];
+
+    //
+    // Mac OS cannot handle --gc-sections or strip -p.
+    //
+
+    if (mconfig.build_os != "Darwin") {
+        mconfig.build_ldflags += ["-Wl,--gc-sections"];
+        mconfig.stripflags += ["-p"];
+    }
+
+    //
+    // Define the set of variables that get passed all the way through to the
+    // final Make/ninja file. Passing these on as variables rather than
+    // substituting during the mingen build process allows for a smaller
+    // build file, and easier manual tweaking by the user.
+    //
+
+    config.vars = {
+        "BUILD_CC": mconfig.build_cc,
+        "BUILD_AR": mconfig.build_ar,
+        "BUILD_STRIP": mconfig.build_strip,
+        "CC": mconfig.cc,
+        "AR": mconfig.ar,
+        "STRIP": mconfig.strip,
+        "OBJCOPY": mconfig.objcopy,
+        "RCC": mconfig.rcc,
+        "IASL": mconfig.iasl,
+        "SHELL": mconfig.shell,
+        "BASE_CFLAGS": mconfig.cflags,
+        "BASE_CPPFLAGS": mconfig.cppflags,
+        "BASE_LDFLAGS": mconfig.ldflags,
+        "BASE_ASFLAGS": mconfig.asflags,
+        "BUILD_BASE_CFLAGS": mconfig.build_cflags,
+        "BUILD_BASE_CPPFLAGS": mconfig.build_cppflags,
+        "BUILD_BASE_LDFLAGS": mconfig.build_ldflags,
+        "BUILD_BASE_ASFLAGS": mconfig.asflags,
+        "STRIP_FLAGS": mconfig.stripflags,
+        "IASL_FLAGS": ["-we"]
+    };
+
+    if (config.verbose) {
+        Core.print("Minoca Build Configuration:");
+        for (key in mconfig) {
+            Core.print("\t%s: %s" % [key, mconfig[key].__str()]);
+        }
+    }
+
+    return;
+}
+
+function
+addConfig (
+    entry,
+    name,
+    value
+    )
+
+/*++
+
+Routine Description:
+
+    This routine adds a configure option to a list, ensuring that both the
+    config dictionary and option already exist.
+
+Arguments:
+
+    entry - Supplies the entry to add the configure option to.
+
+    name - Supplies the name of the option to add.
+
+    value - Supplies the new value to add to the list of options.
+
+Return Value:
+
+    None.
+
+--*/
+
+{
+
+    if (!entry.get("config")) {
+        entry.config = {};
+    }
+
+    if (!entry.config.get(name)) {
+        entry.config[name] = [];
+    }
+
+    entry.config[name] += [value];
+    return;
+}
+
+function
+group (
+    name,
+    entries
+    )
+
+/*++
+
+Routine Description:
+
+    This routine creates a phony target that groups a bunch of different
+    targets together under a common name.
+
+Arguments:
+
+    name - Supplies the name of the new group target.
+
+    entries - Supplies the list of entries.
+
+Return Value:
+
+    Returns a list containing the entry for the group target.
+
+--*/
+
+{
+    var entry = {
+        "label": name,
+        "type": "target",
+        "tool": "phony",
+        "inputs": entries,
+        "config": {}
+    };
+
+    return [entry];
+}
+
+function
+copy (
+    source,
+    destination,
+    destination_label,
+    flags,
+    mode
+    )
+
+/*++
+
+Routine Description:
+
+    This routine creates a target that copies a file from one place to another.
+
+Arguments:
+
+    source - Supplies the source to copy.
+
+    destination - Supplies the copy destination.
+
+    destination_label - Supplies a label naming the copy target.
+
+    flags - Supplies the flags to include in the copy.
+
+    mode - Supplies the chmod mode of the destination.
+
+Return Value:
+
+    Returns a list containing the copy entry.
+
+--*/
+
+{
+
+    var config = {};
+
+    if (flags) {
+        config["CPFLAGS"] = flags;
+    }
+
+    if (mode) {
+        config["CHMOD_FLAGS"] = mode;
+    }
+
+    var entry = {
+        "type": "target",
+        "tool": "copy",
+        "label": destination_label,
+        "inputs": [source],
+        "output": destination,
+        "config": config
+    };
+
+    if (!destination_label) {
+        entry["label"] = destination;
+    }
+
+    return [entry];
+}
+
+function
+strip (
+    params
+    )
+
+/*++
+
+Routine Description:
+
+    This routine converts an entry to a strip entry, where the target will be
+    stripped.
+
+Arguments:
+
+    params - Supplies the existing entry.
+
+Return Value:
+
+    Returns a list containing the strip entry.
+
+--*/
+
+{
+
+    params.type = "target";
+    params.tool = "strip";
+    if (params.get("build")) {
+        params.tool = "build_strip";
+    }
+
+    return [params];
+}
+
+function
+binplace (
+    params
+    )
+
+/*++
+
+Routine Description:
+
+    This routine replaces the current target with a copied version in the
+    final bin directory. This will also create a stripped version in the
+    stripped directory unless told not to.
+
+Arguments:
+
+    params - Supplies the existing entry.
+
+Return Value:
+
+    Returns a list containing the strip entry.
+
+--*/
+
+{
+
+    var build = params.get("build");
+    var copiedEntry;
+    var cpflags = params.get("cpflags");;
+    var destination;
+    var entries;
+    var fileName;
+    var label = params.get("label");
+    var mode = params.get("mode");
+    var newOriginalLabel;
+    var originalTarget;
+    var source = params.get("output");
+    var StrippedEntry;
+    var strippedOutput;
+
+    label ?= source;
+    source ?= label;
+    if ((!label) || (!source)) {
+        Core.raise(ValueError("Label or output must be defined"));
+    }
+
+    //
+    // Set the output since the label is going to be renamed and create the
+    // copy target.
+    //
+
+    params.output = source;
+    fileName = basename(source);
+    if (build) {
+        destination = mconfig.binroot + "/tools/bin/" + fileName;
+
+    } else {
+        destination = mconfig.binroot + "/" + fileName;
+    }
+
+    newOriginalLabel = label + "_orig";
+    originalTarget = ":" + newOriginalLabel;
+    copiedEntry = copy(originalTarget, destination, label, cpflags, mode)[0];
+
+    //
+    // The original label was given to the copied destination, so tack a _orig
+    // on the source label.
+    //
+
+    params.label = newOriginalLabel;
+    entries = [copiedEntry, params];
+
+    //
+    // Unless asked not to, create a stripped entry as well.
+    //
+
+    if (!params.get("nostrip")) {
+        if (build) {
+            strippedOutput = mconfig.stripped + "/build/" + fileName;
+
+        } else {
+            strippedOutput = mconfig.stripped + "/" + fileName;
+        }
+
+        StrippedEntry = {
+            "label": label + "_stripped",
+            "inputs": [originalTarget],
+            "output": strippedOutput,
+            "build": build,
+        };
+
+        //
+        // Make the binplaced copy depend on the stripped version.
+        //
+
+        copiedEntry.implicit = [":" + StrippedEntry["label"]];
+        entries += strip(StrippedEntry);
+    }
+
+    return entries;
+}
+
+function
+compiledSources (
+    params
+    )
+
+/*++
+
+Routine Description:
+
+    This routine compiles a group of object file targets from source files.
+
+Arguments:
+
+    params - Supplies the entry with inputs filled out.
+
+Return Value:
+
+    Returns the list containing a list of object names, and a list of object
+    targets.
+
+--*/
+
+{
+
+    var build = params.get("build");
+    var entries = [];
+    var ext;
+    var includes = params.get("includes");
+    var inputParts;
+    var inputs = params.inputs;
+    var objName;
+    var obj;
+    var objs = [];
+    var sourcesConfig = params.get("sources_config");
+    var prefix = params.get("prefix");
+    var suffix;
+    var tool;
+
+    if (includes) {
+        sourcesConfig ?= {};
+        if (!sourcesConfig.get("CPPFLAGS")) {
+            sourcesConfig.CPPFLAGS = [];
+        }
+
+        for (include in includes) {
+            sourcesConfig["CPPFLAGS"] += ["-I" + include];
+        }
+    }
+
+    if (inputs.length() == 0) {
+        Core.raise(ValueError("Compilation must have inputs"));
+    }
+
+    for (input in inputs) {
+        inputParts = input.rsplit(".", 1);
+        try {
+            ext = inputParts[1];
+
+        } except IndexError {
+            ext = "";
+        }
+
+        suffix = ".o";
+        if (ext == "c") {
+            tool = "cc";
+
+        } else if (ext == "cc") {
+            tool = "cxx";
+
+        } else if (ext == "S") {
+            tool = "as";
+
+        } else if (ext == "rc") {
+            tool = "rcc";
+            suffix = ".rsc";
+
+        } else {
+            objs += [input];
+            continue;
+        }
+
+        if (build) {
+            tool = "build_" + tool;
+        }
+
+        objName = inputParts[0] + suffix;
+        if (prefix) {
+            objName = prefix + "/" + objName;
+        }
+
+        obj = {
+            "type": "target",
+            "label": objName,
+            "output": objName,
+            "inputs": [input],
+            "tool": tool,
+            "config": sourcesConfig,
+        };
+
+        entries += [obj];
+        objs += [":" + objName];
+    }
+
+    if (prefix) {
+        if (!params.get("output")) {
+            params.output = params.label;
+        }
+
+        params.output = prefix + "/" + params.output;
+    }
+
+    return [objs, entries];
+}
+
+function
+executable (
+    params
+    )
+
+/*++
+
+Routine Description:
+
+    This routine links a set of sources into some sort of executable or shared
+    object.
+
+Arguments:
+
+    params - Supplies the entry with inputs filled out.
+
+Return Value:
+
+    Returns the list of the linked entry.
+
+--*/
+
+{
+
+    var build = params.get("build");
+    var entry = params.get("entry");
+    var compilation = compiledSources(params);
+    var linkerScript = params.get("linker_script");
+    var objs = compilation[0];
+    var entries = compilation[1];
+    var textAddress = params.get("text_address");;
+
+    params.type = "target";
+    params.inputs = objs;
+    params.tool = "ld";
+    if (build) {
+        params.tool = "build_ld";
+    }
+
+    //
+    // Convert options for text_address, linker_script, and entry to actual
+    // LDFLAGS.
+    //
+
+    if (textAddress) {
+        addConfig(params, "LDFLAGS", "-Wl,-Ttext-segment=" + textAddress);
+        addConfig(params, "LDFLAGS", "-Wl,-Ttext=" + textAddress);
+    }
+
+    if (linkerScript) {
+        addConfig(params, "LDFLAGS", "-Wl,-T" + linkerScript);
+    }
+
+    if (entry != null) {
+        addConfig(params, "LDFLAGS", "-Wl,-e" + entry);
+        addConfig(params, "LDFLAGS", "-Wl,-u" + entry);
+    }
+
+    if (params.get("binplace")) {
+        entries += binplace(params);
+
+    } else {
+        entries += [params];
+    }
+
+    return entries;
+}
+
+function
+application (
+    params
+    )
+
+/*++
+
+Routine Description:
+
+    This routine creates a position independent application.
+
+Arguments:
+
+    params - Supplies the entry with inputs filled out.
+
+Return Value:
+
+    Returns the list of the application entry.
+
+--*/
+
+{
+
+    var build = params.get("build");
+    var exename = params.get("output");
+
+    exename ?= params.get("label");
+    if (!exename) {
+        Core.raise(ValueError("Missing output or label"));
+    }
+
+    if (build && (mconfig.build_os == "Windows")) {
+        params.output = exename + ".exe";
+    }
+
+    if (build && (mconfig.build_os == "Darwin")) {
+        addConfig(params, "LDFLAGS", "-Wl,-pie");
+
+    } else {
+        addConfig(params, "LDFLAGS", "-pie");
+    }
+
+    params.binplace = true;
+    return executable(params);
+}
+
+function
+sharedLibrary (
+    params
+    )
+
+/*++
+
+Routine Description:
+
+    This routine creates a shared library or DLL.
+
+Arguments:
+
+    params - Supplies the entry with inputs filled out.
+
+Return Value:
+
+    Returns the list of the application entry.
+
+--*/
+
+{
+
+    var build = params.get("build");
+    var majorVersion = params.get("major_version");
+    var minorVersion = params.get("minor_version");
+    var soname = params.get("soname");
+
+    soname ?= params.get("output");
+    soname ?= params.get("label");
+    if (!soname) {
+        Core.raise(ValueError(
+                          "One of output, label, or soname must be defined."));
+    }
+
+    //
+    // Darwin shared libraries build with a whole different ballgame of options.
+    //
+
+    if (build && (mconfig.build_os == "Darwin")) {
+        majorVersion ?= 0;
+        minorVersion ?= 0;
+        addConfig(params,
+                  "LDFLAGS",
+                  "-undefined dynamic_lookup -dynamiclib");
+
+        addConfig(params,
+                  "LDFLAGS",
+                  "-current_version %d.%d" % [majorVersion, minorVersion]);
+
+        addConfig(params,
+                  "LDFLAGS",
+                  "-compatibility_version %d.%d" % [majorVersion, 0]);
+
+
+    } else {
+        addConfig(params, "LDFLAGS", "-shared");
+        if ((!build) || (mconfig.build_os != "Windows")) {
+            soname += ".so";
+            if (majorVersion != null) {
+                soname += "." + majorVersion;
+            }
+
+            addConfig(params, "LDFLAGS", "-Wl,-soname=" + soname);
+
+        } else {
+            soname += ".dll";
+        }
+    }
+
+    params.output = soname;
+    params.binplace = true;
+    return executable(params);
+}
+
+function
+staticLibrary (
+    params
+    )
+
+/*++
+
+Routine Description:
+
+    This routine creates a static library.
+
+Arguments:
+
+    params - Supplies the entry with inputs filled out.
+
+Return Value:
+
+    Returns the list of the application entry.
+
+--*/
+
+{
+
+    var build = params.get("build");
+    var compilation = compiledSources(params);
+    var objs = compilation[0];
+    var output;
+    var entries = compilation[1];
+
+    params.type = "target";
+    output = params.get("output");
+    output ?= params.get("label");
+    if (!output) {
+        Core.raise(ValueError("output or label must be defined"));
+    }
+
+    params.output = output + ".a";
+    params.inputs  = objs;
+    params.tool = "ar";
+    if (build) {
+        params.tool = "build_ar";
+    }
+
+    if (params.get("binplace")) {
+        entries += binplace(params);
+
+    } else {
+        entries += [params];
+    }
+
+    return entries;
+}
+
+function
+compiledAsl (
+    inputs
+    )
+
+/*++
+
+Routine Description:
+
+    This routine creates a list of compiled .aml files from a list of .asl
+    files.
+
+Arguments:
+
+    params - Supplies the entry with inputs filled out.
+
+Return Value:
+
+    Returns a list where the first element is a list of all the resulting
+    target names, and the second element is a list of the target entries.
+
+--*/
+
+{
+
+    var entries = [];
+    var ext;
+    var inputParts;
+    var objName;
+    var obj;
+    var objs = [];
+
+    if (inputs.length() == 0) {
+        Core.raise(ValueError("Compilation must have inputs"));
+    }
+
+    for (input in inputs) {
+        inputParts = input.rsplit(".", 1);
+        ext = inputParts[1];
+        objName = inputParts[0] + ".aml";
+        obj = {
+            "type": "target",
+            "label": objName,
+            "output": objName,
+            "inputs": [input],
+            "tool": "iasl"
+        };
+
+        entries += [obj];
+        objs += [":" + objName];
+    }
+
+    return [objs, entries];
+}
+
+function
+objectifiedBinaries (
+    params
+    )
+
+/*++
+
+Routine Description:
+
+    This routine creates a group of object file targets from binary files.
+
+Arguments:
+
+    params - Supplies the entry with inputs filled out.
+
+Return Value:
+
+    Returns a list of object names in the first element and the object file
+    target entries in the second element.
+
+--*/
+
+{
+
+    var build = params.get("build");
+    var entries = [];
+    var inputs = params.inputs;
+    var obj;
+    var objcopyConfig = params.get("config");
+    var objName;
+    var objs = [];
+    var prefix = params.get("prefix");
+    var tool;
+
+    if (inputs.length() == 0) {
+        Core.raise(ValueError("Compilation must have inputs"));
+    }
+
+    for (input in inputs) {
+        tool = "objcopy";
+        if (build) {
+            tool = "build_objcopy";;
+        }
+
+        objName = input + ".o";
+        if (prefix) {
+            objName = prefix + "/" + objName;
+        }
+
+        obj = {
+            "type": "target",
+            "label": objName,
+            "output": objName,
+            "inputs": [input],
+            "tool": tool,
+            "config": objcopyConfig,
+        };
+
+        entries += [obj];
+        objs += [":" + objName];
+    }
+
+    if (prefix) {
+        params.output ?= params.label;
+        params.output = prefix + "/" + params.output;
+    }
+
+    return [objs, entries];
+}
+
+function
+objectifiedBinary (
+    params
+    )
+
+/*++
+
+Routine Description:
+
+    This routine creates a single object file from a binary file.
+
+Arguments:
+
+    params - Supplies the entry with inputs filled out.
+
+Return Value:
+
+    Returns a list of the object file.
+
+--*/
+
+{
+    return objectifiedBinaries(params)[1];
+}
+
+function
+objectifiedLibrary (
+    params
+    )
+
+/*++
+
+Routine Description:
+
+    This routine creates a library from a set of objectified files.
+
+Arguments:
+
+    params - Supplies the entry with inputs filled out.
+
+Return Value:
+
+    Returns a list of the object file.
+
+--*/
+
+{
+
+    var build = params.get("build");
+    var compilation = objectifiedBinaries(params);
+    var objs = compilation[0];
+    var entries = compilation[1];
+    var output = params.get("output");
+
+    params.type = "target";
+    output ?= params.label;
+    params.output = output + ".a";
+    params.inputs = objs;
+    params.tool = "ar";
+    if (build) {
+        params.tool = "build_ar";
+    }
+
+    entries += [params];
+    return entries;
+}
+
+//
+// Create a flat binary from an executable image.
+//
+
+function
+flattenedBinary (
+    params
+    )
+
+/*++
+
+Routine Description:
+
+    This routine creates a flat binary from an executable image.
+
+Arguments:
+
+    params - Supplies the entry with inputs filled out.
+
+Return Value:
+
+    Returns a list of the flat binary.
+
+--*/
+
+{
+
+    var entries;
+
+    params.type = "target";
+    params.tool = "objcopy";
+    addConfig(params, "OBJCOPY_FLAGS", "-O binary");
+    if (params.get("binplace")) {
+        params.nostrip = true;
+        entries = binplace(params);
+
+    } else {
+        entries = [params];
+    }
+
+    return entries;
+}
+
+function
+driver (
+    params
+    )
+
+/*++
+
+Routine Description:
+
+    This routine creates a Minoca kernel driver.
+
+Arguments:
+
+    params - Supplies the entry with inputs filled out.
+
+Return Value:
+
+    Returns a list of the driver entry.
+
+--*/
+
+{
+
+    var soname = params.get("output");
+
+    params.entry ?= "DriverEntry";
+    params.binplace = true;
+
+    soname ?= params.get("label");
+    if (soname != "kernel") {
+        soname += ".drv";
+        params.output = soname;
+        params.inputs += ["kernel:kernel"];
+    }
+
+    addConfig(params, "LDFLAGS", "-shared");
+    addConfig(params, "LDFLAGS", "-Wl,-soname=" + soname);
+    addConfig(params, "LDFLAGS", "-nostdlib");
+    return executable(params);
+}
+
+function
+uefiRuntimeFfs (
+    name
+    )
+
+/*++
+
+Routine Description:
+
+    This routine creates a runtime driver .FFS file from an ELF file.
+
+Arguments:
+
+    params - Supplies the entry with inputs filled out.
+
+Return Value:
+
+    Returns a list of the .FFS entry.
+
+--*/
+
+{
+
+    var elfconvConfig;
+    var ffs;
+    var pe;
+
+    elfconvConfig = {
+        "ELFCONV_FLAGS": "-t efiruntimedriver"
+    };
+
+    pe = {
+        "type": "target",
+        "label": name,
+        "inputs": [":" + name + ".elf"],
+        "implicit": ["uefi/tools/elfconv:elfconv"],
+        "tool": "elfconv",
+        "config": elfconvConfig
+    };
+
+    ffs = {
+        "type": "target",
+        "label": name + ".ffs",
+        "inputs": [":" + name],
+        "implicit": ["uefi/tools/genffs:genffs"],
+        "tool": "genffs_runtime"
+    };
+
+    return [pe, ffs];
+}
+
+function
+uefiFwvol (
+    name,
+    ffs
+    )
+
+/*++
+
+Routine Description:
+
+    This routine creates a UEFI firmware volume object file based on a platform
+    name and a list of FFS inputs.
+
+Arguments:
+
+    params - Supplies the entry with inputs filled out.
+
+Return Value:
+
+    Returns a list of the firmware volume entry.
+
+--*/
+
+{
+
+    var fwv;
+    var fwvO;
+    var fwvName = name + "fwv";
+
+    fwv = {
+        "type": "target",
+        "label": fwvName,
+        "inputs": ffs,
+        "implicit": ["uefi/tools/genfv:genfv"],
+        "tool": "genfv"
+    };
+
+    fwvO = compiledSources({"inputs": [fwvName + ".S"]});
+    return [fwv] + fwvO;
+}
+
+//
+// Define a function that creates a version.h file target.
+//
+
+function
+createVersionHeader (
+    major,
+    minor,
+    revision
+    )
+
+/*++
+
+Routine Description:
+
+    This routine creates a version.h header that includes aspects of the
+    build environment.
+
+Arguments:
+
+    major - Supplies the major number.
+
+    minor - Supplies the minor number.
+
+    revision - Supplies the revision.
+
+Return Value:
+
+    Returns a list of the firmware volume entry.
+
+--*/
+
+{
+
+    var versionConfig;
+    var versionH;
+
+    versionConfig = {
+        "FORM": "header",
+        "MAJOR": major,
+        "MINOR": minor,
+        "REVISION": revision,
+        "RELEASE": mconfig.release_level
+    };
+
+    versionH = {
+        "type": "target",
+        "output": "version.h",
+        "inputs": ["$S/.git/HEAD"],
+        "tool": "gen_version",
+        "config": versionConfig
+    };
+
+    return [versionH];
+}
+