nsfwapp/backend/build.bat
2026-06-23 12:36:04 +02:00

149 lines
3.6 KiB
Batchfile

@echo off
setlocal
cd /d "%~dp0"
set "LOCAL_GOCACHE=%CD%\.gocache-build"
if exist "%LOCAL_GOCACHE%" rmdir /s /q "%LOCAL_GOCACHE%" >nul 2>nul
set "GOCACHE=%LOCAL_GOCACHE%"
echo Baue Windows x64...
if exist nsfwapp.exe del /q nsfwapp.exe >nul 2>nul
set GOOS=windows
set GOARCH=amd64
set CGO_ENABLED=1
go build -ldflags="-H=windowsgui" -o nsfwapp.exe
if errorlevel 1 goto error
echo.
echo Baue Debian/Linux x64 via WSL...
if exist nsfwapp-linux-amd64 del /q nsfwapp-linux-amd64 >nul 2>nul
where wsl >nul 2>nul
if errorlevel 1 goto wsl_missing
set "WSL_CWD="
for /f "delims=" %%i in ('wsl wslpath -a "%CD%" 2^>nul') do set "WSL_CWD=%%i"
if "%WSL_CWD%"=="" goto wsl_path_error
if not "%WSL_CWD:~0,1%"=="/" goto wsl_missing
wsl bash -lc "command -v go >/dev/null 2>&1"
if errorlevel 1 goto wsl_go_missing
wsl bash -lc "command -v gcc >/dev/null 2>&1 && command -v pkg-config >/dev/null 2>&1"
if errorlevel 1 goto wsl_build_deps_missing
wsl bash -lc "cd ""%WSL_CWD%"" && mkdir -p .gocache-linux && GOOS=linux GOARCH=amd64 CGO_ENABLED=1 GOCACHE=""$PWD/.gocache-linux"" go build -o nsfwapp-linux-amd64"
if errorlevel 1 goto error
if not exist nsfwapp-linux-amd64 goto linux_output_missing
if not exist dist mkdir dist
copy /y nsfwapp.exe dist\nsfwapp.exe >nul
if errorlevel 1 goto dist_copy_error
copy /y nsfwapp-linux-amd64 dist\nsfwapp-linux-amd64 >nul
if errorlevel 1 goto dist_copy_error
echo.
echo Baue Debian Application Package via WSL...
wsl bash -lc "cd ""%WSL_CWD%"" && DEB_SKIP_REBUILD=1 bash ./build_deb.sh"
if errorlevel 1 goto deb_package_error
echo.
echo Build erfolgreich.
echo Windows: nsfwapp.exe
echo Debian: nsfwapp-linux-amd64
echo Dist: dist\nsfwapp.exe
echo Dist: dist\nsfwapp-linux-amd64
echo Debian-Paket: dist\nsfwapp_*.deb
goto end
:error
echo.
echo Build fehlgeschlagen.
call :cleanup_cache
exit /b 1
:wsl_missing
echo.
echo Debian/Linux-Build braucht eine installierte WSL-Linux-Distribution.
echo Aktuell kann WSL nicht gestartet werden.
echo.
echo Einmalig installieren, z.B.:
echo wsl --install -d Debian
echo.
echo In Debian danach die Build-Abhaengigkeiten installieren:
echo sudo apt update
echo sudo apt install -y build-essential pkg-config
echo.
call :cleanup_cache
exit /b 1
:wsl_go_missing
echo.
echo In WSL ist Go nicht installiert oder nicht im PATH.
echo.
echo In Debian installieren:
echo sudo apt update
echo sudo apt install -y golang-go
echo.
echo Falls Debian eine zu alte Go-Version installiert, installiere Go passend zu go.mod von go.dev
echo und setze PATH in ~/.profile oder ~/.bashrc, z.B.:
echo export PATH=/usr/local/go/bin:$PATH
echo.
call :cleanup_cache
exit /b 1
:wsl_build_deps_missing
echo.
echo In WSL fehlen Build-Abhaengigkeiten fuer den Linux-Build.
echo.
echo In Debian installieren:
echo sudo apt update
echo sudo apt install -y build-essential pkg-config
echo.
call :cleanup_cache
exit /b 1
:wsl_path_error
echo.
echo WSL-Pfad konnte nicht aus dem Windows-Pfad erzeugt werden:
echo %CD%
call :cleanup_cache
exit /b 1
:linux_output_missing
echo.
echo Debian/Linux-Build wurde nicht erzeugt:
echo nsfwapp-linux-amd64
echo.
echo Pruefe, ob in WSL eine Debian/Ubuntu-Distribution mit Go und den Build-Abhaengigkeiten installiert ist.
call :cleanup_cache
exit /b 1
:dist_copy_error
echo.
echo Build-Artefakte konnten nicht nach dist kopiert werden.
call :cleanup_cache
exit /b 1
:deb_package_error
echo.
echo Debian-Paket-Build fehlgeschlagen.
call :cleanup_cache
exit /b 1
:end
call :cleanup_cache
endlocal
exit /b 0
:cleanup_cache
if defined LOCAL_GOCACHE if exist "%LOCAL_GOCACHE%" rmdir /s /q "%LOCAL_GOCACHE%" >nul 2>nul
if exist "%CD%\.gocache-linux" rmdir /s /q "%CD%\.gocache-linux" >nul 2>nul
exit /b 0