subdirectory support
This commit is contained in:
parent
7ce5bd3cf3
commit
96f3fa1f70
9 changed files with 109 additions and 29 deletions
|
|
@ -73,6 +73,10 @@ for(var i = 1; i < ARGV.length; i++) {
|
|||
main();
|
||||
|
||||
(function() {
|
||||
function makefile(target) {
|
||||
return target.base + "/" + target.target + ".make";
|
||||
}
|
||||
|
||||
function make(output) {
|
||||
const targets = pmake.resolveProjects(pmake.projects);
|
||||
|
||||
|
|
@ -101,21 +105,25 @@ function make(output) {
|
|||
|
||||
for(var i = 0; i < targets.length; i++) {
|
||||
mk.write(targets[i].target + ": " + pmake.resolveProjects(targets[i].libraries).map(target_map).join(" ") + "\n");
|
||||
mk.write(" @$(MAKE) $(MAKEARGS) -f " + targets[i].target + ".make\n");
|
||||
mk.write(" @cd " + targets[i].base + " ; $(MAKE) $(MAKEARGS) -f " + makefile(targets[i]) + "\n");
|
||||
mk.write("\n");
|
||||
}
|
||||
|
||||
mk.write("clean:\n");
|
||||
for(var i = 0; i < targets.length; i++) {
|
||||
mk.write(" @$(MAKE) $(MAKEARGS) -f " + targets[i].target + ".make clean\n");
|
||||
mk.write(" @cd " + targets[i].base + " ; $(MAKE) $(MAKEARGS) -f " + makefile(targets[i]) + " clean\n");
|
||||
}
|
||||
mk.write("\n");
|
||||
|
||||
mk.write("distclean: clean\n");
|
||||
mk.write(" $(SILENT)rm -f *.make Makefile\n");
|
||||
mk.write(" $(SILENT)rm -f Makefile\n");
|
||||
for(var i = 0; i < targets.length; i++) {
|
||||
mk.write(" $(SILENT)rm -f " + makefile(targets[i]) + "\n");
|
||||
}
|
||||
} else {
|
||||
function target_filter(x) {
|
||||
return x.target == output.replace(/\.make$/, "");
|
||||
const p = output.replace(/\.make$/, "").split("/");
|
||||
return x.target == p[p.length - 1];
|
||||
}
|
||||
|
||||
const self = targets.filter(target_filter)[0];
|
||||
|
|
@ -150,6 +158,6 @@ function make(output) {
|
|||
make("Makefile");
|
||||
const targets = pmake.resolveProjects(pmake.projects);
|
||||
for(var i = 0; i < targets.length; i++) {
|
||||
make(targets[i].target + ".make");
|
||||
make(makefile(targets[i]));
|
||||
}
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -72,8 +72,12 @@ pmake.resolveProjects = function(arr, if_str) {
|
|||
for(var i = 0; i < arr.length; i++) {
|
||||
var proj = arr[i];
|
||||
|
||||
if((typeof proj) == "string" && pmake.projects[proj]) {
|
||||
proj = pmake.projects[proj];
|
||||
function filter_project(x) {
|
||||
return x.target == proj;
|
||||
}
|
||||
|
||||
if((typeof proj) == "string" && pmake.projects.filter(filter_project)[0]) {
|
||||
proj = pmake.projects.filter(filter_project)[0];
|
||||
}
|
||||
|
||||
if(proj instanceof pmake.Project) {
|
||||
|
|
@ -95,26 +99,36 @@ pmake.isCxx = function(src) {
|
|||
return src.endsWith(".cc") || src.endsWith(".cxx") || src.endsWith(".cpp");
|
||||
};
|
||||
|
||||
pmake.pathTransform = function(target) {
|
||||
return function(x) {
|
||||
if(x == "." || x == ".." || x.startsWith("./") || x.startsWith("../")) {
|
||||
return target.base + "/" + x;
|
||||
} else {
|
||||
return x;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
pmake.includes = function(target) {
|
||||
function includes(x) {
|
||||
return x.includes;
|
||||
return x.includes.map(pmake.pathTransform(x));
|
||||
}
|
||||
|
||||
const targets = pmake.resolveProjects(target.libraries);
|
||||
|
||||
return targets.map(includes).flat();
|
||||
return target.includes.concat(targets.map(includes).flat());
|
||||
};
|
||||
|
||||
pmake.libdirs = function(target, if_str) {
|
||||
pmake.libdirs = function(target) {
|
||||
function libdirs(x) {
|
||||
if(x instanceof pmake.LibraryProject) {
|
||||
return x.libdirs;
|
||||
return x.libdirs.map(pmake.pathTransform(x));
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
const targets = pmake.resolveProjects(target.libraries, if_str);
|
||||
const targets = pmake.resolveProjects(target.libraries);
|
||||
|
||||
return target.libdirs.concat(targets.map(libdirs).flat());
|
||||
};
|
||||
|
|
@ -122,7 +136,7 @@ pmake.libdirs = function(target, if_str) {
|
|||
pmake.libs = function(target, if_str) {
|
||||
function libs(x) {
|
||||
if(x instanceof pmake.LibraryProject) {
|
||||
const r = pmake.resolveProjects(x.libraries, if_str).concat([ pmake.compiler.output(x) ]);
|
||||
const r = pmake.resolveProjects(x.libraries, if_str).concat([ x.base + "/" + pmake.compiler.output(x) ]);
|
||||
|
||||
return r;
|
||||
} else if((typeof x) == "string") {
|
||||
|
|
@ -236,6 +250,7 @@ const Project = function(target) {
|
|||
this.libdirs = [];
|
||||
this.libraries = [];
|
||||
this.output = target;
|
||||
this.base = fs.cwd();
|
||||
};
|
||||
|
||||
Project.prototype.generate = function() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue