@echo off
REM Windows 编译脚本

echo 开始编译 Go 项目...

set APP_NAME=software-download-center
set BUILD_DIR=build
set OUTPUT_DIR=%BUILD_DIR%\output

REM 创建输出目录
if not exist %OUTPUT_DIR% mkdir %OUTPUT_DIR%

echo 编译 Windows 版本...
set GOOS=windows
set GOARCH=amd64
go build -ldflags="-s -w" -o %OUTPUT_DIR%\%APP_NAME%_windows_amd64.exe .

echo 编译 Linux 版本...
set GOOS=linux
set GOARCH=amd64
go build -ldflags="-s -w" -o %OUTPUT_DIR%\%APP_NAME%_linux_amd64.exe .

echo 编译 macOS 版本...
set GOOS=darwin
set GOARCH=amd64
go build -ldflags="-s -w" -o %OUTPUT_DIR%\%APP_NAME%_darwin_amd64.exe .
set GOARCH=arm64
go build -ldflags="-s -w" -o %OUTPUT_DIR%\%APP_NAME%_darwin_arm64.exe .

REM 复制必要文件
echo 复制必要文件...
xcopy /E /I /Y public %OUTPUT_DIR%\public
xcopy /E /I /Y views %OUTPUT_DIR%\views
copy README.md %OUTPUT_DIR% >nul 2>&1
copy ADMIN.md %OUTPUT_DIR% >nul 2>&1

REM 创建启动脚本
echo @echo off > %OUTPUT_DIR%\start.bat
echo REM Windows 启动脚本 >> %OUTPUT_DIR%\start.bat
echo. >> %OUTPUT_DIR%\start.bat
echo set PORT=3355 >> %OUTPUT_DIR%\start.bat
echo if not "%%PORT%%"=="" set PORT=%%PORT%% >> %OUTPUT_DIR%\start.bat
echo echo 启动服务器，端口: %%PORT%% >> %OUTPUT_DIR%\start.bat
echo set PORT=%%PORT%% >> %OUTPUT_DIR%\start.bat
echo %APP_NAME%_windows_amd64.exe >> %OUTPUT_DIR%\start.bat

echo.
echo 编译完成！
echo 输出目录: %OUTPUT_DIR%
echo.
echo 使用方法:
echo   Windows: 运行 start.bat 或直接运行 .exe 文件
echo   Linux:   运行 ./start.sh 或直接运行可执行文件
echo   macOS:   运行 ./start.sh 或直接运行可执行文件

pause
