From 5fd695266f27a5f8d1bd9bfa5ecece1d042d99e6 Mon Sep 17 00:00:00 2001 From: Gatsby Date: Fri, 9 May 2025 22:27:52 +0800 Subject: [PATCH] refactor(make): reorganize targets and improve locking mechanism MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Introduce a “project lock” mechanism alongside the existing “build lock”; the lock file is now generated within the platform-specific Makefile. 2. Set `project` as the default Makefile goal for consistency. 3. Remove the `standalone` target to improve compatibility, especially when invoked via `make -f`. 4. Simplify target dependencies for better maintainability and clarity. --- generic.mk | 39 ++++++++++----------------------------- platform/xilinx/xilinx.mk | 13 +++++++++---- 2 files changed, 19 insertions(+), 33 deletions(-) diff --git a/generic.mk b/generic.mk index f304fc5..8647752 100644 --- a/generic.mk +++ b/generic.mk @@ -45,7 +45,8 @@ endif # COMMON INITIALIZATION #------------------------------------------------------------------------------ PLATFORM_TOOLS = $(SCRIPT_DIR)/platform/$(PLATFORM) -BUILD_LOCK = $(BUILD_DIR)/.project.lock +BUILD_LOCK = $(BUILD_DIR)/.build.lock +PROJECT_LOCK = $(BUILD_DIR)/.project.lock ifeq ('xilinx', '$(PLATFORM)') include $(PLATFORM_TOOLS)/xilinx.mk @@ -56,43 +57,23 @@ endif # Generic Goals #------------------------------------------------------------------------------ -.DEFAULT_GOAL := all -PHONY += all -ifneq ($(wildcard $(BUILD_LOCK)),) -all: - @$(call print_build_type,$(PLATFORM)) - $(MAKE) --no-print-directory build - @$(call print,Done ($(notdir $(BUILD_DIR)))) -else -all: - @$(call print_build_type,$(PLATFORM)) - $(MAKE) --no-print-directory project - $(MAKE) --no-print-directory build - @$(call print,Done ($(notdir $(BUILD_DIR)))) -endif +PHONY := clean reset project build sdkopen +.DEFAULT_GOAL := project +# Create project using corresponding SDK project: $(PLATFORM)_project - @echo "$(TIMESTAMP): Build lock." > $(BUILD_LOCK) -standalone: - $(MAKE) --no-print-directory project LINK_SRCS=n - -# Build project using generic compiler -build: $(PLATFORM)_sdkbuild +# Build project using corresponding compiler +build: project $(PLATFORM)_sdkbuild # Open the project using the corresponding SDK -sdkopen: $(PLATFORM)_sdkopen +sdkopen: project $(PLATFORM)_sdkopen # Remove build artefacts -PHONY += clean ifneq ($(wildcard $(BUILD_LOCK)),) -clean: - @$(call log,Cleaning sdk build uploaded to board) - $(MAKE) --no-print-directory $(PLATFORM)_sdkclean +clean: $(PLATFORM)_sdkclean else -clean: - @$(call log,No project found, cleaning dummy files) - $(MAKE) --no-print-directory reset +clean: reset endif # Remove the whole build directory diff --git a/platform/xilinx/xilinx.mk b/platform/xilinx/xilinx.mk index 15fc5e1..19b3e91 100644 --- a/platform/xilinx/xilinx.mk +++ b/platform/xilinx/xilinx.mk @@ -7,6 +7,8 @@ define tcl_util $(CONFIG_FILE) $(BUILD_DIR) endef +PHONY += xilinx_reset xilinx_project xilinx_sdkclean xilinx_sdkbuild + xilinx_sdkopen: @$(call log,Launching IDE...) @if [ "$(call check_command,vitis)" = "y" ]; then \ @@ -21,19 +23,22 @@ xilinx_sdkopen: echo "No IDE found!" && exit 1; \ fi -PHONY += xilinx_sdkbuild xilinx_sdkbuild: @$(call log,[Build] SDK projects in $(BUILD_DIR)) $(call tcl_util, build) $(HIDE) + @echo "$(TIMESTAMP): Build lock." > $(BUILD_LOCK) xilinx_sdkclean: @$(call log,[Delete] SDK artefacts from $(BUILD_DIR)) $(call tcl_util, clean_project) $(HIDE) -xilinx_project: - @$(call print,Creating and configuring the IDE project) - $(call mk_dir,$(BUILD_DIR)) +$(XILINX_PROJECT_LOCK): + @$(call log,Creating and configuring the IDE project) + @$(call cmd_mkdir,$(BUILD_DIR)) $(call tcl_util, create_project) $(HIDE) + @echo "$(TIMESTAMP): Project lock." > $@ + +xilinx_project: $(PROJECT_LOCK) xilinx_reset: $(call cmd_remove,.Xil) $(HIDE) \ No newline at end of file