Initial commit

This commit is contained in:
Gatsby
2024-10-26 00:49:32 +08:00
commit b93e7f85a4
14 changed files with 1474 additions and 0 deletions
+110
View File
@@ -0,0 +1,110 @@
ifeq ($(VERBOSE),y)
else
HIDE = > /dev/zero
.SILENT:
endif
TIMESTAMP = $(shell date +"%T")
copy_files = cp $(1) $(2)
copy_dir = cp -r $(1) $(2)
remove_file = rm -rf $(1)
remove_dir = rm -rf $(1)
mk_dir = mkdir -p $(1)
read_file = cat $(1) 2>/dev/null
print_lines = echo $(1) | tr ' ' '\n'
green = \\e[32m$(1)\\e[39m
print = printf "$(call green,[$(TIMESTAMP)]) $(1)\n"
make_dir_link = ln -sfr $(1) $(2)
make_link = ln -sfr $(1) $(2)
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))')
update_files = $(call make_link,$(1),$(2))
update_dir = $(call make_dir_link,$(1),$(2))
ACTION = Linking
else
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
CURRENT_FILE := $(lastword $(MAKEFILE_LIST))
CURRENT_DIR := $(patsubst %/,%,$(dir $(CURRENT_FILE)))
SCRIPT_DIR := $(CURRENT_DIR)
endif
#------------------------------------------------------------------------------
# COMMON INITIALIZATION
#------------------------------------------------------------------------------
PLATFORM_TOOLS = $(SCRIPT_DIR)/platform/$(PLATFORM)
BUILD_LOCK = $(BUILD_DIR)/.project.lock
ifeq ('xilinx', '$(PLATFORM)')
include $(PLATFORM_TOOLS)/xilinx.mk
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
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
# Open the project using the corresponding SDK
sdkopen: $(PLATFORM)_sdkopen
# Remove build artefacts
PHONY += clean
ifneq ($(wildcard $(BUILD_LOCK)),)
clean:
$(call print,Cleaning sdk build uploaded to board)
$(MAKE) --no-print-directory $(PLATFORM)_sdkclean
else
clean:
$(call print,No project found, cleaning dummy files)
$(MAKE) --no-print-directory reset
endif
# Remove the whole build directory
PHONY += reset
reset: $(PLATFORM)_reset
$(call print,[Delete] $(BUILD_DIR))
$(call remove_dir,$(BUILD_DIR))
.PHONY: $(PHONY)