[PATCH v1 2/5] Makefile: clean up unnecessary phony targets

Junjie Mao

Phony targets are mostly for recipes that are expected to be invoked
directly from the command line as a target and will always be executed. As
a result, it is in most cases not appropriate for a real file target to to
depend on a phony one, as that means the file will always be regenerated.

In the Makefile today, however, dependencies on phony targets are common
and cause the hypervisor to be fully rebuilt regardless of whether an
existing build exists or not.

This patch cleans up the following phony targets which are not meant to be
targets from the command line.

- pre_build: This target has three outputs, namely the prebuild checker,
the ACPI tables for pre-launched VMs and the serial.conf. It is split
into three targets, one for each output.

- headers: This target is an alias of dynamically-generated header
files. It is replaced with a variable so that targets depending on
"header" now depends on the actual header files generated.

With this patch, make will only rebuild modified files and targets
depending on them directly or indirectly.

Signed-off-by: Junjie Mao <junjie.mao@...>
hypervisor/Makefile | 33 +++++++++++++++++++--------------
misc/hv_prebuild/Makefile | 6 +++---
2 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/hypervisor/Makefile b/hypervisor/Makefile
index a077eb36d..3bd65a2d8 100644
--- a/hypervisor/Makefile
+++ b/hypervisor/Makefile
@@ -393,11 +393,15 @@ MODULES += $(SYS_INIT_MOD)

DISTCLEAN_OBJS := $(shell find $(BASEDIR) -name '*.o')
VERSION := $(HV_OBJDIR)/include/version.h

PRE_BUILD_DIR := ../misc/hv_prebuild
+PRE_BUILD_CHECKER := $(HV_OBJDIR)/hv_prebuild_check.out
+SERIAL_CONF = $(HV_OBJDIR)/serial.conf

.PHONY: all
-all: env_check pre_build $(HV_OBJDIR)/$(HV_FILE).32.out $(HV_OBJDIR)/$(HV_FILE).bin
+all: env_check $(ACPI_TABLE_TIMESTAMP) $(SERIAL_CONF) $(HV_OBJDIR)/$(HV_FILE).32.out $(HV_OBJDIR)/$(HV_FILE).bin

install: $(HV_OBJDIR)/$(HV_FILE).32.out $(HV_OBJDIR)/$(HV_FILE).bin
install -D $(HV_OBJDIR)/$(HV_FILE).32.out $(DESTDIR)$(libdir)/acrn/$(HV_FILE).$(BOARD).$(SCENARIO).32.out
@@ -419,18 +423,19 @@ ifndef ASL_COMPILER
$(error Please either install "iasl" or provide the path to "iasl" by using the ASL_COMPILER variable)

-.PHONY: pre_build
@echo "Start pre-build static check ..."
- @$(HV_OBJDIR)/hv_prebuild_check.out
@echo "generate the binary of ACPI tables for pre-launched VMs ..."
- python3 ../misc/config_tools/acpi_gen/bin_gen.py --board $(HV_OBJDIR)/.board.xml --scenario $(HV_OBJDIR)/.scenario.xml --asl $(HV_CONFIG_DIR) --out $(HV_OBJDIR) --iasl_path $(ASL_COMPILER) --iasl_min_ver $(IASL_MIN_VER)
- @echo "generate the serial configuration file for service VM ..."
- python3 ../misc/config_tools/service_vm_config/serial_config.py --allocation $(HV_OBJDIR)/configs/allocation.xml --scenario $(HV_OBJDIR)/.scenario.xml --out $(HV_OBJDIR)/serial.conf
+ python3 ../misc/config_tools/acpi_gen/bin_gen.py --board $(HV_BOARD_XML) --scenario $(HV_SCENARIO_XML) --asl $(HV_CONFIG_DIR) --out $(HV_OBJDIR) --iasl_path $(ASL_COMPILER) --iasl_min_ver $(IASL_MIN_VER)

-.PHONY: header
+ @echo "generate the serial configuration file for service VM ..."
+ python3 ../misc/config_tools/service_vm_config/serial_config.py --allocation $(HV_ALLOCATION_XML) --scenario $(HV_SCENARIO_XML) --out $(SERIAL_CONF)

.PHONY: lib-mod boot-mod hw-mod vp-base-mod vp-dm-mod vp-trusty-mod vp-x86tee-mod vp-hcall-mod sys-init-mod
@@ -480,7 +485,7 @@ sys-init-mod: $(SYS_INIT_MOD)

.PHONY: lib

-$(LIB_BUILD): header

lib: $(LIB_BUILD)
@@ -550,17 +555,17 @@ $(VERSION): $(HV_CONFIG_H)
-include $(C_OBJS:.o=.d)
-include $(S_OBJS:.o=.d)

-$(HV_OBJDIR)/%.o: %.c header
[ ! -e $@ ] && mkdir -p $(dir $@) && mkdir -p $(HV_MODDIR); \
$(CC) $(patsubst %, -I%, $(INCLUDE_PATH)) -I. -c $(CFLAGS) $(ARCH_CFLAGS) $< -o $@ -MMD -MT $@


-$(VM_CFG_C_OBJS): %.o: %.c header
[ ! -e $@ ] && mkdir -p $(dir $@) && mkdir -p $(HV_MODDIR); \
$(CC) $(patsubst %, -I%, $(INCLUDE_PATH)) -I. -c $(CFLAGS) $(ARCH_CFLAGS) $< -o $@ -MMD -MT $@

-$(HV_OBJDIR)/%.o: %.S header
[ ! -e $@ ] && mkdir -p $(dir $@) && mkdir -p $(HV_MODDIR); \
$(CC) $(patsubst %, -I%, $(INCLUDE_PATH)) -I. $(ASFLAGS) $(ARCH_ASFLAGS) -c $< -o $@ -MMD -MT $@

diff --git a/misc/hv_prebuild/Makefile b/misc/hv_prebuild/Makefile
index 846149d94..73fbf6f86 100644
--- a/misc/hv_prebuild/Makefile
+++ b/misc/hv_prebuild/Makefile
@@ -14,8 +14,8 @@ ifeq ($(SCENARIO),)
$(error please specify SCENARIO for the build!)

-ifeq ($(TARGET_DIR),)
- $(error please specify VM configs directory! )
+ifeq ($(CHECKER_OUT),)
+ $(error please specify the path to the generated checker! )

BOARD_INFO_DIR := $(HV_OBJDIR)/configs/boards
@@ -52,4 +52,4 @@ default: $(PRE_BUILD_SRCS)
else \
echo "Found $(BOARD) configuration for SCENARIO $(SCENARIO) under $(BOARD_CFG_DIR)"; \
- $(CC) $(PRE_BUILD_SRCS) $(PRE_BUILD_INCLUDE) $(PRE_BUILD_CFLAGS) -o $(HV_OBJDIR)/hv_prebuild_check.out