refactor(build): use a standard rule to run the preprocessor
There are a few, functionally identical, ways to call the preprocessor
on a non-C file, depending on the file. They differ in subtle, not
entirely correct, ways - one is missing a dependency to the makefiles,
another generates its .d inline, and the prints are different. That has
resulted in platforms reimplementing this functionality, making the
build brittle - a change to the overall build system doesn't propagate.
So add a MAKE_PRE macro that will make a rule with all the bells and
whistles to run the preprocessor on an arbitrary file.
This patch converts the arm platforms' cot_descriptors DTS rules. The
files are renamed to fit with the build rule and all extra flags are
dropped. Those flags are only necessary for building BL2 c files, which
will be passed to the output C file. Only the DTS flags are needed for
the preprocessing step, which will be passed automatically.
Change-Id: I3c1cc0ecf93b87d828f868214928c1bc9bcb5758
Signed-off-by: Boyan Karatotev <boyan.karatotev@arm.com>
diff --git a/make_helpers/build_macros.mk b/make_helpers/build_macros.mk
index c28a14e..46a1ce0 100644
--- a/make_helpers/build_macros.mk
+++ b/make_helpers/build_macros.mk
@@ -411,6 +411,20 @@
endef
+# MAKE_PRE run the C preprocessor on a file
+# $(1) = output file
+# $(2) = list of input files
+# $(3) = dep file
+# $(4) = list of rule-specific flags to pass
+define MAKE_PRE
+$(eval OUT := $(1))
+$(eval SRC := $(2))
+$(eval DEP := $(3))
+$(eval CUSTOM_FLAGS := $(4))
+$(OUT): $(SRC) $(filter-out %.d,$(MAKEFILE_LIST)) | $$$$(@D)/
+ $$(s)echo " CPP $$<"
+ $$(q)$($(ARCH)-cpp) -E -P -x assembler-with-cpp $$(TF_CFLAGS) $(CUSTOM_FLAGS) $(call MAKE_DEP,$(DEP),$(OUT)) -o $$@ $$<
+endef
# MAKE_LD generate the linker script using the C preprocessor
# $(1) = output linker script
@@ -424,11 +438,9 @@
$(eval BL_DEFINES := IMAGE_$(4) $($(4)_DEFINES))
$(eval BL_INCLUDE_DIRS := $($(4)_INCLUDE_DIRS))
$(eval BL_CPPFLAGS := $($(4)_CPPFLAGS) $(addprefix -D,$(BL_DEFINES)) $(addprefix -I,$(BL_INCLUDE_DIRS)))
+$(eval FLAGS := -D__LINKER__ $(BL_CPPFLAGS))
-$(1): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $$$$(@D)/
- $$(s)echo " PP $$<"
- $$(q)$($(ARCH)-cpp) -E $$(CPPFLAGS) $(BL_CPPFLAGS) $(TF_CFLAGS_$(ARCH)) -P -x assembler-with-cpp -D__LINKER__ $(call MAKE_DEP,$(DEP),$1) -o $$@ $$<
-
+$(eval $(call MAKE_PRE,$(1),$(2),$(DEP),$(FLAGS)))
-include $(DEP)
endef
@@ -639,10 +651,7 @@
# Dependencies of the DT compilation on its pre-compiled DTS
$(eval DTBDEP := $(patsubst %.dtb,%.d,$(DOBJ)))
-$(DPRE): $(2) | $$$$(@D)/
- $$(s)echo " CPP $$<"
- $(eval DTBS := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2))))
- $$(q)$($(ARCH)-cpp) -E $$(TF_CFLAGS_$(ARCH)) $$(DTC_CPPFLAGS) -MT $(DTBS) -MMD -MF $(DTSDEP) -o $(DPRE) $$<
+$(eval $(call MAKE_PRE,$(DPRE),$(2),$(DTSDEP),$(DTC_CPPFLAGS)))
$(DOBJ): $(DPRE) $(filter-out %.d,$(MAKEFILE_LIST)) | $$$$(@D)/
$$(s)echo " DTC $$<"