-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.cmd
More file actions
214 lines (191 loc) · 6.05 KB
/
Copy pathbuild.cmd
File metadata and controls
214 lines (191 loc) · 6.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
@echo off
setlocal
set "APP_NAME=pobatch"
:: Determine build architecture: 64-bit by default, 32-bit if first argument is "32"
SET "ARCH=64"
SET "SKIP_DEPS=0"
SET "SKIP_BUILD=0"
SET "SKIP_SIGN=0"
SET "SKIP_BINARIES=0"
:parse_args
if "%~1"=="" goto :done_parsing
if /I "%~1"=="32" SET "ARCH=32"
if /I "%~1"=="--no-deps" SET "SKIP_DEPS=1"
if /I "%~1"=="--no-build" SET "SKIP_BUILD=1"
if /I "%~1"=="--no-sign" SET "SKIP_SIGN=1"
if /I "%~1"=="--no-binary" SET "SKIP_BINARIES=1"
shift
goto :parse_args
:done_parsing
:: Label for console output
IF "%ARCH%"=="32" (SET "ARCH_LABEL=x86") ELSE (SET "ARCH_LABEL=x64")
:: Detect if running in CI (non-interactive) environment
:: Skip kill in CI environments
if defined CI goto :start.build
TASKLIST | FINDSTR /I "%APP_NAME%.exe" >NUL
IF ERRORLEVEL 1 GOTO :start.build
:: Kill App if running (local only)
ECHO Closing process '%APP_NAME%.exe'
taskkill /F /IM %APP_NAME%.exe >NUL
:start.build
::Build Lazarus project "%APP_NAME%" using lazbuild
SET "PROJECT_PATH=%APP_NAME%.lpi"
SET "BUILD_MODE=Release"
SET "LAZARUS_DIR=%LAZARUS_DIR%"
for %%D in ("%LAZARUS_DIR%" "C:\Lazarus" "C:\lazarus") do (
if exist "%%~D\lazbuild.exe" (
SET "LAZARUS_DIR=%%~D"
)
)
if not exist "%LAZARUS_DIR%\lazbuild.exe" (
echo Lazarus not found. Set LAZARUS_DIR or install Lazarus.
if not defined CI pause
exit /b 1
)
SET "LAZBUILD=%LAZARUS_DIR%\lazbuild.exe"
:: Prepare common lazbuild options (used for packages and project)
set "LAZBUILD_OPTS=--build-mode=%BUILD_MODE%"
IF "%ARCH%"=="32" SET "FPC32=%FPC32_PATH%"
IF "%ARCH%"=="32" if not exist "%FPC32%" (
for /d %%F in ("%LAZARUS_DIR%\fpc\*") do (
if exist "%%~F\bin\i386-win32\fpc.exe" (
SET "FPC32=%%~F\bin\i386-win32\fpc.exe"
)
)
)
IF "%ARCH%"=="32" if not exist "%FPC32%" (
echo 32-bit FPC compiler not found. Set FPC32_PATH.
if not defined CI pause
exit /b 1
)
IF "%ARCH%"=="32" set "LAZBUILD_OPTS=%LAZBUILD_OPTS% --cpu=i386 --ws=win32 --compiler=%FPC32%"
:: Updating and building dependencies
if %SKIP_DEPS%==1 goto :skip_deps
IF "%ARCH%"=="32" (
call "%~dp0dependencies.cmd" 32 nopull
) ELSE (
call "%~dp0dependencies.cmd" 64 nopull
)
if %ERRORLEVEL% neq 0 (
echo Dependency build failed!
if not defined CI pause
exit /b %ERRORLEVEL%
)
:skip_deps
if %SKIP_BUILD%==1 goto :skip_build
echo.
echo ############################################################
echo Build %ARCH_LABEL%
echo ############################################################
echo.
:: 32-bit build needs to protect the existing 64-bit executable
IF "%ARCH%"=="32" (
if exist "%APP_NAME%.exe" (
echo Renaming existing 64-bit executable...
ren "%APP_NAME%.exe" "%APP_NAME%64.exe"
)
)
echo Building project: %PROJECT_PATH%
"%LAZBUILD%" %PROJECT_PATH% %LAZBUILD_OPTS% -q
IF %ERRORLEVEL% NEQ 0 (
IF "%ARCH%"=="32" (
echo 32-bit build failed!
::Restore 64-bit exe back
if exist "%APP_NAME%64.exe" ren "%APP_NAME%64.exe" "%APP_NAME%.exe"
) ELSE (
echo Build failed!
)
if not defined CI pause
exit /b %ERRORLEVEL%
)
:: 32-bit post-build renaming
IF "%ARCH%"=="32" (
if exist "%APP_NAME%.exe" (
echo Renaming 32-bit executable...
if exist "%APP_NAME%32.exe" del /F /Q "%APP_NAME%32.exe"
ren "%APP_NAME%.exe" "%APP_NAME%32.exe"
)
::Restore 64-bit exe back to original name
if exist "%APP_NAME%64.exe" (
echo Restoring 64-bit executable name...
if exist "%APP_NAME%.exe" del /F /Q "%APP_NAME%.exe"
ren "%APP_NAME%64.exe" "%APP_NAME%.exe"
)
)
echo Build completed successfully
:skip_build
if %SKIP_SIGN%==1 goto :skip_sign
echo.
echo ############################################################
echo Signing %ARCH_LABEL% executable
echo ############################################################
echo.
echo Wait 2 seconds to ensure file is free
ping 127.0.0.1 -n 3 >nul
:: Set architecture-specific EXE name
IF "%ARCH%"=="32" (
SET "EXE_NAME=%APP_NAME%32.exe"
) ELSE (
SET "EXE_NAME=%APP_NAME%.exe"
)
:: Certificate settings (same as before)
IF "%SIGNTOOL%"=="" (
SET "SIGNTOOL=C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64\signtool.exe"
)
IF "%CERTFILE%"=="" (
IF EXIST "%~dp0installer\AlexanderT.pfx" (
SET "CERTFILE=%~dp0installer\AlexanderT.pfx"
) ELSE (
IF NOT "%CERT_PFX%"=="" (
SET "CERTFILE=%TEMP%\%APP_NAME%-cert.pfx"
powershell -NoProfile -Command "[IO.File]::WriteAllBytes('%TEMP%\\%APP_NAME%-cert.pfx',[Convert]::FromBase64String($env:CERT_PFX))"
) ELSE (
SET "CERTFILE="
)
)
)
SET "CERTPASS=1234"
::SET "TIMESTAMP_URL=http://timestamp.digicert.com"
SET "TIMESTAMP_URL=http://timestamp.sectigo.com"
::SET "TIMESTAMP_URL=http://ts.ssl.com"
::Sign the executable
if exist "%EXE_NAME%" (
if not "%CERTFILE%"=="" (
if exist "%CERTFILE%" (
if exist "%SIGNTOOL%" (
echo Signing %EXE_NAME%...
"%SIGNTOOL%" sign /f "%CERTFILE%" /p "%CERTPASS%" /fd SHA256 /tr %TIMESTAMP_URL% /td SHA256 "%EXE_NAME%" < nul
IF %ERRORLEVEL% EQU 0 (
echo Executable signing completed successfully
) else (
echo Executable signing failed
if not defined CI pause
exit /b %ERRORLEVEL%
)
) else (
echo Skipping signing: signtool not found.
)
) else (
echo Skipping signing: cert file not found.
)
) else (
echo Skipping signing: CERTFILE not set.
)
) else (
echo Skipping signing: executable %EXE_NAME% missing.
if not defined CI pause
exit /b 1
)
:skip_sign
:: Copy and sign binaries using external script
if %SKIP_BINARIES%==1 goto :skip_binaries
echo.
echo Processing binaries...
call "%~dp0depsbinary.cmd" %ARCH% %APP_NAME%
if %ERRORLEVEL% neq 0 (
echo Binaries processing failed!
if not defined CI pause
exit /b %ERRORLEVEL%
)
:skip_binaries
echo All done.