hare

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

commit 017c8082e9d51cf440285eeb623dc19086e15c58
parent 37a1e42afa0bc3efa01417c99251f495c066087b
Author: Dridi Boukelmoune <dridi.boukelmoune@gmail.com>
Date:   Mon, 21 Aug 2023 07:12:30 +0200

cmd/hare: Bring back LDFLAGS support

The hare(1) command used to pass additional flags to the linker using
the LDFLAGS variable but it conflicted with how the LDFLAGS variable is
traditionally used, linking with the cc(1) command.

Since hare(1) may use either ld(1) or cc(1) for linking, LDLINKFLAGS can
not work as a one-size-fits-all.

By adding a formal cc_tool we can support both LDFLAGS and LDLINKFLAGS.

Diffstat:
Mcmd/hare/plan.ha | 7++-----
Mcmd/hare/schedule.ha | 10++++++++--
Mdocs/hare.scd | 6+++++-
3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/cmd/hare/plan.ha b/cmd/hare/plan.ha @@ -106,11 +106,8 @@ fn mkplan( ar_tool.0 = target.ar_cmd; as_tool.0 = target.as_cmd; - ld_tool.0 = if (len(libs) > 0) { - yield target.cc_cmd; - } else { - yield target.ld_cmd; - }; + cc_tool.0 = target.cc_cmd; + ld_tool.0 = target.ld_cmd; let environ: [](str, str) = alloc([ (strings::dup("HARECACHE"), strings::dup(ctx.cache)), diff --git a/cmd/hare/schedule.ha b/cmd/hare/schedule.ha @@ -34,6 +34,7 @@ fn getenv(var: str) []str = { // (executable name, executable variable, flags variable) type tool = (str, str, str); +let cc_tool: tool = ("", "CC", "LDFLAGS"); let ld_tool: tool = ("", "LD", "LDLINKFLAGS"); let as_tool: tool = ("", "AS", "ASFLAGS"); let ar_tool: tool = ("", "AR", "ARFLAGS"); @@ -109,11 +110,16 @@ fn sched_module(plan: *plan, ident: ast::ident, link: *[]*task) *task = { // Schedules a task which compiles objects into an executable. fn sched_ld(plan: *plan, output: str, depend: *task...) *task = { + let linker = if (len(plan.libs) > 0) { + yield &cc_tool; + } else { + yield &ld_tool; + }; let task = alloc(task { status = status::SCHEDULED, output = output, depend = alloc(depend...), - cmd = getcmd(&ld_tool, + cmd = getcmd(linker, "-T", plan.script, "-o", output), module = void, @@ -127,7 +133,7 @@ fn sched_ld(plan: *plan, output: str, depend: *task...) *task = { // Using --gc-sections and -z noexecstack will not work when using cc as // the linker - if (len(plan.libs) == 0 && task.cmd[0] == plan.target.ld_cmd) { + if (linker == &ld_tool) { append(task.cmd, ["--gc-sections", "-z", "noexecstack"]...); }; diff --git a/docs/hare.scd b/docs/hare.scd @@ -296,6 +296,10 @@ The following environment variables affect *hare*'s execution: : Name of the *as*(1) command to use. | *ASFLAGS* : Additional flags to pass to *as*(1). +| *CC* +: Name of the *cc*(1) command to use when linking external libraries. +| *LDFLAGS* +: Additional linker flags to pass to *cc*(1). | *LD* : Name of the *ld*(1) command to use. | *LDLINKFLAGS* @@ -303,4 +307,4 @@ The following environment variables affect *hare*'s execution: # SEE ALSO -*harec*(1), *haredoc*(1), *as*(1), *ld*(1), *ar*(1), *make*(1) +*harec*(1), *haredoc*(1), *ar*(1), *as*(1), *cc*(1), *ld*(1), *make*(1)