From f2e1d57e43a0688901cc5f83546c66079fce5451 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 22 Dec 2016 12:39:55 +0900 Subject: [PATCH 1/4] Build: exclude -c flag from TF_CFLAGS The -c flag should not be included in the global variable TF_CFLAGS; it should be specified in the build rule only when its target is a *.o file. Signed-off-by: Masahiro Yamada --- Makefile | 2 +- make_helpers/build_macros.mk | 2 +- make_helpers/windows.mk | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index e8716e566..bb46afcb4 100644 --- a/Makefile +++ b/Makefile @@ -149,7 +149,7 @@ ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \ ${DEFINES} ${INCLUDES} TF_CFLAGS += -nostdinc -ffreestanding -Wall \ -Werror -Wmissing-include-dirs \ - -std=c99 -c -Os \ + -std=c99 -Os \ $(TF_CFLAGS_$(ARCH)) \ ${DEFINES} ${INCLUDES} TF_CFLAGS += -ffunction-sections -fdata-sections diff --git a/make_helpers/build_macros.mk b/make_helpers/build_macros.mk index 16bdd7883..4ec060b64 100644 --- a/make_helpers/build_macros.mk +++ b/make_helpers/build_macros.mk @@ -358,7 +358,7 @@ ifdef MAKE_BUILD_STRINGS else @echo 'const char build_message[] = "Built : "$(BUILD_MESSAGE_TIMESTAMP); \ const char version_string[] = "${VERSION_STRING}";' | \ - $$(CC) $$(TF_CFLAGS) $$(CFLAGS) -xc - -o $(BUILD_DIR)/build_message.o + $$(CC) $$(TF_CFLAGS) $$(CFLAGS) -xc -c - -o $(BUILD_DIR)/build_message.o endif $$(Q)$$(LD) -o $$@ $$(LDFLAGS) -Map=$(MAPFILE) --script $(LINKERFILE) \ $(BUILD_DIR)/build_message.o $(OBJS) diff --git a/make_helpers/windows.mk b/make_helpers/windows.mk index fe5e8c1fe..c4317d53d 100644 --- a/make_helpers/windows.mk +++ b/make_helpers/windows.mk @@ -104,6 +104,6 @@ BUILT_TIME_DATE_STRING = const char build_message[] = "Built : "${BUILD_MESSAGE_ VERSION_STRING_MESSAGE = const char version_string[] = "${VERSION_STRING}"; define MAKE_BUILD_STRINGS @echo $$(BUILT_TIME_DATE_STRING) $$(VERSION_STRING_MESSAGE) | \ - $$(CC) $$(TF_CFLAGS) $$(CFLAGS) -x c - -o $1 + $$(CC) $$(TF_CFLAGS) $$(CFLAGS) -x c -c - -o $1 endef From 59de50963cc49f6aa003bd10f5a20f766186c02a Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 22 Dec 2016 12:51:53 +0900 Subject: [PATCH 2/4] Build: use CPP just for pre-processing Using AS for pre-processing looks a bit weird, and some assembly specific options are given for nothing. Rather, use CPP. Signed-off-by: Masahiro Yamada --- Makefile | 18 ++++++++---------- make_helpers/build_macros.mk | 4 ++-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index bb46afcb4..adfdba6c2 100644 --- a/Makefile +++ b/Makefile @@ -143,16 +143,14 @@ TF_CFLAGS_aarch64 = -mgeneral-regs-only -mstrict-align ASFLAGS_aarch32 = -march=armv8-a TF_CFLAGS_aarch32 = -march=armv8-a -ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \ - -Werror -Wmissing-include-dirs \ - -D__ASSEMBLY__ $(ASFLAGS_$(ARCH)) \ - ${DEFINES} ${INCLUDES} -TF_CFLAGS += -nostdinc -ffreestanding -Wall \ - -Werror -Wmissing-include-dirs \ - -std=c99 -Os \ - $(TF_CFLAGS_$(ARCH)) \ - ${DEFINES} ${INCLUDES} -TF_CFLAGS += -ffunction-sections -fdata-sections +CPPFLAGS = ${DEFINES} ${INCLUDES} -nostdinc \ + -Wmissing-include-dirs -Werror +ASFLAGS += $(CPPFLAGS) $(ASFLAGS_$(ARCH)) \ + -D__ASSEMBLY__ -ffreestanding \ + -Wa,--fatal-warnings +TF_CFLAGS += $(CPPFLAGS) $(TF_CFLAGS_$(ARCH)) \ + -ffreestanding -Wall -std=c99 -Os \ + -ffunction-sections -fdata-sections LDFLAGS += --fatal-warnings -O1 LDFLAGS += --gc-sections diff --git a/make_helpers/build_macros.mk b/make_helpers/build_macros.mk index 4ec060b64..dd8c2b508 100644 --- a/make_helpers/build_macros.mk +++ b/make_helpers/build_macros.mk @@ -262,11 +262,11 @@ $(eval PREREQUISITES := $(1).d) $(1): $(2) @echo " PP $$<" - $$(Q)$$(AS) $$(ASFLAGS) -P -E -D__LINKER__ -o $$@ $$< + $$(Q)$$(CPP) $$(CPPFLAGS) -P -D__ASSEMBLY__ -D__LINKER__ -o $$@ $$< $(PREREQUISITES): $(2) | $(dir ${1}) @echo " DEPS $$@" - $$(Q)$$(AS) $$(ASFLAGS) -M -MT $(1) -MF $$@ $$< + $$(Q)$$(CPP) $$(CPPFLAGS) -D__ASSEMBLY__ -M -MT $(1) -MF $$@ $$< ifdef IS_ANYTHING_TO_BUILD -include $(PREREQUISITES) From 710ea1d01a1031dab06af3835c76b510d45cd362 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 22 Dec 2016 14:02:27 +0900 Subject: [PATCH 3/4] Build: generate .d file at the same time as object is created Currently, .d files are generated before any objects are built. So, IS_ANYTHING_TO_BUILD flag is needed to avoid such processing for non-build targets. There is a cleverer way; just create a .d file simultaneously when the corresponding object is created. No need to have separate rules for .d files. This commit will also fix a bug; -D$(IMAGE) is defined for $(OBJ), but not for $(PREREQUISITES). So, .d files are generated with different macro sets from those for .o files, then wrong .d files are generated. For example, in lib/cpus/aarch64/cpu_helpers.S #if IMAGE_BL31 #include #endif is parsed for the object when built for BL31, but the .d file does not pick up that dependency. With this commit, the compiler will generate .o and .d at the same time, guaranteeing they are generated under the same circumstances. Signed-off-by: Masahiro Yamada --- make_helpers/build_macros.mk | 61 ++++++++---------------------------- 1 file changed, 13 insertions(+), 48 deletions(-) diff --git a/make_helpers/build_macros.mk b/make_helpers/build_macros.mk index dd8c2b508..5de810b9d 100644 --- a/make_helpers/build_macros.mk +++ b/make_helpers/build_macros.mk @@ -184,24 +184,7 @@ endef # Auxiliary macros to build TF images from sources ################################################################################ -# If no goal is specified in the command line, .DEFAULT_GOAL is used. -# .DEFAULT_GOAL is defined in the main Makefile before including this file. -ifeq ($(MAKECMDGOALS),) -MAKECMDGOALS := $(.DEFAULT_GOAL) -endif - -define match_goals -$(strip $(foreach goal,$(1),$(filter $(goal),$(MAKECMDGOALS)))) -endef - -# List of rules that involve building things -BUILD_TARGETS := all bl1 bl2 bl2u bl31 bl32 certificates fip - -# Does the list of goals specified on the command line include a build target? -ifneq ($(call match_goals,${BUILD_TARGETS}),) -IS_ANYTHING_TO_BUILD := 1 -endif - +MAKE_DEP = -Wp,-MD,$(DEP) -MT $$@ # MAKE_C builds a C source file and generates the dependency file # $(1) = output directory @@ -210,20 +193,14 @@ endif define MAKE_C $(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2)))) -$(eval PREREQUISITES := $(patsubst %.o,%.d,$(OBJ))) +$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) $(eval IMAGE := IMAGE_BL$(call uppercase,$(3))) -$(OBJ): $(2) +$(OBJ): $(2) | bl$(3)_dirs @echo " CC $$<" - $$(Q)$$(CC) $$(TF_CFLAGS) $$(CFLAGS) -D$(IMAGE) -c $$< -o $$@ + $$(Q)$$(CC) $$(TF_CFLAGS) $$(CFLAGS) -D$(IMAGE) $(MAKE_DEP) -c $$< -o $$@ -$(PREREQUISITES): $(2) | bl$(3)_dirs - @echo " DEPS $$@" - $$(Q)$$(CC) $$(TF_CFLAGS) $$(CFLAGS) -M -MT $(OBJ) -MF $$@ $$< - -ifdef IS_ANYTHING_TO_BUILD --include $(PREREQUISITES) -endif +-include $(DEP) endef @@ -235,20 +212,14 @@ endef define MAKE_S $(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2)))) -$(eval PREREQUISITES := $(patsubst %.o,%.d,$(OBJ))) +$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) $(eval IMAGE := IMAGE_BL$(call uppercase,$(3))) -$(OBJ): $(2) +$(OBJ): $(2) | bl$(3)_dirs @echo " AS $$<" - $$(Q)$$(AS) $$(ASFLAGS) -D$(IMAGE) -c $$< -o $$@ + $$(Q)$$(AS) $$(ASFLAGS) -D$(IMAGE) $(MAKE_DEP) -c $$< -o $$@ -$(PREREQUISITES): $(2) | bl$(3)_dirs - @echo " DEPS $$@" - $$(Q)$$(AS) $$(ASFLAGS) -M -MT $(OBJ) -MF $$@ $$< - -ifdef IS_ANYTHING_TO_BUILD --include $(PREREQUISITES) -endif +-include $(DEP) endef @@ -258,19 +229,13 @@ endef # $(2) = input template define MAKE_LD -$(eval PREREQUISITES := $(1).d) +$(eval DEP := $(1).d) -$(1): $(2) +$(1): $(2) | $(dir ${1}) @echo " PP $$<" - $$(Q)$$(CPP) $$(CPPFLAGS) -P -D__ASSEMBLY__ -D__LINKER__ -o $$@ $$< + $$(Q)$$(CPP) $$(CPPFLAGS) -P -D__ASSEMBLY__ -D__LINKER__ $(MAKE_DEP) -o $$@ $$< -$(PREREQUISITES): $(2) | $(dir ${1}) - @echo " DEPS $$@" - $$(Q)$$(CPP) $$(CPPFLAGS) -D__ASSEMBLY__ -M -MT $(1) -MF $$@ $$< - -ifdef IS_ANYTHING_TO_BUILD --include $(PREREQUISITES) -endif +-include $(DEP) endef From 1d274ab00fce999b9ce39849d1db984aa59ae015 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 22 Dec 2016 15:23:05 +0900 Subject: [PATCH 4/4] Build: add -MP option to add dummy rules to *.d files This adds a phony target for each dependency other than the main file, causing each to depend on nothing. Without this, the incremental build will fail when a header file is removed. Signed-off-by: Masahiro Yamada --- make_helpers/build_macros.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/make_helpers/build_macros.mk b/make_helpers/build_macros.mk index 5de810b9d..bf9dc7949 100644 --- a/make_helpers/build_macros.mk +++ b/make_helpers/build_macros.mk @@ -184,7 +184,7 @@ endef # Auxiliary macros to build TF images from sources ################################################################################ -MAKE_DEP = -Wp,-MD,$(DEP) -MT $$@ +MAKE_DEP = -Wp,-MD,$(DEP) -MT $$@ -MP # MAKE_C builds a C source file and generates the dependency file # $(1) = output directory