Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 135 lines (107 sloc) 4.484 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
/*
* Jakefile
* Objective-J
*
* Created by Francisco Tolmasky.
* Copyright 2009, 280 North, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

require("../common.jake");

var FILE = require("file"),
    OS = require("os"),
    stream = require("narwhal/term").stream;

//$BUILD_CONFIGURATION_DIR = "../Build"
$BROWSER_FILE = FILE.join("Browser", "Objective-J.js");

$BUILD_OBJECTIVE_J = FILE.join($BUILD_CONFIGURATION_DIR, "Objective-J");
$BUILD_BROWSER_FILE = FILE.join($BUILD_OBJECTIVE_J, "Objective-J.js");

$INCLUDE_FLAGS = ["-I" + FILE.cwd()];
$DEBUG_FLAGS = $CONFIGURATION === "Debug" ? ["-DDEBUG=1"] : [""];
$OBJECTIVEJ_FILES = new FileList("*.js");

$BROWSER_FILES = new FileList($BROWSER_FILE).include($OBJECTIVEJ_FILES);

filedir($BUILD_BROWSER_FILE, $BROWSER_FILES, function(aTask)
{
    gcc($BROWSER_FILE,
        $BUILD_BROWSER_FILE,
        environmentFlags("Browser", "ObjJ").concat($INCLUDE_FLAGS, $DEBUG_FLAGS), $CONFIGURATION !== "Debug");
});

$LICENSE = FILE.join("CommonJS", "lib", "objective-j", "jake", "LICENSES", "LGPL-v2.1");
$BUILD_LICENSE = FILE.join($BUILD_OBJECTIVE_J, "LICENSE");

filedir($BUILD_LICENSE, [$LICENSE], function()
{
    FILE.copy($LICENSE, $BUILD_LICENSE);
});

new FileList("CommonJS/**/*").forEach(function(aFilename)
{
    // . files should be left out of FileList...
    if (!FILE.isFile(aFilename) || FILE.basename(aFilename).charAt(0) === ".")
        return;

    var buildFilename = FILE.join($BUILD_CJS_OBJECTIVE_J, FILE.relative("CommonJS/", aFilename));

    filedir (buildFilename, new FileList(aFilename).include($OBJECTIVEJ_FILES), function ()
    {
        if (FILE.extension(aFilename) !== ".js")
        {
            stream.print("Copying... \0green(" + aFilename +"\0)");
            cp(aFilename, buildFilename);
        }
        else
            gcc(aFilename,
                buildFilename,
                environmentFlags("CommonJS", "ObjJ").concat($INCLUDE_FLAGS, $DEBUG_FLAGS), false);
    });

    // HACK: narwhal should copy permissions
    if (FILE.dirname(aFilename) === FILE.join("CommonJS", "bin"))
    {
        filedir (buildFilename, function ()
        {
            FILE.chmod(buildFilename, 0755);
        });
    }

    task ("build", buildFilename);
    CLOBBER.include(buildFilename);
});

task ("build", function() {
    setPackageMetadata(FILE.join($BUILD_CJS_OBJECTIVE_J, "package.json"));
});

$BUILD_CJS_OBJECTIVE_J_FRAMEWORK = FILE.join($BUILD_CJS_OBJECTIVE_J, "Frameworks", "Objective-J");

filedir($BUILD_CJS_OBJECTIVE_J_FRAMEWORK, function()
{
    cp_r($BUILD_OBJECTIVE_J, $BUILD_CJS_OBJECTIVE_J_FRAMEWORK);
});

CLOBBER.include($BUILD_OBJECTIVE_J);

function environmentFlags()
{
    var environments = Array.prototype.slice.call(arguments)

    return environments.map(function(anEnvironment) {
        return "-D" + anEnvironment.toUpperCase();
    }).concat("-DENVIRONMENTS=" + OS.enquote(JSON.stringify(environments)));
}

var SHRINKSAFE = require("minify/shrinksafe");
function compressor(code) {
    return SHRINKSAFE.compress(code, { charset : "UTF-16", useServer : true });
}

function gcc(inputFilePath, outputFilePath, flags, compress)
{
    stream.print("Building... \0green(" + outputFilePath +"\0)");

    // GCC preprocess the file.
    var cmd = ["gcc", "-E", "-x", "c", "-P"].concat(flags, inputFilePath).join(" ");
    var gcc = OS.popen(cmd, { charset:"UTF-8" });

    var contents = FILE.read("header.txt", { charset : "UTF-8" });
    contents += gcc.stdout.read();

    if (FILE.extension(inputFilePath) === ".js" && compress)
        contents = compressor(contents);

    FILE.write(outputFilePath, contents, { charset : "UTF-8" });
}

task("build", [$BUILD_BROWSER_FILE, $BUILD_LICENSE, $BUILD_CJS_OBJECTIVE_J_FRAMEWORK]);
Something went wrong with that request. Please try again.