From 7ce5bd3cf3305b8554c2f3c98529f77ce6cc742e Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Sat, 9 May 2026 19:19:44 +0900 Subject: [PATCH] libdirs --- pmake.js | 1 + src/compiler/watcom.js | 6 +++++- src/js/core.js | 41 +++++++++++++++++++++++++++++++++-------- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/pmake.js b/pmake.js index b864c1f..0318219 100644 --- a/pmake.js +++ b/pmake.js @@ -20,6 +20,7 @@ function main() { Duktape.output = "duktape"; Duktape.sources = fs.glob("external/duktape/*.c"); Duktape.includes = [ "external/duktape" ]; + Duktape.libdirs = ["a"]; if(pmake.system.target == "Unix") { Duktape.libraries = [ "m" ]; diff --git a/src/compiler/watcom.js b/src/compiler/watcom.js index ea72853..d00d268 100644 --- a/src/compiler/watcom.js +++ b/src/compiler/watcom.js @@ -46,7 +46,11 @@ Watcom.link = function(target, files) { return "library \"" + x + "\""; } - return "wlink option quiet system nt name " + this.output(target) + " " + files.map(add_file).join(" ") + " " + pmake.libs(target, add_lib).map(add_library).join(" "); + function add_libpath(x) { + return "libpath \"" + x + "\""; + } + + return "wlink option quiet system nt name " + this.output(target) + " " + files.map(add_file).join(" ") + " " + pmake.libdirs(target).map(add_libpath).join(" ") + " " + pmake.libs(target, add_lib).map(add_library).join(" "); } return ""; diff --git a/src/js/core.js b/src/js/core.js index ed443f6..f5fb7c8 100644 --- a/src/js/core.js +++ b/src/js/core.js @@ -77,7 +77,7 @@ pmake.resolveProjects = function(arr, if_str) { } if(proj instanceof pmake.Project) { - r = r.concat(pmake.resolveProjects(proj.libraries)); + r = r.concat(pmake.resolveProjects(proj.libraries, if_str)); r.push(proj); } else if((typeof proj) == "string" && if_str) { r.push(if_str(proj)); @@ -105,12 +105,10 @@ pmake.includes = function(target) { return targets.map(includes).flat(); }; -pmake.libs = function(target, if_str) { - function libs(x) { +pmake.libdirs = function(target, if_str) { + function libdirs(x) { if(x instanceof pmake.LibraryProject) { - return x.libraries.concat([ pmake.compiler.output(x) ]); - } else if((typeof x) == "string") { - return [ x ]; + return x.libdirs; } return []; @@ -118,7 +116,29 @@ pmake.libs = function(target, if_str) { const targets = pmake.resolveProjects(target.libraries, if_str); - return targets.map(libs).flat(); + return target.libdirs.concat(targets.map(libdirs).flat()); +}; + +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) ]); + + return r; + } else if((typeof x) == "string") { + return [ x ]; + } + + return []; + } + + const targets = pmake.resolveProjects(target.libraries, if_str).map(libs).flat(); + + targets = targets.filter(function(item, pos) { + return targets.indexOf(item) == pos; + }); + + return targets; }; pmake.setSystem = function(target) { @@ -192,7 +212,11 @@ POSIXCompiler.prototype.link = function(target, files) { return "-l" + x; } - return this.prefix + c + " -o " + this.output(target) + " " + files.join(" ") + " " + pmake.libs(target, add_l).join(" "); + function add_L(x) { + return "-L" + x; + } + + return this.prefix + c + " " + pmake.libdirs(target).map(add_L).join(" ") + " -o " + this.output(target) + " " + files.join(" ") + " " + pmake.libs(target, add_l).join(" "); } return ""; @@ -209,6 +233,7 @@ const Project = function(target) { this.target = target; this.sources = []; this.includes = []; + this.libdirs = []; this.libraries = []; this.output = target; };