Files
hldrCenter/server/package.sh
2025-11-03 00:08:48 +08:00

43 lines
1.3 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 设置目标文件夹和项目名称
target_dir="./software/hldrCenter"
project_name="hldrCenter"
# 创建目标文件夹(若不存在)
mkdir -p "$target_dir"
# 定义目标平台列表格式GOOS/GOARCH
platforms=(
"linux/amd64" # Linux 64位
"darwin/amd64" # MacIntel芯片64位
# 如需支持Mac Apple Silicon可添加darwin/arm64
)
# 遍历每个平台进行打包
for platform in "${platforms[@]}"; do
# 解析平台信息
IFS='/' read -r goos goarch <<< "$platform"
# 设置平台相关的环境变量
export CGO_ENABLED=0 # 禁用CGO确保纯静态编译跨平台兼容
export GOOS="$goos"
export GOARCH="$goarch"
# 生成输出文件名Mac需加.dmg后缀Linux用可执行文件
if [ "$goos" = "darwin" ]; then
output_file="${project_name}-${goos}-${goarch}.dmg"
else
output_file="${project_name}-${goos}-${goarch}"
fi
# 执行打包命令
echo "正在打包 $platform 平台..."
env GOOS="$goos" GOARCH="$goarch" CGO_ENABLED=0 go build -o "$target_dir/$output_file" .
# 检查打包结果
if [ $? -eq 0 ]; then
echo "$platform 平台打包成功,文件路径:$target_dir/$output_file"
else
echo "$platform 平台打包失败"
fi
done