mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-26 05:27:03 +00:00
139 lines
4.6 KiB
JavaScript
139 lines
4.6 KiB
JavaScript
/*
|
|
* 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
|
|
*/
|
|
|
|
var FILE = require("file"),
|
|
OS = require("os"),
|
|
stream = require("term").stream;
|
|
|
|
require("../common.jake");
|
|
//$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();
|
|
$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") + $INCLUDE_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") + $INCLUDE_FLAGS, false);
|
|
});
|
|
|
|
if (FILE.dirname(aFilename) === FILE.join("CommonJS", "bin"))
|
|
{
|
|
filedir (buildFilename, function ()
|
|
{
|
|
FILE.chmod(buildFilename, 0755);
|
|
});
|
|
}
|
|
|
|
task ("build", buildFilename);
|
|
CLOBBER.include(buildFilename);
|
|
});
|
|
|
|
$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()
|
|
{
|
|
return Array.prototype.map.apply(arguments, [function(anEnvironment)
|
|
{
|
|
return "-D" + anEnvironment.toUpperCase();
|
|
}]).join(" ") +
|
|
" -DENVIRONMENTS=\"[" + Array.prototype.map.apply(arguments, [function(anEnvironment) {
|
|
return "\\\"" + anEnvironment + "\\\"";
|
|
}]).join(", ") + "]\"";
|
|
}
|
|
|
|
function gcc(inputFilePath, outputFilePath, flags, compress)
|
|
{
|
|
stream.print("Building... \0green(" + outputFilePath +"\0)");
|
|
|
|
// GCC preprocess the file.
|
|
var gcc = OS.popen("gcc -E -x c -P " + flags + " " + inputFilePath, { charset:"UTF-8" }),
|
|
gccFilePath = FILE.join("", "tmp", "objj-gcc.js"),
|
|
chunk = null,
|
|
fileContents = FILE.read("header.txt", { charset : "UTF-8" });
|
|
|
|
while (chunk = gcc.stdout.read())
|
|
fileContents += chunk;
|
|
|
|
FILE.write(gccFilePath, fileContents, { charset:"UTF-8" });
|
|
|
|
if (FILE.extension(inputFilePath) === ".js" && compress)
|
|
{
|
|
var compressor = OS.popen("java -server -Dfile.encoding=UTF-8 -classpath CommonJS/shrinksafe/js.jar:CommonJS/shrinksafe/shrinksafe.jar org.dojotoolkit.shrinksafe.Main", { charset:"UTF-8" });
|
|
|
|
compressor.stdin.write(FILE.absolute(gccFilePath) + "\n");
|
|
compressor.stdin.flush();
|
|
|
|
fileContents = "";
|
|
|
|
while ((chunk = compressor.stdout.readLine()) !== "/*----*/\n")
|
|
fileContents += chunk;
|
|
}
|
|
|
|
FILE.write(outputFilePath, fileContents, { charset : "UTF-8" });
|
|
}
|
|
|
|
task("build", [$BUILD_BROWSER_FILE, $BUILD_LICENSE, $BUILD_CJS_OBJECTIVE_J_FRAMEWORK]);
|