diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2026-07-10 23:20:03 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2026-07-10 23:20:03 +0800 |
| commit | 48ef95c24e9ac3d11200b61af617a01b10b507d1 (patch) | |
| tree | 57f0e26ab98e795b19839b6eece98ca58a4b702d /lib | |
| parent | b9ff206e6bd3f4d67851263a6f2acb5f575cf3b0 (diff) | |
| download | lume-48ef95c24e9ac3d11200b61af617a01b10b507d1.tar.gz lume-48ef95c24e9ac3d11200b61af617a01b10b507d1.tar.xz | |
build: introduce declarative non-recursive build graph
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Build.mk | 35 | ||||
| -rw-r--r-- | lib/module.mk | 66 |
2 files changed, 35 insertions, 66 deletions
diff --git a/lib/Build.mk b/lib/Build.mk new file mode 100644 index 0000000..77d380c --- /dev/null +++ b/lib/Build.mk @@ -0,0 +1,35 @@ +targets += lib/runtime lib/string lib/libfdt lib/core + +target.lib/runtime.kind := source-set +target.lib/runtime.sources := \ + lib/cxx_abi.cc lib/rbtree.cc lib/kobject.cc lib/kprintf.cc lib/klog.cc \ + lib/random.cc lib/printf.c + +target.lib/string.kind := static-library +target.lib/string.sources := $(sort $(wildcard lib/string/*.c)) + +# Architecture assembly replaces the matching generic C implementation. +string-arch.riscv := +string-arch.x86_64 := x86_64 +string-arch.aarch64 := aarch64 +string-arch.i386 := i386 +string-arch.arm := arm +string-arch := $(string-arch.$(ARCH)) +ifneq ($(string-arch),) +string-asm := $(sort $(wildcard lib/string/$(string-arch)/*.S) \ + $(wildcard lib/string/$(string-arch)/*.s)) +string-asm-names := $(sort $(basename $(notdir $(string-asm)))) +target.lib/string.sources := $(filter-out \ + $(foreach name,$(string-asm-names),lib/string/$(name).c), \ + $(target.lib/string.sources)) $(string-asm) +endif + +target.lib/libfdt.kind := static-library +target.lib/libfdt.sources := \ + lib/fdt.c lib/fdt_ro.c lib/fdt_wip.c lib/fdt_rw.c lib/fdt_sw.c \ + lib/fdt_strerror.c lib/fdt_empty_tree.c lib/fdt_addresses.c +target.lib/libfdt.private-includes := scripts/dtc/libfdt +target.lib/libfdt.cflags := -Wno-parentheses -Wno-sign-compare + +target.lib/core.kind := header-library +target.lib/core.deps := lib/runtime lib/string lib/libfdt diff --git a/lib/module.mk b/lib/module.mk deleted file mode 100644 index 0b178f8..0000000 --- a/lib/module.mk +++ /dev/null @@ -1,66 +0,0 @@ -# lib/module.mk -SRCS_CC += lib/cxx_abi.cc -SRCS_CC += lib/rbtree.cc -SRCS_CC += lib/kobject.cc -SRCS_CC += lib/kprintf.cc -SRCS_CC += lib/klog.cc -SRCS_CC += lib/random.cc -SRCS_C += lib/printf.c - -# ============================================================ -# musl string library (cross-platform with arch asm overrides) -# ============================================================ - -# Map LumeOS ARCH to musl string arch directory -# riscv has no musl asm optimizations → pure C fallback -MUSL_STRING_ARCH_riscv := -MUSL_STRING_ARCH_x86_64 := x86_64 -MUSL_STRING_ARCH_i386 := i386 -MUSL_STRING_ARCH_aarch64:= aarch64 -MUSL_STRING_ARCH_arm := arm - -MUSL_STRING_ARCH := $(MUSL_STRING_ARCH_$(ARCH)) - -# Collect arch-specific asm sources (if any for this arch) -MUSL_ASM_SRCS := -ifneq ($(MUSL_STRING_ARCH),) - MUSL_ASM_SRCS += $(wildcard lib/string/$(MUSL_STRING_ARCH)/*.S) \ - $(wildcard lib/string/$(MUSL_STRING_ARCH)/*.s) -endif - -# Derive which C files are overridden by asm (strip path+ext to get base name) -MUSL_ASM_BASENAMES := $(sort $(basename $(notdir $(MUSL_ASM_SRCS)))) - -# All C sources, then filter out those with asm replacements -MUSL_ALL_C := $(wildcard lib/string/*.c) -MUSL_EXCLUDED_C := $(foreach name,$(MUSL_ASM_BASENAMES),lib/string/$(name).c) -MUSL_C_SRCS := $(filter-out $(MUSL_EXCLUDED_C),$(MUSL_ALL_C)) - -SRCS_C += $(MUSL_C_SRCS) -SRCS_S += $(filter %.S,$(MUSL_ASM_SRCS)) -SRCS_s += $(filter %.s,$(MUSL_ASM_SRCS)) - -# ============================================================ -# libfdt — kernel adapter shims around scripts/dtc/libfdt/. -# -# Each shim is two lines: -# #include <linux/libfdt_env.h> -# #include "../scripts/dtc/libfdt/fdt*.c" -# matching Linux lib/fdt*.c verbatim. The compile recipe needs: -# - <linux/libfdt_env.h> reachable via the default -Iinclude path -# - -I scripts/dtc/libfdt so the upstream source's #include <libfdt.h> -# and friends resolve to scripts/dtc/libfdt/libfdt.h -# Overriding CFLAGS_LIBC (which the %.o: %.c rule uses) avoids dragging -# in libc-shim headers — libfdt is freestanding-compatible and uses -# only the string functions forward-declared in <linux/libfdt_env.h>. -# ============================================================ -LIBFDT_FILES := fdt.c fdt_ro.c fdt_wip.c fdt_rw.c fdt_sw.c \ - fdt_strerror.c fdt_empty_tree.c fdt_addresses.c -SRCS_C += $(addprefix lib/,$(LIBFDT_FILES)) - -# Per-target CFLAGS override: plain CFLAGS plus the upstream include dir. -# Use `=` (recursive) not `:=` because $(CFLAGS) is defined in the top -# Makefile AFTER this file is included — `:=` would expand it now (empty) -# and lose -Iinclude, breaking <linux/libfdt_env.h>. -$(addprefix $(BUILD)/lib/,$(LIBFDT_FILES:.c=.o)): CFLAGS_LIBC = \ - $(CFLAGS) -I scripts/dtc/libfdt |
