Makefile: clean up unnecessary phony targets

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.

Tracked-On: #8259
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
This commit is contained in:
Junjie Mao 2022-10-14 21:00:11 +08:00 committed by acrnsi-robot
parent 0e8ce66af9
commit cdf7796a62
2 changed files with 23 additions and 18 deletions

View File

@ -393,11 +393,15 @@ MODULES += $(SYS_INIT_MOD)
DISTCLEAN_OBJS := $(shell find $(BASEDIR) -name '*.o')
VERSION := $(HV_OBJDIR)/include/version.h
HEADERS := $(VERSION) $(HV_CONFIG_H) $(HV_CONFIG_TIMESTAMP)
PRE_BUILD_DIR := ../misc/hv_prebuild
PRE_BUILD_CHECKER := $(HV_OBJDIR)/hv_prebuild_check.out
HV_ACPI_TABLE_TIMESTAMP := $(HV_OBJDIR)/acpi.timestamp
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 $(HV_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)
endif
.PHONY: pre_build
pre_build: $(HV_CONFIG_H) $(HV_CONFIG_TIMESTAMP)
$(PRE_BUILD_CHECKER): $(HV_CONFIG_H) $(HV_CONFIG_TIMESTAMP)
@echo "Start pre-build static check ..."
$(MAKE) -C $(PRE_BUILD_DIR) BOARD=$(BOARD) SCENARIO=$(SCENARIO) TARGET_DIR=$(HV_CONFIG_DIR)
@$(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
$(MAKE) -C $(PRE_BUILD_DIR) BOARD=$(BOARD) SCENARIO=$(SCENARIO) CHECKER_OUT=$(PRE_BUILD_CHECKER)
@$(PRE_BUILD_CHECKER)
.PHONY: header
header: $(VERSION) $(HV_CONFIG_H) $(HV_CONFIG_TIMESTAMP)
$(HV_ACPI_TABLE_TIMESTAMP): $(HV_CONFIG_TIMESTAMP)
@echo "generate the binary of ACPI tables for pre-launched VMs ..."
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)
@touch $(HV_ACPI_TABLE_TIMESTAMP)
$(SERIAL_CONF): $(HV_CONFIG_TIMESTAMP)
@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
$(LIB_MOD): $(LIB_C_OBJS) $(LIB_S_OBJS)
@ -480,7 +485,7 @@ sys-init-mod: $(SYS_INIT_MOD)
.PHONY: lib
$(LIB_BUILD): header
$(LIB_BUILD): $(HEADERS)
$(MAKE) -f $(LIB_MK) MKFL_NAME=$(LIB_MK)
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
$(HV_OBJDIR)/%.o: %.c $(HEADERS) $(PRE_BUILD_CHECKER)
[ ! -e $@ ] && mkdir -p $(dir $@) && mkdir -p $(HV_MODDIR); \
$(CC) $(patsubst %, -I%, $(INCLUDE_PATH)) -I. -c $(CFLAGS) $(ARCH_CFLAGS) $< -o $@ -MMD -MT $@
$(VM_CFG_C_SRCS): %.c: $(HV_CONFIG_TIMESTAMP)
$(VM_CFG_C_OBJS): %.o: %.c header
$(VM_CFG_C_OBJS): %.o: %.c $(HEADERS) $(PRE_BUILD_CHECKER)
[ ! -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
$(HV_OBJDIR)/%.o: %.S $(HEADERS) $(PRE_BUILD_CHECKER)
[ ! -e $@ ] && mkdir -p $(dir $@) && mkdir -p $(HV_MODDIR); \
$(CC) $(patsubst %, -I%, $(INCLUDE_PATH)) -I. $(ASFLAGS) $(ARCH_ASFLAGS) -c $< -o $@ -MMD -MT $@

View File

@ -14,8 +14,8 @@ ifeq ($(SCENARIO),)
$(error please specify SCENARIO for the build!)
endif
ifeq ($(TARGET_DIR),)
$(error please specify VM configs directory! )
ifeq ($(CHECKER_OUT),)
$(error please specify the path to the generated checker! )
endif
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)"; \
fi;
$(CC) $(PRE_BUILD_SRCS) $(PRE_BUILD_INCLUDE) $(PRE_BUILD_CFLAGS) -o $(HV_OBJDIR)/hv_prebuild_check.out
$(CC) $(PRE_BUILD_SRCS) $(PRE_BUILD_INCLUDE) $(PRE_BUILD_CFLAGS) -o $(CHECKER_OUT)