commit 0cd51184a7acdfd4ef20195d1648622b04477293
parent 6a326e53dfecb77839ac262bfebc377ac65d345b
Author: Drew DeVault <sir@cmpwn.com>
Date: Wed, 24 Apr 2024 13:18:27 +0200
hare(1): don't auto-add -lc if freestanding
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/cmd/hare/build.ha b/cmd/hare/build.ha
@@ -148,7 +148,7 @@ fn build(name: str, cmd: *getopt::command) (void | error) = {
os::tryenv("AS", arch.as_cmd),
os::tryenv("LD", arch.ld_cmd),
];
- if (len(ctx.libs) > 0 || ctx.platform.need_libc) {
+ if (!ctx.freestanding && (len(ctx.libs) > 0 || ctx.platform.need_libc)) {
ctx.libc = true;
merge_tags(&ctx.ctx.tags, "+libc")?;
ctx.cmds[build::stage::BIN] = os::tryenv("CC", arch.cc_cmd);
diff --git a/docs/hare-build.1.scd b/docs/hare-build.1.scd
@@ -33,8 +33,8 @@ working directory is built.
Print the help text.
*-F*
- Build for freestanding (non-hosted) environment. This allows a
- declaration whose symbol is main to take on any form.
+ Build for freestanding (non-hosted) environment. See *FREESTANDING
+ ENVIRONMENT*.
*-q*
Outside of errors, don't write anything to stdout while building.
@@ -100,6 +100,17 @@ The system usually provides reasonable defaults for the *AR*, *AS*, *LD*, and
*CC* tools based on the desired target. However, you may wish to set these
variables yourself to control the cross toolchain in use.
+# FREESTANDING ENVIRONMENT
+
+If run with *-F*, hare build will target a freestanding environment. This has
+the following effects:
+
+- No constraints are imposed on the signature of "main"
+- Specifying external libraries with *-l* will *not* automatically:
+ - Link with libc (add *-lc* manually if required)
+ - Add the +libc flag (add *-T+libc* manually if required)
+ - Use the C compiler for linking (use *LD=cc* if required)
+
# ENVIRONMENT
The following environment variables affect *hare build*'s execution: