Skip to content

Qwen3-0.6B inference (12 KB), bare-metal bootable OS (22 KB), and from-scratch Mini-GPT trainer with live Braille TUI (32 KB) in 100% pure x86-64 NASM assembly. Zero C, zero libc, zero dependencies.

build: add cross-platform Makefile for macOS compatibility

tekintian79584645268d
diff --git a/Makefile b/Makefile
index 4ae546d..efe3975 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,26 @@
-NASM := nasm
-LD := ld
-OBJCOPY := objcopy
+# --- Cross-platform toolchain detection ---
+# Linux : GNU binutils (ld, objcopy) 原生支持所有参数
+# macOS : Apple ld/objcopy 不支持 ELF, 必须用 mold + llvm-objcopy + ld.lld
+UNAME_S := $(shell uname -s)
+
+ifeq ($(UNAME_S),Darwin)
+ LLVM_BIN := $(firstword \
+ $(wildcard /opt/local/libexec/llvm-devel/bin) \
+ $(wildcard /opt/local/libexec/llvm-21/bin) \
+ $(wildcard /opt/local/libexec/llvm-19/bin) \
+ $(wildcard /opt/local/libexec/llvm-18/bin) \
+ $(wildcard /opt/local/libexec/llvm-17/bin) \
+ )
+ LD := mold
+ OBJCOPY := $(LLVM_BIN)/llvm-objcopy
+ OS_LD := $(LLVM_BIN)/ld.lld
+else
+ LD := ld
+ OBJCOPY := objcopy
+ OS_LD := ld
+endif
+
+NASM := nasm
LDFLAGS := --gc-sections -s -z noexecstack -z noseparate-code
BUILD := build
@@ -132,7 +152,7 @@ $(OS_BUILD)/transformer.o: $(SHARED_DIR)/transformer.asm $(SHARED_DIR)/constants
$(NASM) $(OS_AFLAGS) $< -o $@
$(OS_ELF64): $(OS_OBJS) $(P2_DIR)/linker.ld
- $(LD) $(OS_LDFLAGS) $(OS_OBJS) -o $@
+ $(OS_LD) $(OS_LDFLAGS) $(OS_OBJS) -o $@
$(OS_ELF): $(OS_ELF64)
$(OBJCOPY) -O elf32-i386 $< $@
@@ -177,4 +197,4 @@ train-check: $(TRAIN_TARGET)
check-all: check os-check train-check
clean:
- rm -rf $(BUILD)
+ rm -rf $(BUILD)
\ No newline at end of file