subdirectory support

This commit is contained in:
Nishi 2026-05-10 00:22:00 +09:00
commit 96f3fa1f70
Signed by: nishi
GPG key ID: 27EF69B208EB9343
9 changed files with 109 additions and 29 deletions

View file

@ -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() {