140 lines
5.1 KiB
Batchfile
140 lines
5.1 KiB
Batchfile
@echo off
|
|
setlocal EnableExtensions EnableDelayedExpansion
|
|
cd /d "%~dp0"
|
|
title NightShot Win64 build
|
|
|
|
set "EXITCODE=0"
|
|
set "PAUSE_ON_EXIT=1"
|
|
if /I "%~1"=="--no-pause" set "PAUSE_ON_EXIT=0"
|
|
set "CXX_PATH="
|
|
set "WINDRES_PATH="
|
|
set "RES_OBJECT="
|
|
|
|
rem Prefer an explicitly named MinGW-w64 compiler, then a 64-bit g++ from PATH.
|
|
for /f "delims=" %%P in ('where x86_64-w64-mingw32-g++.exe 2^>nul') do if not defined CXX_PATH set "CXX_PATH=%%P"
|
|
if not defined CXX_PATH for /f "delims=" %%P in ('where g++.exe 2^>nul') do if not defined CXX_PATH set "CXX_PATH=%%P"
|
|
|
|
if not defined CXX_PATH (
|
|
echo [ERROR] A Win64 MinGW-w64 g++ compiler was not found.
|
|
echo Install MSYS2 UCRT64/MinGW64 or add its bin directory to PATH.
|
|
set "EXITCODE=1"
|
|
goto :finish
|
|
)
|
|
|
|
for /f "delims=" %%T in ('""!CXX_PATH!" -dumpmachine 2^>nul"') do set "TARGET=%%T"
|
|
echo !TARGET! | findstr /I /C:"x86_64-w64-mingw32" >nul
|
|
if errorlevel 1 (
|
|
echo [ERROR] The detected compiler is not a Win64 MinGW-w64 compiler.
|
|
echo Compiler: !CXX_PATH!
|
|
echo Target: !TARGET!
|
|
set "EXITCODE=1"
|
|
goto :finish
|
|
)
|
|
|
|
rem windres is often next to g++.exe but is not always added to PATH.
|
|
for %%P in ("!CXX_PATH!") do set "TOOLBIN=%%~dpP"
|
|
for %%R in ("!TOOLBIN!x86_64-w64-mingw32-windres.exe" "!TOOLBIN!!TARGET!-windres.exe" "!TOOLBIN!windres.exe") do (
|
|
if not defined WINDRES_PATH if exist "%%~fR" set "WINDRES_PATH=%%~fR"
|
|
)
|
|
if not defined WINDRES_PATH for /f "delims=" %%P in ('where x86_64-w64-mingw32-windres.exe 2^>nul') do if not defined WINDRES_PATH set "WINDRES_PATH=%%P"
|
|
if not defined WINDRES_PATH for /f "delims=" %%P in ('where windres.exe 2^>nul') do if not defined WINDRES_PATH set "WINDRES_PATH=%%P"
|
|
|
|
if not exist build mkdir build
|
|
if not exist dist mkdir dist
|
|
|
|
set "COMMON=-std=c++20 -O2 -fms-extensions -Wall -Wextra -Wpedantic -DUNICODE -D_UNICODE -D_WIN32_WINNT=0x0A00 -D_WIN32_IE=0x0600 -finput-charset=UTF-8 -Iinclude -ffunction-sections -fdata-sections"
|
|
|
|
echo Compiler: !CXX_PATH!
|
|
echo Target: !TARGET!
|
|
echo.
|
|
|
|
echo [1/13] Compiling capture.cpp
|
|
"!CXX_PATH!" !COMMON! -c src\capture.cpp -o build\capture.o
|
|
if errorlevel 1 goto :build_failed
|
|
|
|
echo [2/13] Compiling image_io.cpp
|
|
"!CXX_PATH!" !COMMON! -c src\image_io.cpp -o build\image_io.o
|
|
if errorlevel 1 goto :build_failed
|
|
|
|
echo [3/13] Compiling gif_recorder.cpp
|
|
"!CXX_PATH!" !COMMON! -c src\gif_recorder.cpp -o build\gif_recorder.o
|
|
if errorlevel 1 goto :build_failed
|
|
|
|
echo [4/13] Compiling gif_options_window.cpp
|
|
"!CXX_PATH!" !COMMON! -c src\gif_options_window.cpp -o build\gif_options_window.o
|
|
if errorlevel 1 goto :build_failed
|
|
|
|
echo [5/13] Compiling overlay.cpp
|
|
"!CXX_PATH!" !COMMON! -c src\overlay.cpp -o build\overlay.o
|
|
if errorlevel 1 goto :build_failed
|
|
|
|
echo [6/13] Compiling notifications.cpp
|
|
"!CXX_PATH!" !COMMON! -c src\notifications.cpp -o build\notifications.o
|
|
if errorlevel 1 goto :build_failed
|
|
|
|
echo [7/13] Compiling settings.cpp
|
|
"!CXX_PATH!" !COMMON! -c src\settings.cpp -o build\settings.o
|
|
if errorlevel 1 goto :build_failed
|
|
|
|
echo [8/13] Compiling startup.cpp
|
|
"!CXX_PATH!" !COMMON! -c src\startup.cpp -o build\startup.o
|
|
if errorlevel 1 goto :build_failed
|
|
|
|
echo [9/13] Compiling settings_window.cpp
|
|
"!CXX_PATH!" !COMMON! -c src\settings_window.cpp -o build\settings_window.o
|
|
if errorlevel 1 goto :build_failed
|
|
|
|
echo [10/13] Compiling uploader.cpp
|
|
"!CXX_PATH!" !COMMON! -c src\uploader.cpp -o build\uploader.o
|
|
if errorlevel 1 goto :build_failed
|
|
|
|
echo [11/13] Compiling main.cpp
|
|
"!CXX_PATH!" !COMMON! -c src\main.cpp -o build\main.o
|
|
if errorlevel 1 goto :build_failed
|
|
|
|
if defined WINDRES_PATH (
|
|
echo [12/13] Compiling resources
|
|
"!WINDRES_PATH!" -Iinclude -Ires res\app.rc -O coff -o build\app_res.o
|
|
if errorlevel 1 goto :build_failed
|
|
set "RES_OBJECT=build\app_res.o"
|
|
) else (
|
|
echo [12/13] Resources skipped
|
|
echo [WARN] Win64 windres was not found. The EXE will still build, but without the embedded icon/version/manifest.
|
|
echo [WARN] Install the full MSYS2 mingw-w64-x86_64-binutils package to restore resources.
|
|
)
|
|
|
|
echo [13/13] Linking Win64 executable
|
|
"!CXX_PATH!" -municode -mwindows -static -static-libgcc -static-libstdc++ ^
|
|
-Wl,--gc-sections -Wl,--nxcompat -Wl,--dynamicbase -Wl,--high-entropy-va ^
|
|
build\capture.o build\image_io.o build\gif_recorder.o build\gif_options_window.o ^
|
|
build\overlay.o build\notifications.o ^
|
|
build\settings.o build\startup.o build\settings_window.o build\uploader.o ^
|
|
build\main.o !RES_OBJECT! ^
|
|
-lgdiplus -lgdi32 -luser32 -lshell32 -lshcore -lole32 -lruntimeobject ^
|
|
-lcomdlg32 -luuid -lwinhttp -ladvapi32 -lwindowscodecs ^
|
|
-o dist\NightShot.exe
|
|
if errorlevel 1 goto :build_failed
|
|
|
|
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
|
|
"$b=[IO.File]::ReadAllBytes('dist\NightShot.exe');$pe=[BitConverter]::ToInt32($b,0x3c);$magic=[BitConverter]::ToUInt16($b,$pe+24);if($magic-ne 0x20b){Write-Error 'Output is not PE32+ Win64';exit 1}"
|
|
if errorlevel 1 goto :build_failed
|
|
|
|
echo.
|
|
echo [OK] Built: dist\NightShot.exe [Win64 / PE32+]
|
|
set "EXITCODE=0"
|
|
goto :finish
|
|
|
|
:build_failed
|
|
set "EXITCODE=!ERRORLEVEL!"
|
|
if "!EXITCODE!"=="0" set "EXITCODE=1"
|
|
echo.
|
|
echo [ERROR] Build failed with exit code !EXITCODE!.
|
|
|
|
:finish
|
|
echo.
|
|
if "!PAUSE_ON_EXIT!"=="1" (
|
|
echo Press any key to close this window...
|
|
pause >nul
|
|
)
|
|
exit /b !EXITCODE!
|