From 924337184ee944c5e38864ae39848b557c02a848 Mon Sep 17 00:00:00 2001 From: Nicholas Chin Date: Sun, 25 Aug 2024 17:31:23 -0600 Subject: [PATCH] Makefile: Allow defining order-only prerequisites in create_cc_template Generated files such as static.h are currently added as prerequisites for all compilation units to ensure that they exist and are up to date before anything that might need them is compiled. However, this has the side effect of forcing every compilation unit out of date when such files are regenerated, even if the object has no dependency on the generated file. GNU Make has order-only prerequisites [1] which are used to define prerequisites that must be updated before a given target, but which don't force the target out of date. Add a new argument to create_cc_template, similar to the "additional dependencies" argument, which allows dependencies on such generated files for a specified object class and source suffix to be defined. This new functionality will be utilized in subsequent commits to fix up the dependencies on generated files. Objects that do depend on generated headers will still be handled correctly due to the .d dependency files that are generated by the compiler during the build, which declare normal prerequisites to any headers an object directly or indirectly includes. As per the GNU Make documentation, normal prerequisites take precedence over order-only prerequisites, so the header dependencies declared in the .d files will override the order-only one declared through create_cc_template. This does mean that a necessary rebuild of an object due to a generated file may be missed if the dependency file from the compiler is missing, but this is an unusual situation that is unlikely to occur during normal incremental builds. [1] https://www.gnu.org/software/make/manual/html_node/Prerequisite-Types.html Change-Id: I50d87b3d9012967eefb197be12b2e0f096b0b67c Signed-off-by: Nicholas Chin Reviewed-on: https://review.coreboot.org/c/coreboot/+/84386 Tested-by: build bot (Jenkins) Reviewed-by: Nico Huber --- Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index cc73900bda..810ccb8a46 100644 --- a/Makefile +++ b/Makefile @@ -392,16 +392,17 @@ define create_cc_template # $2 source suffix (c, S, ld, ...) # $3 additional compiler flags # $4 additional dependencies +# $5 generated header dependencies ifn$(EMPTY)def $(1)-objs_$(2)_template de$(EMPTY)fine $(1)-objs_$(2)_template ifn$(EMPTY)eq ($(filter ads adb,$(2)),) -$$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $$(call create_ada_deps,$1,$$(call src-to-ali,$1,$$(1).$2)) $(4) +$$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $$(call create_ada_deps,$1,$$(call src-to-ali,$1,$$(1).$2)) $(4) | $(5) @printf " GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n" $(GCC_$(1)) \ $$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs)) \ $(3) -c -o $$$$@ $$$$< el$(EMPTY)se -$$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4) +$$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4) | $(5) @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n" $(CC_$(1)) \ -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) \ @@ -416,7 +417,7 @@ $(foreach class,$(classes), \ $(foreach type,$(call filetypes-of-class,$(class)), \ $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \ $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\ - $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps)))))) + $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps),$($(class)-$(type)-gen-deps)))))) foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file))))) $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))