things
This commit is contained in:
parent
c89f96ce8a
commit
d951a0bceb
15 changed files with 381 additions and 90 deletions
|
|
@ -1,5 +1,4 @@
|
|||
const PADDING = 16;
|
||||
var action;
|
||||
const PADDING = 24;
|
||||
|
||||
for(var i = 1; i < ARGV.length; i++) {
|
||||
if(ARGV[i] == "--help") {
|
||||
|
|
@ -7,10 +6,42 @@ for(var i = 1; i < ARGV.length; i++) {
|
|||
|
||||
console.log("PMake " + pmake.VERSION + " - Pyrite's build script generator");
|
||||
console.log("");
|
||||
console.log("Usage: " + ARGV[0] + " [options] action [arguments]");
|
||||
console.log("Usage: " + ARGV[0] + " [options]");
|
||||
|
||||
keys = Object.keys(pmake.options);
|
||||
for(var i = 0; i < keys.length; i++) {
|
||||
console.log("");
|
||||
console.log("OPTIONS - " + keys[i]);
|
||||
|
||||
var keys2 = Object.keys(pmake.options[keys[i]]);
|
||||
for(var j = 0; j < keys2.length; j++) {
|
||||
const opt = pmake.options[keys[i]][keys2[j]];
|
||||
var arg = "";
|
||||
var opts = [];
|
||||
|
||||
if(opt.option) {
|
||||
arg = "=" + opt.option;
|
||||
}
|
||||
|
||||
console.log(" --" + keys2[j] + arg + " ".repeat(PADDING - keys2[j].length - 2 - arg.length) + opt.description);
|
||||
if(!opt.options) {
|
||||
} else if((typeof opt.options) == "function") {
|
||||
opts = opt.options();
|
||||
} else {
|
||||
opts = opt.options;
|
||||
}
|
||||
|
||||
if(opts.length > 0) {
|
||||
for(var k = 0; k < opts.length; k++) {
|
||||
console.log(" " + opts[k]);
|
||||
}
|
||||
console.log("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log("");
|
||||
console.log("ACTIONS");
|
||||
|
||||
keys = Object.keys(pmake.actions);
|
||||
for(var i = 0; i < keys.length; i++) {
|
||||
console.log(" " + keys[i] + " ".repeat(PADDING - keys[i].length) + pmake.actions[keys[i]].description);
|
||||
|
|
@ -19,16 +50,34 @@ for(var i = 1; i < ARGV.length; i++) {
|
|||
} else if(ARGV[i].startsWith("--")) {
|
||||
console.log("Error: invalid option '" + ARGV[i].substr(2) + "'");
|
||||
process.exit(1);
|
||||
} else if(pmake.actions[ARGV[i]]) {
|
||||
action = ARGV[i];
|
||||
break;
|
||||
} else {
|
||||
console.log("Error: no such action '" + ARGV[i] + "'");
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if(!action) {
|
||||
console.log("Type '" + ARGV[0] + " --help' for help");
|
||||
process.exit(1);
|
||||
(function(){
|
||||
function make(output){
|
||||
var mk = new pmake.File(output, "w");
|
||||
|
||||
mk.write("# This file was auto-generated. Do not edit manually!\n");
|
||||
mk.write("\n");
|
||||
mk.write("SILENT = @\n");
|
||||
mk.write("\n");
|
||||
|
||||
if(output == "Makefile"){
|
||||
var targets = pmake.resolveProjects(pmake.projects);
|
||||
for(var i = 0; i < targets.length; i++){
|
||||
mk.write(targets[i].target + ":\n");
|
||||
mk.write(" @$(MAKE) -f " + targets[i].target + ".make\n");
|
||||
mk.write("\n");
|
||||
}
|
||||
}else{
|
||||
}
|
||||
|
||||
mk.close();
|
||||
}
|
||||
|
||||
make("Makefile");
|
||||
var targets = pmake.resolveProjects(pmake.projects);
|
||||
for(var i = 0; i < targets.length; i++){
|
||||
make(targets[i].target + ".make");
|
||||
}
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
const pmake = {
|
||||
VERSION : "0.0",
|
||||
actions : {},
|
||||
compilers : {}
|
||||
compilers : {},
|
||||
options : {},
|
||||
projects : []
|
||||
};
|
||||
|
||||
pmake.inherit = function(base) {
|
||||
const func = function() {};
|
||||
pmake.inherit = function(base, call) {
|
||||
const func = (function() {});
|
||||
|
||||
Object.setPrototypeOf(func.prototype, base.prototype);
|
||||
|
||||
|
|
@ -25,15 +26,77 @@ pmake.inherited = function(base, parent) {
|
|||
};
|
||||
|
||||
pmake.register = function(base) {
|
||||
if(pmake.inherited(base, pmake.Compiler)) {
|
||||
if(base instanceof pmake.Compiler) {
|
||||
pmake.compilers[base.target] = base;
|
||||
} else if(pmake.inherited(base, pmake.Action)) {
|
||||
pmake.actions[base.target] = base;
|
||||
} else if(base instanceof pmake.Option) {
|
||||
if(!pmake.options[base.category]) pmake.options[base.category] = {};
|
||||
|
||||
pmake.options[base.category][base.target] = base;
|
||||
} else if(base instanceof pmake.Project) {
|
||||
pmake.projects.push(base);
|
||||
}
|
||||
};
|
||||
|
||||
pmake.Compiler = function() {
|
||||
pmake.resolveProjects = function(arr){
|
||||
var r = [];
|
||||
|
||||
for(var i = 0; i < arr.length; i++){
|
||||
if(arr[i] instanceof pmake.Project){
|
||||
r = r.concat(pmake.resolveProjects(arr[i].libraries));
|
||||
r.push(arr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return r;
|
||||
};
|
||||
|
||||
pmake.Action = function() {
|
||||
(function() {
|
||||
const Compiler = function() {};
|
||||
|
||||
const POSIXCompiler = pmake.inherit(Compiler);
|
||||
|
||||
const Option = function() {};
|
||||
|
||||
const Project = function(target) {
|
||||
this.target = target;
|
||||
this.files = [];
|
||||
this.libraries = [];
|
||||
};
|
||||
|
||||
Project.prototype.generate = function() {
|
||||
};
|
||||
|
||||
const File = function(filename, mode) {
|
||||
this.fp = fs.open(filename, mode);
|
||||
};
|
||||
|
||||
File.prototype.write = function(string) {
|
||||
fs.write(this.fp, string);
|
||||
};
|
||||
|
||||
File.prototype.close = function() {
|
||||
fs.close(this.fp);
|
||||
};
|
||||
|
||||
pmake.Compiler = Compiler;
|
||||
pmake.POSIXCompiler = POSIXCompiler;
|
||||
pmake.Option = Option;
|
||||
pmake.Project = Project;
|
||||
pmake.File = File;
|
||||
})();
|
||||
|
||||
/*** Option ***/
|
||||
(function() {
|
||||
const Compiler = new pmake.Option();
|
||||
|
||||
Compiler.category = "General";
|
||||
Compiler.target = "compiler";
|
||||
Compiler.description = "Choose a compiler set; one of:";
|
||||
Compiler.option = "VALUE";
|
||||
|
||||
Compiler.options = function() {
|
||||
return Object.keys(pmake.compilers);
|
||||
};
|
||||
|
||||
pmake.register(Compiler);
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue