summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <[email protected]>2026-03-24 13:45:20 -0600
committerTom Rini <[email protected]>2026-04-07 11:33:04 -0600
commit738428dc0e761617c5196a5210774ac7347e6bb7 (patch)
tree1abb73530a3e16fb6864490b7210f179a160b3ab
parentc98bf0533be6479f6b7d973b2419e9c4b7181456 (diff)
sandbox: Adjust how OS-interface files are built
The current mechanism uses a completely separate build rule for each file which must be built with system headers. This is tricky to maintain. Add a foreach template in the sandbox cpu Makefile which generates the custom compile rules from a CFLAGS_USE_SYSHDRS list. This keeps the rules data-driven without needing changes to the common scripts/Makefile.lib, which could affect other architectures. Move initjmp.o into the template since it uses the same pattern. Add sdl.o to the list too, with an override for its command since it also needs -fshort-wchar removed and -fno-lto added. Signed-off-by: Simon Glass <[email protected]>
-rw-r--r--arch/sandbox/Makefile2
-rw-r--r--arch/sandbox/cpu/Makefile45
2 files changed, 17 insertions, 30 deletions
diff --git a/arch/sandbox/Makefile b/arch/sandbox/Makefile
index a335f8acfde..5bbf9f1f96b 100644
--- a/arch/sandbox/Makefile
+++ b/arch/sandbox/Makefile
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-2.0+
-head-y := arch/sandbox/cpu/start.o arch/sandbox/cpu/os.o
+head-y := arch/sandbox/cpu/start.o
head-$(CONFIG_SANDBOX_SDL) += arch/sandbox/cpu/sdl.o
libs-y += arch/sandbox/cpu/
libs-y += arch/sandbox/lib/
diff --git a/arch/sandbox/cpu/Makefile b/arch/sandbox/cpu/Makefile
index 038ad78accc..ee3c04c49e1 100644
--- a/arch/sandbox/cpu/Makefile
+++ b/arch/sandbox/cpu/Makefile
@@ -5,42 +5,29 @@
# (C) Copyright 2000-2003
# Wolfgang Denk, DENX Software Engineering, [email protected].
-obj-y := cache.o cpu.o state.o initjmp.o
-extra-y := start.o os.o
+obj-y := cache.o cpu.o state.o initjmp.o os.o
+extra-y := start.o
extra-$(CONFIG_SANDBOX_SDL) += sdl.o
obj-$(CONFIG_XPL_BUILD) += spl.o
obj-$(CONFIG_ETH_SANDBOX_RAW) += eth-raw-os.o
-# os.c is build in the system environment, so needs standard includes
-# CFLAGS_REMOVE_os.o cannot be used to drop header include path
-quiet_cmd_cc_os.o = CC $(quiet_modtag) $@
-cmd_cc_os.o = $(CC) $(filter-out -nostdinc, \
- $(patsubst -I%,-idirafter%,$(c_flags))) -c -o $@ $<
+# These files need to be built with system headers, since they use system
+# calls or system-level interfaces. Generate a custom compile rule for each
+# one that drops -nostdinc and converts -I to -idirafter.
+CFLAGS_USE_SYSHDRS := eth-raw-os.o initjmp.o os.o sdl.o
-$(obj)/os.o: $(src)/os.c FORCE
- $(call if_changed_dep,cc_os.o)
+define syshdrs_rule
+quiet_cmd_cc_$(1) = CC $$(quiet_modtag) $$@
+cmd_cc_$(1) = $$(CC) $$(filter-out -nostdinc, \
+ $$(patsubst -I%,-idirafter%,$$(c_flags))) -c -o $$@ $$<
-# eth-raw-os.c is built in the system env, so needs standard includes
-# CFLAGS_REMOVE_eth-raw-os.o cannot be used to drop header include path
-quiet_cmd_cc_eth-raw-os.o = CC $(quiet_modtag) $@
-cmd_cc_eth-raw-os.o = $(CC) $(filter-out -nostdinc, \
- $(patsubst -I%,-idirafter%,$(c_flags))) -c -o $@ $<
+$$(obj)/$(1): $$(src)/$(1:.o=.c) FORCE
+ $$(call if_changed_dep,cc_$(1))
+endef
-$(obj)/eth-raw-os.o: $(src)/eth-raw-os.c FORCE
- $(call if_changed_dep,cc_eth-raw-os.o)
+$(foreach f,$(CFLAGS_USE_SYSHDRS),$(eval $(call syshdrs_rule,$(f))))
-# initjmp.c is build in the system environment, so needs standard includes
-# CFLAGS_REMOVE_initjmp.o cannot be used to drop header include path
-quiet_cmd_cc_initjmp.o = CC $(quiet_modtag) $@
-cmd_cc_initjmp.o = $(CC) $(filter-out -nostdinc, \
- $(patsubst -I%,-idirafter%,$(c_flags))) -c -o $@ $<
-
-$(obj)/initjmp.o: $(src)/initjmp.c FORCE
- $(call if_changed_dep,cc_initjmp.o)
-
-# sdl.c fails to build with -fshort-wchar using musl
+# sdl.c also needs -fshort-wchar removed (musl) and -fno-lto, so override
+# the generated rule
cmd_cc_sdl.o = $(CC) $(filter-out -nostdinc -fshort-wchar, \
$(patsubst -I%,-idirafter%,$(c_flags))) -fno-lto -c -o $@ $<
-
-$(obj)/sdl.o: $(src)/sdl.c FORCE
- $(call if_changed_dep,cc_sdl.o)