Compare commits

..
1 Commits
Author SHA1 Message Date
Gatsby a3f08704e6 doc: add common issue regarding symbolic links on Windows 2024-10-29 14:40:53 +08:00
6 changed files with 140 additions and 179 deletions
+65 -39
View File
@@ -5,48 +5,53 @@ HIDE = > /dev/zero
endif
TIMESTAMP = $(shell date +"%T")
cmd_copy = cp -a $(1) $(2)
cmd_link = ln -sfr $(1) $(2)
cmd_remove = rm -rf $(1)
cmd_mkdir = mkdir -p $(1)
cmd_cat = cat $(1) 2>/dev/null
cmd_print_lines = echo $(1) | tr ' ' '\n'
color_green = \033[32m$(1)\033[0m
log = @printf "$(call color_green,[$(TIMESTAMP)]) %s\n" "$(1)"
show_build_type = $(call log,Building for $(call green,$(1)))
check-var = $(if $(strip $($(1))),,$(error [ERROR] Missing required variable: $(1)))
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)))
$(call check-var,PROJECT)
$(call check-var,PLATFORM)
$(call check-var,BUILD_DIR)
$(call check-var,CONFIG_FILE)
$(call check-var,LINK_SRCS)
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
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
#------------------------------------------------------------------------------
PLATFORM_TOOLS = $(SCRIPT_DIR)/platform/$(PLATFORM)
BUILD_LOCK = $(BUILD_DIR)/.build.lock
PROJECT_LOCK = $(BUILD_DIR)/.project.lock
BUILD_LOCK = $(BUILD_DIR)/.project.lock
ifeq ('xilinx', '$(PLATFORM)')
include $(PLATFORM_TOOLS)/xilinx.mk
@@ -57,28 +62,49 @@ endif
# Generic Goals
#------------------------------------------------------------------------------
PHONY := clean reset project build sdkopen
.DEFAULT_GOAL := project
.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
# Create project using corresponding SDK
project: $(PLATFORM)_project
@echo "$(TIMESTAMP): Build lock." > $(BUILD_LOCK)
# Build project using corresponding compiler
build: project $(PLATFORM)_sdkbuild
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: project $(PLATFORM)_sdkopen
sdkopen: $(PLATFORM)_sdkopen
# Remove build artefacts
PHONY += clean
ifneq ($(wildcard $(BUILD_LOCK)),)
clean: $(PLATFORM)_sdkclean
clean:
$(call print,Cleaning sdk build uploaded to board)
$(MAKE) --no-print-directory $(PLATFORM)_sdkclean
else
clean: reset
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 log,[Delete] $(BUILD_DIR))
@$(call cmd_remove,$(BUILD_DIR))
$(call print,[Delete] $(BUILD_DIR))
$(call remove_dir,$(BUILD_DIR))
.PHONY: $(PHONY)
+6 -10
View File
@@ -44,7 +44,7 @@
- **project_name**: 项目名称,例如 `"demo"`。
- **version**: 项目版本,例如 `"0.0.0"`。
- **hw_design**: 硬件设计文件(`.hdf` 或 `.xsa` 文件)路径(相对档案工作路径),例如 `"demo_v0.0.0.hdf"`。
- **hw_design**: 硬件设计文件(`.hdf` 或 `.xsa` 文件)路径(相对配置文件路径),例如 `"demo_v0.0.0.hdf"`。
### *fsbl_patch* (TODO)
@@ -135,7 +135,6 @@
"target_cpu": "<cpu_id>",
"os": "<os_type>",
"language": "<language>",
"template": "<app_template>",
"bsp": "<bsp_name>",
"bsp_lib": {
"<lib_name>": {
@@ -172,12 +171,11 @@
}
```
- **sources**: 源文件列表,可使用通配符。例如,`"src/*"` 会将当前工作路径下的 `src` 文件夹中的所有文件复制或链接到相应工程目录下的 `src` 文件夹中。
- **sources**: 源文件列表,应为相对当前配置文件的路径,可使用通配符。例如,`"src/*"` 会将配置文件所在目录下的 `src` 文件夹中的所有文件复制或链接到相应工程目录下的 `src` 文件夹中。
- **target_cpu**: 目标 CPU ID[^2];
- **os**: 操作系统类型[^1],必须与 BSP/Domain 匹配;
- **language**: 编程语言,"C" 或 "C++";
- *template*: 所使用的应用模板名称,不指定则默认为对应语言的 “Empty Application”;
- *bsp*: 应用所使用的 BSP 名称,若未指定则会自动创建名为 `<app_name>_bsp` 的 BSP/Domain.
- *bsp*: 应用所使用的 BSP 名称,若未指定则会自动创建名为 `<os>_<cpu_id>` 的 BSP/Domain.
- *bsp_lib*: 针对自动创建的 BSP/Domain 所使用库的配置,与 [bsps](#bsps) 中 `libs` 对应;
- *bsp_config*: 针对自动创建的 BSP/Domain 配置与 [bsps](#bsps) 中 `config` 对应;
- *mem_layout*: 应用内存布局,包括堆栈大小和堆大小等;
@@ -188,12 +186,12 @@
- `compiler-misc`: 其他编译器选项;
- `compiler-optimization`: 编译优化选项;
- `linker-misc`: 链接器选项;
- `linker-script`: 链接脚本路径[^3];
- `linker-script`: 链接脚本路径;
- `define-compiler-symbols`: 自定义的编译器宏定义符号列表;
- `undef-compiler-symbols`: 要取消定义的符号列表;
- `include-path`: 包含文件路径[^3];
- `include-path`: 包含文件路径;
- `libraries`: 需要链接的库;
- `library-search-path`: 库搜索路径[^3];
- `library-search-path`: 库搜索路径;
以下配置添加了一个名为 `demo_app` 的 Application 工程,该工程没有指定 BSP/Domain 但能够通过 `bsp_lib` 和 `bsp_config` 自动生成一个名为 `standalone_ps7_cortexa9_0` 的 BSP/Domain 工程。
@@ -239,5 +237,3 @@
[^1]: 具体可配置项取决于对应 IDE 版本;
[^2]: 具体可选 CPU ID 取决于硬件型号;
[^3]: 相对对应工程的文件夹的路径;
-1
View File
@@ -31,7 +31,6 @@
"target_cpu": "<cpu_id>",
"os": "<os_type>",
"language": "<language>",
"template": "<app_template>",
"bsp": "<bsp_name>",
"bsp_lib": {
"<lib_name>": {
+46 -97
View File
@@ -81,7 +81,6 @@ proc _configure_bsp {bsp_name bsp_config platform_name is_vitis} {
if {$is_vitis} {
bsp regenerate
platform generate -domains "$bsp_name"
} else {
regenbsp -bsp $bsp_name
projects -build -type bsp -name $bsp_name
@@ -90,46 +89,6 @@ proc _configure_bsp {bsp_name bsp_config platform_name is_vitis} {
return $bsp_name
}
# Helper procedure to recursively create hard links for files in a directory
proc _link_or_copy_dir {source_dir target_dir link_mode} {
# Create target directory if it doesn't exist
if {![file exists $target_dir]} {
file mkdir $target_dir
_info "Created directory: $target_dir"
}
# Process each file and subdirectory in the source directory
foreach item [glob -nocomplain -directory $source_dir *] {
set item_name [file tail $item]
set target_item [file join $target_dir $item_name]
# Remove existing file or directory
if {[file exists $target_item]} {
file delete -force $target_item
_warn "Deleted existing item: $target_item"
}
if {[file isfile $item]} {
# Handle file - create hard link or copy
if {$link_mode eq "y"} {
if {[catch {
file link -hard $target_item $item
} err]} {
error "Failed to create hard link: $err"
} else {
_info "Created hard link: $target_item -> $item"
}
} else {
file copy $item $target_item
_info "Copied file: $item to $target_item"
}
} elseif {[file isdirectory $item]} {
# Handle subdirectory recursively
_link_or_copy_dir $item $target_item $link_mode
}
}
}
# Helper procedure to handle source files: link or copy based on LINK_SRCS
proc _handle_sources {app_name sources} {
# Check environment variable LINK_SRCS
@@ -144,41 +103,53 @@ proc _handle_sources {app_name sources} {
if {[llength $expanded_sources] == 0} {
_error "Source file not found" "No file or directory matches $source_file"
}
# Handle each expanded source
# Hanle each expanded source
foreach eval_source $expanded_sources {
set relative_source [string range $eval_source [expr [string length $::root] + 1] end]
set target_path [file join $::ws $app_name $relative_source]
if {[file isfile $eval_source]} {
# For files, ensure the parent directory exists
set target_dir [file dirname $target_path]
if {![file exists $target_dir]} {
file mkdir $target_dir
_info "Created directory: $target_dir"
}
# Ensure the target directory exists
set target_dir [file dirname $target_path]
if {![file exists $target_dir]} {
file mkdir $target_dir
_info "Created directory: $target_dir"
}
# Delete existing file if it exists
if {[file exists $target_path]} {
file delete -force $target_path
_warn "Deleted existing file: $target_path"
}
# Delete existing symbolic link or file if it exists
if {[file exists $target_path]} {
file delete -force $target_path
_warn "Deleted existing link or file: $target_path"
}
# Handle file based on LINK_SRCS
if {$link_srcs eq "y"} {
if {[catch {
file link -hard $target_path $eval_source
} err]} {
error "Failed to create hard link: $err"
# Handle source based on the value of LINK_SRCS
switch $link_srcs {
"y" {
# Create symbolic link
# -- TCL cannont create symbolic link for files on Windows
# -- Fallback to use mklink command
if {$::tcl_platform(platform) eq "windows" && ![file isdirectory $eval_source]} {
if {[catch {
exec cmd /c mklink [file nativename $target_path] [file nativename $eval_source]
} err]} {
error "Failed to create file symbolic link using mklink: $err"
}
} else {
if {[catch {
file link -symbolic $target_path $eval_source
} err]} {
error "Failed to create symbolic link: $err"
}
}
_info "Created hard link: $target_path -> $eval_source"
} else {
file copy $eval_source $target_path
_info "Copied file: $eval_source to $target_path"
_info "Created symbolic link: $target_path -> $eval_source"
}
"n" {
# Copy the source file
file copy $eval_source $target_path
_info "Copied source file: $eval_source to $target_path"
}
default {
_error "Unknown value for LINK_SRCS: ${link_srcs}."
}
} else {
# For directories, use the helper function
_link_or_copy_dir $eval_source $target_path $link_srcs
}
}
}
@@ -261,8 +232,7 @@ proc _update_app_build_config {app_name build_type build_config is_vitis} {
"linker-misc" -
"linker-script" {
if {$value ne ""} {
set value_list [list $value]
eval $cmd $app_name -set $param $value_list
eval $cmd $app_name -set $param $value
_info "Set $param: $value for $app_name."
}
}
@@ -277,33 +247,13 @@ proc _update_app_build_config {app_name build_type build_config is_vitis} {
proc _create_app {app_name app_config platform_name is_vitis} {
set cpu [dict get $app_config target_cpu]
set os [dict get $app_config os]
set sources [dict get $app_config sources]
set bsp_name "${app_name}_bsp"
set lang [dict get $app_config language]
if { $lang ne "C" && $lang ne "C++" } {
_error "Unsupport language" "language should be C or C++"
}
if { [dict exists $app_config template] } {
set template [dict get $app_config template]
} elseif { !$is_vitis } {
set template "Empty Application"
} elseif { $lang eq "C++" } {
set template "Empty Application (C++)"
} else {
set template "Empty Application(C)"
}
set sources [dict get $app_config sources]
set bsp_name "${os}_${cpu}"
# Configure BSP/Domain for application
if {[dict exists $app_config bsp] && [dict get $app_config bsp] ne ""} {
set bsp_name [dict get $app_config bsp]
if {![dict exists $::config bsps]} {
_error "BSP configuration missing" "The 'bsps' section is not found in the configuration."
} elseif {![dict exists [dict get $::config bsps] $bsp_name]} {
_error "BSP configuration missing" "No configuration found for BSP '$bsp_name' in the 'bsps' section."
} else {
_info "Configuring BSP '$bsp_name' for application '$app_name'."
}
} else {
set bsp_config [dict create]
set bsp_config [dict set bsp_config target_cpu $cpu]
@@ -316,7 +266,6 @@ proc _create_app {app_name app_config platform_name is_vitis} {
set bsp_cfg [dict get $app_config bsp_config]
set bsp_config [dict merge $bsp_config [dict create config $bsp_cfg]]
}
_info "Creating BSP $bsp_name for Application $app_name ..."
_configure_bsp $bsp_name $bsp_config $platform_name $is_vitis
}
@@ -330,7 +279,7 @@ proc _create_app {app_name app_config platform_name is_vitis} {
-os $os \
-lang $lang \
-sysproj $::project_name \
-template "$template"
-template "Empty Application($lang)"
_info "Application '$app_name' created for Vitis."
} else {
sdk createapp -name $app_name \
@@ -339,7 +288,7 @@ proc _create_app {app_name app_config platform_name is_vitis} {
-proc $cpu \
-os $os \
-lang $lang \
-app "$template"
-app "Empty Application"
_info "Application '$app_name' created for Xilinx SDK."
}
@@ -466,10 +415,10 @@ _info "Working at $ws"
set config_file_id [open $config_file r]
set config_data [read $config_file_id]
close $config_file_id
set root [pwd]
set root [file dirname [file normalize $config_file]]
set config [json::json2dict $config_data]
set project_name [dict get $config project_name]
set hw_file [file normalize [file join $root [dict get $config hw_design]]]
set hw_file [file normalize [file join [file dirname $config_file] [dict get $config hw_design]]]
_info "Starting process: $function"
_info "Project name: $project_name"
+17 -24
View File
@@ -1,21 +1,14 @@
$(call check-var,XILINX_VITIS_CLASSIC)
$(call check-var,PLATFORM_TOOLS)
$(call check-var,CONFIG_FILE)
$(call check-var,BUILD_DIR)
$(call check-var,PROJECT_LOCK)
$(call check-var,BUILD_LOCK)
$(call check-var,LINK_SRCS)
#------------------------------------------------------------------------------
# ENVIRONMENT VARIABLES
#------------------------------------------------------------------------------
define tcl_util
xsct -nodisp $(PLATFORM_TOOLS)/util.tcl \
$(1) \
$(CONFIG_FILE) $(BUILD_DIR)
xsct -nodisp $(PLATFORM_TOOLS)/util.tcl \
$(1) \
$(CONFIG_FILE) $(BUILD_DIR)
endef
PHONY += xilinx_reset xilinx_project xilinx_sdkclean xilinx_sdkbuild
xilinx_sdkopen:
@$(call log,Launching IDE...)
$(call print,Launching IDE...)
@if [ "$(call check_command,vitis)" = "y" ]; then \
if [ "$(XILINX_VITIS_CLASSIC)" = "y" ]; then \
vitis -classic -workspace=$(BUILD_DIR); \
@@ -28,22 +21,22 @@ xilinx_sdkopen:
echo "No IDE found!" && exit 1; \
fi
PHONY += xilinx_sdkbuild
xilinx_sdkbuild:
@$(call log,[Build] SDK projects in $(BUILD_DIR))
$(call print,[Build] SDK projects in $(BUILD_DIR))
$(call tcl_util, build) $(HIDE)
@echo "$(TIMESTAMP): Build lock." > $(BUILD_LOCK)
PHONY += xilinx_sdkclean
xilinx_sdkclean:
@$(call log,[Delete] SDK artefacts from $(BUILD_DIR))
$(call print,[Delete] SDK artefacts from $(BUILD_DIR))
$(call tcl_util, clean_project) $(HIDE)
$(PROJECT_LOCK):
@$(call log,Creating and configuring the IDE project)
@$(call cmd_mkdir,$(BUILD_DIR))
xilinx_project:
$(call mk_dir,$(BUILD_DIR))
$(call print,Creating and configuring the IDE project)
$(call tcl_util, create_project) $(HIDE)
@echo "$(TIMESTAMP): Project lock." > $@
xilinx_project: $(PROJECT_LOCK)
xilinx_reset: xilinx_clean_all
xilinx_reset:
$(call cmd_remove,.Xil) $(HIDE)
xilinx_clean_all:
$(call remove_dir,.Xil) $(HIDE)
+6 -8
View File
@@ -1,16 +1,14 @@
@echo off
cd /d "%~dp0"
set "platform=xilinx"
set "platform_ver=2019.1"
set "pltform_ver=2019.1"
set "work_dir=%~dp0build"
set "config=%~dp0config.json"
set "tools_dir=%~dp0scripts\platform\%platform%"
REM Set up environment
call "%tools_dir%\setenv.bat" "%platform_ver%"
REM Set up enviroment
call "%tools_dir%\setenv.bat" "%pltform_ver%"
if "%ERRORLEVEL%" neq "0" (
echo Error: Failed to initialize environment.
echo Error: Failed to installize enviroment.
pause >nul
exit /b 1
)
@@ -23,8 +21,8 @@ if "%ERRORLEVEL%" neq "0" (
exit /b 1
)
REM Launch SDK
call "%tools_dir%\launch.bat" "%platform_ver%" "%work_dir%"
REM Lauch SDK
call "%tools_dir%\launch.bat" "%pltform_ver%" "%work_dir%"
if "%ERRORLEVEL%" neq "0" (
echo Error: Failed to launch SDK.
pause >nul