chore: refine common commands

This commit is contained in:
Gatsby
2025-05-09 22:22:40 +08:00
parent 751071d670
commit 698e123a26
2 changed files with 35 additions and 43 deletions
+31 -38
View File
@@ -5,48 +5,42 @@ HIDE = > /dev/zero
endif endif
TIMESTAMP = $(shell date +"%T") TIMESTAMP = $(shell date +"%T")
copy_files = cp $(1) $(2) cmd_copy = cp -a $(1) $(2)
copy_dir = cp -r $(1) $(2) cmd_link = ln -sfr $(1) $(2)
remove_file = rm -rf $(1) cmd_remove = rm -rf $(1)
remove_dir = rm -rf $(1) cmd_mkdir = mkdir -p $(1)
mk_dir = mkdir -p $(1) cmd_cat = cat $(1) 2>/dev/null
read_file = cat $(1) 2>/dev/null cmd_print_lines = echo $(1) | tr ' ' '\n'
print_lines = echo $(1) | tr ' ' '\n'
green = \\e[32m$(1)\\e[39m color_green = \033[32m$(1)\033[0m
print = printf "$(call green,[$(TIMESTAMP)]) $(1)\n" log = @printf "$(call color_green,[$(TIMESTAMP)]) %s\n" "$(1)"
make_dir_link = ln -sfr $(1) $(2) show_build_type = $(call log,Building for $(call green,$(1)))
make_link = ln -sfr $(1) $(2)
check-var = $(if $(strip $($(1))),,$(error [ERROR] Missing required variable: $(1)))
check_command = $(shell which $(1) > /dev/null 2>&1 && echo y || echo n) check_command = $(shell which $(1) > /dev/null 2>&1 && echo y || echo n)
print_build_type = $(call print,Building for $(call green,$(1)))
ifeq ('y', '$(strip $(LINK_SRCS))') $(call check-var,PROJECT)
update_files = $(call make_link,$(1),$(2)) $(call check-var,PLATFORM)
update_dir = $(call make_dir_link,$(1),$(2)) $(call check-var,BUILD_DIR)
ACTION = Linking $(call check-var,CONFIG_FILE)
else $(call check-var,LINK_SRCS)
update_files = $(call copy_files,$(1),$(dir $(2)))
update_dir = $(call copy_dir,$(1),$(2))
ACTION = Copying
endif
ifndef PROJECT
@$(error "PROJECT variable needs to be set")
endif
ifndef PLATFORM
@$(error "PLATFORM variable needs to be set")
endif
ifndef BUILD_DIR
@$(error "BUILD_DIR variable needs to be set")
endif
ifndef CONFIG_FILE
@$(error "CONFIG_FILE variable needs to be set")
endif
ifndef SCRIPT_DIR ifndef SCRIPT_DIR
CURRENT_FILE := $(lastword $(MAKEFILE_LIST)) CURRENT_FILE := $(lastword $(MAKEFILE_LIST))
CURRENT_DIR := $(patsubst %/,%,$(dir $(CURRENT_FILE))) CURRENT_DIR := $(patsubst %/,%,$(dir $(CURRENT_FILE)))
SCRIPT_DIR := $(CURRENT_DIR) SCRIPT_DIR := $(CURRENT_DIR)
endif endif
ifeq ($(strip $(LINK_SRCS)),y)
update_files = $(call cmd_link,$(1),$(2))
update_dir = $(call cmd_link,$(1),$(2))
ACTION = Linking
else
update_files = $(call cmd_copy,$(1),$(dir $(2)))
update_dir = $(call cmd_copy,$(1),$(2))
ACTION = Copying
endif
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# COMMON INITIALIZATION # COMMON INITIALIZATION
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
@@ -93,18 +87,17 @@ sdkopen: $(PLATFORM)_sdkopen
PHONY += clean PHONY += clean
ifneq ($(wildcard $(BUILD_LOCK)),) ifneq ($(wildcard $(BUILD_LOCK)),)
clean: clean:
@$(call print,Cleaning sdk build uploaded to board) @$(call log,Cleaning sdk build uploaded to board)
$(MAKE) --no-print-directory $(PLATFORM)_sdkclean $(MAKE) --no-print-directory $(PLATFORM)_sdkclean
else else
clean: clean:
@$(call print,No project found, cleaning dummy files) @$(call log,No project found, cleaning dummy files)
$(MAKE) --no-print-directory reset $(MAKE) --no-print-directory reset
endif endif
# Remove the whole build directory # Remove the whole build directory
PHONY += reset
reset: $(PLATFORM)_reset reset: $(PLATFORM)_reset
@$(call print,[Delete] $(BUILD_DIR)) @$(call log,[Delete] $(BUILD_DIR))
@$(call remove_dir,$(BUILD_DIR)) @$(call cmd_remove,$(BUILD_DIR))
.PHONY: $(PHONY) .PHONY: $(PHONY)
+4 -5
View File
@@ -8,7 +8,7 @@ define tcl_util
endef endef
xilinx_sdkopen: xilinx_sdkopen:
@$(call print,Launching IDE...) @$(call log,Launching IDE...)
@if [ "$(call check_command,vitis)" = "y" ]; then \ @if [ "$(call check_command,vitis)" = "y" ]; then \
if [ "$(XILINX_VITIS_CLASSIC)" = "y" ]; then \ if [ "$(XILINX_VITIS_CLASSIC)" = "y" ]; then \
vitis -classic -workspace=$(BUILD_DIR); \ vitis -classic -workspace=$(BUILD_DIR); \
@@ -23,12 +23,11 @@ xilinx_sdkopen:
PHONY += xilinx_sdkbuild PHONY += xilinx_sdkbuild
xilinx_sdkbuild: xilinx_sdkbuild:
@$(call print,[Build] SDK projects in $(BUILD_DIR)) @$(call log,[Build] SDK projects in $(BUILD_DIR))
$(call tcl_util, build) $(HIDE) $(call tcl_util, build) $(HIDE)
PHONY += xilinx_sdkclean
xilinx_sdkclean: xilinx_sdkclean:
@$(call print,[Delete] SDK artefacts from $(BUILD_DIR)) @$(call log,[Delete] SDK artefacts from $(BUILD_DIR))
$(call tcl_util, clean_project) $(HIDE) $(call tcl_util, clean_project) $(HIDE)
xilinx_project: xilinx_project:
@@ -37,4 +36,4 @@ xilinx_project:
$(call tcl_util, create_project) $(HIDE) $(call tcl_util, create_project) $(HIDE)
xilinx_reset: xilinx_reset:
$(call remove_dir,.Xil) $(HIDE) $(call cmd_remove,.Xil) $(HIDE)