]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
sandbox: Adjust how OS-interface files are built 923/head
authorSimon Glass <sjg@chromium.org>
Tue, 24 Mar 2026 19:45:20 +0000 (13:45 -0600)
committerTom Rini <trini@konsulko.com>
Tue, 7 Apr 2026 17:33:04 +0000 (11:33 -0600)
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 <sjg@chromium.org>
arch/sandbox/Makefile
arch/sandbox/cpu/Makefile

index a335f8acfde623c0a637bfdfb10378afbf8d93a5..5bbf9f1f96bb2d25249b84ae908cdf2b9c0c0803 100644 (file)
@@ -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/
index 038ad78accc558bed83bf206699a9ae8cdfb4d60..ee3c04c49e14a47411b6da752fb8245327df0d3b 100644 (file)
@@ -5,42 +5,29 @@
 # (C) Copyright 2000-2003
 # Wolfgang Denk, DENX Software Engineering, wd@denx.de.
 
-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)