hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 097b30120d980ac8a6e443f8c0bfc1d3f62f185e
parent 3c5b4260dfa58620dc5997fbeecd922fff76676e
Author: B. Atticus Grobe <grobe0ba@tcp80.org>
Date:   Mon,  7 Nov 2022 08:22:33 -0600

cmd/hare: pass -L to add directory to library search path

Signed-off-by: B. Atticus Grobe <grobe0ba@tcp80.org>

Diffstat:
Mcmd/hare/plan.ha | 3+++
Mcmd/hare/schedule.ha | 6++++++
Mcmd/hare/subcmds.ha | 21++++++++++++++++++---
Mdocs/hare.scd | 12++++++++++++
4 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/cmd/hare/plan.ha b/cmd/hare/plan.ha @@ -56,6 +56,7 @@ type plan = struct { scheduled: []*task, complete: []*task, script: str, + libdir: []str, libs: []str, environ: [](str, str), modmap: [64][]modcache, @@ -72,6 +73,7 @@ type plan_progress = struct { fn mkplan( ctx: *module::context, + libdir: []str, libs: []str, target: *target, ) plan = { @@ -118,6 +120,7 @@ fn mkplan( environ = alloc([ (strings::dup("HARECACHE"), strings::dup(ctx.cache)), ]), + libdir = libdir, libs = libs, progress = plan_progress { tty = if (tty::isatty(os::stderr)) os::stderr else void, diff --git a/cmd/hare/schedule.ha b/cmd/hare/schedule.ha @@ -130,6 +130,12 @@ fn sched_ld(plan: *plan, output: str, depend: *task...) *task = { module = void, }); + if (len(plan.libdir) != 0) { + for (let i = 0z; i < len(plan.libdir); i += 1) { + append(task.cmd, strings::concat("-L", plan.libdir[i])); + }; + }; + // Using --gc-sections will not work when using cc as the linker if (len(plan.libs) == 0 && task.cmd[0] == plan.target.ld_cmd) { append(task.cmd, "--gc-sections"); diff --git a/cmd/hare/subcmds.ha b/cmd/hare/subcmds.ha @@ -68,6 +68,7 @@ fn build(args: []str) void = { ('v', "print executed commands"), ('D', "ident[:type]=value", "define a constant"), ('j', "jobs", "set parallelism for build"), + ('L', "libdir", "add directory to linker library search path"), ('l', "name", "link with a system library"), ('N', "namespace", "override namespace for module"), ('o', "path", "set output file name"), @@ -88,6 +89,8 @@ fn build(args: []str) void = { let goal = goal::EXE; let defines: []str = []; defer free(defines); + let libdir: []str = []; + defer free(libdir); let libs: []str = []; defer free(libs); let namespace: ast::ident = []; @@ -102,6 +105,8 @@ fn build(args: []str) void = { append(defines, opt.1); case 'j' => abort("-j option not implemented yet."); // TODO + case 'L' => + append(libdir, opt.1); case 'l' => append(libs, opt.1); case 'N' => @@ -154,7 +159,7 @@ fn build(args: []str) void = { const ctx = module::context_init(tags, defines, HAREPATH); defer module::context_finish(&ctx); - const plan = mkplan(&ctx, libs, build_target); + const plan = mkplan(&ctx, libdir, libs, build_target); defer plan_finish(&plan); const ver = match (module::scan(&ctx, input)) { @@ -283,6 +288,7 @@ fn run(args: []str) void = { ('v', "print executed commands"), ('D', "ident[:type]=value", "define a constant"), ('j', "jobs", "set parallelism for build"), + ('L', "libdir", "add directory to linker library search path"), ('l', "name", "link with a system library"), ('T', "tags...", "set build tags"), ('X', "tags...", "unset build tags"), @@ -298,6 +304,8 @@ fn run(args: []str) void = { let verbose = false; let defines: []str = []; defer free(defines); + let libdir: []str = []; + defer free(libdir); let libs: []str = []; defer free(libs); for (let i = 0z; i < len(cmd.opts); i += 1) { @@ -309,6 +317,8 @@ fn run(args: []str) void = { append(defines, opt.1); case 'j' => abort("-j option not implemented yet."); // TODO + case 'L' => + append(libdir, opt.1); case 'l' => append(libs, opt.1); case 't' => @@ -351,7 +361,7 @@ fn run(args: []str) void = { const ctx = module::context_init(tags, defines, HAREPATH); defer module::context_finish(&ctx); - const plan = mkplan(&ctx, libs, build_target); + const plan = mkplan(&ctx, libdir, libs, build_target); defer plan_finish(&plan); const ver = match (module::scan(&ctx, input)) { @@ -393,6 +403,7 @@ fn test(args: []str) void = { ('v', "print executed commands"), ('D', "ident[:type]=value", "define a constant"), ('j', "jobs", "set parallelism for build"), + ('L', "libdir", "add directory to linker library search path"), ('l', "name", "link with a system library"), ('o', "path", "set output file name"), ('T', "tags...", "set build tags"), @@ -413,6 +424,8 @@ fn test(args: []str) void = { let verbose = false; let defines: []str = []; defer free(defines); + let libdir: []str = []; + defer free(libdir); let libs: []str = []; defer free(libs); for (let i = 0z; i < len(cmd.opts); i += 1) { @@ -424,6 +437,8 @@ fn test(args: []str) void = { append(defines, opt.1); case 'j' => abort("-j option not implemented yet."); // TODO + case 'L' => + append(libdir, opt.1); case 'l' => append(libs, opt.1); case 't' => @@ -468,7 +483,7 @@ fn test(args: []str) void = { const ctx = module::context_init(tags, defines, HAREPATH); defer module::context_finish(&ctx); - const plan = mkplan(&ctx, libs, build_target); + const plan = mkplan(&ctx, libdir, libs, build_target); defer plan_finish(&plan); let depends: []*task = []; diff --git a/docs/hare.scd b/docs/hare.scd @@ -9,6 +9,7 @@ hare - compiles, runs, and tests Hare programs *hare* build [-cv]++ [-D _ident[:type]=value_]++ [-j _jobs_]++ + [-L libdir]++ [-l _name_]++ [-o _path_]++ [-t _arch_]++ @@ -20,6 +21,7 @@ hare - compiles, runs, and tests Hare programs *hare* run [-v]++ [-D _ident[:type]=value_]++ [-l _name_]++ + [-L libdir]++ [-j _jobs_]++ [-T _tags_] [-X _tags_]++ [_path_] [_args_...] @@ -27,6 +29,7 @@ hare - compiles, runs, and tests Hare programs *hare* test [-v]++ [-D _ident[:type]=value_]++ [-l _name_]++ + [-L libdir]++ [-j _jobs_]++ [-T _tags_] [-X _tags_]++ _tests_ @@ -88,6 +91,9 @@ value, and optional context, separated by tabs. *pkg-config --libs* (see *pkg-config*(1)) to obtain the appropriate linker flags. +*-L libdir* + Add directory to the linker library search path. + *-o* _path_ Set the output file to the given path. @@ -137,6 +143,9 @@ value, and optional context, separated by tabs. *pkg-config --libs* (see *pkg-config*(1)) to obtain the appropriate linker flags. +*-L libdir* + Add directory to the linker library search path. + *-T* _tags_ Adds additional build tags. See *CUSTOMIZING BUILD TAGS*. @@ -165,6 +174,9 @@ value, and optional context, separated by tabs. *pkg-config --libs* (see *pkg-config*(1)) to obtain the appropriate linker flags. +*-L libdir* + Add directory to the linker library search path. + *-T* _tags_ Adds additional build tags. See *CUSTOMIZING BUILD TAGS*.