forked from ldraw-linux/ldglite
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.cmd
489 lines (441 loc) · 13.2 KB
/
build.cmd
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
@ECHO OFF &SETLOCAL
Title LDGLite Windows auto build script
rem This script uses Qt to configure and build LDGLite for Windows.
rem The primary purpose is to automatically build both the 32bit and 64bit
rem LDGLite distributions and package the build contents (exe, doc and
rem resources ) as LPub3D 3rd Party components.
rem --
rem Trevor SANDY <[email protected]>
rem Last Update: December 02, 2017
rem Copyright (c) 2017 by Trevor SANDY
rem --
rem This script is distributed in the hope that it will be useful,
rem but WITHOUT ANY WARRANTY; without even the implied warranty of
rem MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
SET PWD=%CD%
rem Variables - change these as required by your build environments
IF "%APPVEYOR%" EQU "True" (
IF [%LP3D_DIST_DIR_PATH%] == [] (
ECHO.
ECHO -ERROR: Distribution directory path not defined.
ECHO -%~nx0 terminated!
GOTO :END
)
SET DIST_DIR=..\..\%LP3D_DIST_DIR%
SET LDRAW_DOWNLOAD_DIR=%APPVEYOR_BUILD_FOLDER%
SET LDRAW_DIR=%APPVEYOR_BUILD_FOLDER%\LDraw
) ELSE (
SET DIST_DIR=..\..\lpub3d_windows_3rdparty
SET LDRAW_DOWNLOAD_DIR=%USERPROFILE%
SET LDRAW_DIR=%USERPROFILE%\LDraw
SET LP3D_QT32_MSYS2=C:\Msys2\Msys64\mingw32\bin
SET LP3D_QT64_MSYS2=C:\Msys2\Msys64\mingw64\bin
)
SET SYS_DIR=%SystemRoot%\System32
SET zipWin64=C:\program files\7-zip
SET OfficialCONTENT=complete.zip
SET PACKAGE=LDGLite
SET VERSION=1.3.4
SET CONFIGURATION=release
SET THIRD_INSTALL=unknown
SET INSTALL_32BIT=unknown
SET INSTALL_64BIT=unknown
SET PLATFORM=unknown
SET LDCONFIG_FILE=unknown
SET CHECK=unknown
ECHO.
ECHO -Start %PACKAGE% %~nx0 with commandline args: [%*].
rem Verify 1st input flag options
IF NOT [%1]==[] (
IF NOT "%1"=="x86" (
IF NOT "%1"=="x86_64" (
IF NOT "%1"=="-all" (
IF NOT "%1"=="-help" GOTO :PLATFORM_ERROR
)
)
)
)
rem Parse platform input flags
IF [%1]==[] (
SET PLATFORM=-all
GOTO :SET_CONFIGURATION
)
IF /I "%1"=="x86" (
SET PLATFORM=x86
GOTO :SET_CONFIGURATION
)
IF /I "%1"=="x86_64" (
SET PLATFORM=x86_64
GOTO :SET_CONFIGURATION
)
IF /I "%1"=="-all" (
SET PLATFORM=-all
GOTO :SET_CONFIGURATION
)
IF /I "%1"=="-help" (
GOTO :USAGE
)
rem If we get here display invalid command message.
GOTO :COMMAND_ERROR
:SET_CONFIGURATION
rem Verify 2nd input flag options
IF NOT [%2]==[] (
IF NOT "%2"=="-ins" (
IF NOT "%2"=="-chk" GOTO :CONFIGURATION_ERROR
)
)
rem Verify 3rd input flag options
IF NOT [%3]==[] (
IF NOT "%3"=="-chk" GOTO :CONFIGURATION_ERROR
)
rem Set third party install as default behaviour
IF [%2]==[] (
SET THIRD_INSTALL=1
GOTO :BUILD
)
IF /I "%2"=="-ins" (
SET THIRD_INSTALL=1
GOTO :BUILD
)
rem Set build check flag
IF /I "%2"=="-chk" (
SET CHECK=1
GOTO :BUILD
)
:BUILD
rem Display build settings
ECHO.
IF "%APPVEYOR%" EQU "True" (
ECHO BUILD_HOST.............[APPVEYOR CONTINUOUS INTEGRATION SERVICE]
ECHO BUILD_ID...............[%APPVEYOR_BUILD_ID%]
ECHO BUILD_BRANCH...........[%APPVEYOR_REPO_BRANCH%]
ECHO PROJECT_NAME...........[%APPVEYOR_PROJECT_NAME%]
ECHO REPOSITORY_NAME........[%APPVEYOR_REPO_NAME%]
ECHO REPO_PROVIDER..........[%APPVEYOR_REPO_PROVIDER%]
)
ECHO PACKAGE................[%PACKAGE%]
ECHO VERSION................[%VERSION%]
ECHO LP3D_QT32_MSYS2........[%LP3D_QT32_MSYS2%]
ECHO LP3D_QT64_MSYS2........[%LP3D_QT64_MSYS2%]
ECHO WORKING_DIRECTORY......[%PWD%]
ECHO DIST_DIRECTORY.........[%DIST_DIR:/=\%]
ECHO LDRAW_DIRECTORY........[%LDRAW_DIR%]
ECHO. LDRAW_DOWNLOAD_DIR.....[%LDRAW_DOWNLOAD_DIR%]
rem Perform build check
IF /I "%3"=="-chk" (
SET CHECK=1
)
rem Check if build all platforms
IF /I "%PLATFORM%"=="-all" (
GOTO :BUILD_ALL
)
rem Configure buid arguments and set environment variables
CALL :CONFIGURE_BUILD_ENV
ECHO.
ECHO -Building %PLATFORM% platform, %CONFIGURATION% configuration...
rem Display QMake version
ECHO.
qmake -v & ECHO.
rem Configure makefiles
qmake %LDGLITE_CONFIG_ARGS%
rem perform build
mingw32-make
rem Perform build check if specified
IF %CHECK%==1 CALL :CHECK_BUILD %PLATFORM%
rem Package 3rd party install content
IF %THIRD_INSTALL%==1 CALL :3RD_PARTY_INSTALL
GOTO :END
:BUILD_ALL
rem Launch qmake/make across all platform builds
ECHO.
ECHO -Build x86 and x86_64 platforms...
FOR %%P IN ( x86, x86_64 ) DO (
SET PLATFORM=%%P
rem Configure buid arguments and set environment variables
CALL :CONFIGURE_BUILD_ENV
ECHO.
ECHO -Building %%P platform, %CONFIGURATION% configuration...
rem Display QMake version
ECHO.
qmake -v & ECHO.
rem Configure makefiles and launch make
SETLOCAL ENABLEDELAYEDEXPANSION
qmake !LDGLITE_CONFIG_ARGS! & mingw32-make !LDGLITE_MAKE_ARGS!
ENDLOCAL
rem Perform build check if specified
IF %CHECK%==1 CALL :CHECK_BUILD %%P
rem Package 3rd party install content
IF %THIRD_INSTALL%==1 CALL :3RD_PARTY_INSTALL
rem Reset PATH_PREPENDED
SET PATH_PREPENDED=False
)
GOTO :END
:CONFIGURE_BUILD_ENV
CD /D %PWD%
ECHO.
ECHO -Configure LDGLite build environment...
ECHO.
ECHO -Cleanup previous LDGLite qmake config files - if any...
FOR /R %%I IN (
".qmake.stash"
"Makefile*"
"ldrawini\Makefile*"
"mui\Makefile*"
"app\Makefile*"
) DO DEL /S /Q "%%~I" >nul 2>&1
ECHO.
ECHO PLATFORM (BUILD_ARCH)...[%PLATFORM%]
SET LDGLITE_CONFIG_ARGS=CONFIG+=3RD_PARTY_INSTALL=%DIST_DIR% CONFIG+=%CONFIGURATION% CONFIG-=debug_and_release
ECHO LDGLITE_CONFIG_ARGS.....[%LDGLITE_CONFIG_ARGS%]
SET LDGLITE_MAKE_ARGS=-f Makefile
IF "%PATH_PREPENDED%" NEQ "True" (
IF %PLATFORM% EQU x86 (
SET PATH=%LP3D_QT32_MSYS2%;%SYS_DIR%
) ELSE (
SET PATH=%LP3D_QT64_MSYS2%;%SYS_DIR%
)
SET PATH_PREPENDED=True
SETLOCAL ENABLEDELAYEDEXPANSION
ECHO( PATH_PREPEND............[!PATH!]
ENDLOCAL
)
) ELSE (
ECHO PATH_ALREADY_PREPENDED..[%PATH%]
)
EXIT /b
:CHECK_BUILD
ECHO.
ECHO -Perform build check...
CALL :CHECK_LDRAW_DIR
IF %1==x86 SET PL=32
IF %1==x86_64 SET PL=64
SET "LPUB3D_DATA=%LOCALAPPDATA%\LPub3D Software\LPub3D"
SET "LDRAW_UNOFFICIAL=%LDRAW_DIR%\Unofficial"
REM SET "LDSEARCHDIRS=%LPUB3D_DATA%\fade^|%LDRAW_UNOFFICIAL%\customParts^|%LDRAW_UNOFFICIAL%\fade^|%LDRAW_UNOFFICIAL%\testParts"
SET ARGS=-l3 -i2 -ca0.01 -cg23,-45,3031328 -J -v1240,1753 -o0,-292 -W2 -q -fh -2g,2x -w1 -l
SET LDCONFIG_FILE=tests\LDConfigCustom01.ldr
SET IN_FILE=tests\Foo2.ldr
SET OUT_FILE=tests\%PL%bit_%CONFIGURATION%-TestOK_1.3.4_Foo2.png
SET PACKAGE_PATH=app\%PL%bit_%CONFIGURATION%\%PACKAGE%.exe
SET COMMAND_LINE_ARGS=%ARGS% -ldcF%LDCONFIG_FILE% -mF%OUT_FILE% %IN_FILE%
SET COMMAND=%PACKAGE_PATH% %COMMAND_LINE_ARGS%
IF %CHECK%==1 (
ECHO.
ECHO PACKAGE................[%PACKAGE%]
ECHO PACKAGE_PATH...........[%PACKAGE_PATH%]
ECHO ARGUMENTS..............[%ARGS%]
ECHO LDCONFIG_FILE..........[%LDCONFIG_FILE%]
ECHO OUT_FILE...............[%OUT_FILE%]
ECHO IN_FILE................[%IN_FILE%]
ECHO LDRAWDIR.^(ENV VAR^).....[%LDRAWDIR%]
ECHO LDRAW_DIRECTORY........[%LDRAW_DIR%]
REM ECHO LDRAW_SEARCH_DIRS......[%LDSEARCHDIRS%]
ECHO COMMAND................[%COMMAND%]
%COMMAND%> Check.out
IF EXIST "Check.out" (
FOR %%R IN (Check.out) DO IF NOT %%~zR LSS 1 ECHO. & TYPE "Check.out"
DEL /Q "Check.out"
)
) ELSE (
ECHO -Check is not possible
)
EXIT /b
:3RD_PARTY_INSTALL
ECHO.
ECHO -Installing 3rd party distribution files to [%DIST_DIR%]...
ECHO.
rem Configure makefiles and perform build
mingw32-make %LDGLITE_MAKE_ARGS% install
EXIT /b
:CHECK_LDRAW_DIR
ECHO.
ECHO -%PACKAGE% - Check for LDraw library...
IF NOT EXIST "%LDRAW_DIR%\parts" (
REM SET CHECK=0
IF NOT EXIST "%LDRAW_DOWNLOAD_DIR%\%OfficialCONTENT%" (
ECHO.
ECHO -LDraw directory %LDRAW_DIR% does not exist - Downloading...
CALL :DOWNLOAD_LDRAW_LIBS
)
IF EXIST "%LDRAW_DOWNLOAD_DIR%\%OfficialCONTENT%" (
IF EXIST "%zipWin64%" (
ECHO.
ECHO -7zip exectutable found at "%zipWin64%"
ECHO.
ECHO -Extracting %OfficialCONTENT%...
ECHO.
"%zipWin64%\7z.exe" x -o"%LDRAW_DOWNLOAD_DIR%\" "%LDRAW_DOWNLOAD_DIR%\%OfficialCONTENT%" | findstr /i /r /c:"^Extracting\>" /c:"^Everything\>"
IF EXIST "%LDRAW_DIR%\parts" (
ECHO.
ECHO -LDraw directory %LDRAW_DIR% extracted.
ECHO.
ECHO -Cleanup %OfficialCONTENT%...
DEL /Q "%LDRAW_DOWNLOAD_DIR%\%OfficialCONTENT%"
ECHO.
ECHO -Set LDRAWDIR to %LDRAW_DIR%.
SET LDRAWDIR=%LDRAW_DIR%
)
) ELSE (
ECHO [WARNING] Could not find 7zip executable.
SET CHECK=0
)
) ELSE (
ECHO.
ECHO -[WARNING] Could not find %LDRAW_DOWNLOAD_DIR%\%OfficialCONTENT%.
SET CHECK=0
)
) ELSE (
ECHO.
ECHO -LDraw directory exist at [%LDRAW_DIR%].
ECHO.
ECHO -Set LDRAWDIR to %LDRAW_DIR%.
SET LDRAWDIR=%LDRAW_DIR%
)
EXIT /b
:DOWNLOAD_LDRAW_LIBS
ECHO.
ECHO - Download LDraw archive libraries...
SET OutputPATH=%LDRAW_DOWNLOAD_DIR%
ECHO.
ECHO - Prepare BATCH to VBS to Web Content Downloader...
IF NOT EXIST "%TEMP%\$" (
MD "%TEMP%\$"
)
SET vbs=WebContentDownload.vbs
SET t=%TEMP%\$\%vbs% ECHO
IF EXIST %TEMP%\$\%vbs% (
DEL %TEMP%\$\%vbs%
)
:WEB CONTENT SAVE-AS Download-- VBS
>%t% Option Explicit
>>%t% On Error Resume Next
>>%t%.
>>%t% Dim args, http, fileSystem, adoStream, url, target, status
>>%t%.
>>%t% Set args = Wscript.Arguments
>>%t% Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
>>%t% url = args(0)
>>%t% target = args(1)
>>%t% WScript.Echo "- Getting '" ^& target ^& "' from '" ^& url ^& "'...", vbLF
>>%t%.
>>%t% http.Open "GET", url, False
>>%t% http.Send
>>%t% status = http.Status
>>%t%.
>>%t% If status ^<^> 200 Then
>>%t% WScript.Echo "- FAILED to download: HTTP Status " ^& status, vbLF
>>%t% WScript.Quit 1
>>%t% End If
>>%t%.
>>%t% Set adoStream = CreateObject("ADODB.Stream")
>>%t% adoStream.Open
>>%t% adoStream.Type = 1
>>%t% adoStream.Write http.ResponseBody
>>%t% adoStream.Position = 0
>>%t%.
>>%t% Set fileSystem = CreateObject("Scripting.FileSystemObject")
>>%t% If fileSystem.FileExists(target) Then fileSystem.DeleteFile target
>>%t% If Err.Number ^<^> 0 Then
>>%t% WScript.Echo "- Error - CANNOT DELETE: '" ^& target ^& "', " ^& Err.Description
>>%t% WScript.Echo " The file may be in use by another process.", vbLF
>>%t% adoStream.Close
>>%t% Err.Clear
>>%t% Else
>>%t% adoStream.SaveToFile target
>>%t% adoStream.Close
>>%t% WScript.Echo "- Download successful!"
>>%t% End If
>>%t%.
>>%t% 'WebContentDownload.vbs
>>%t% 'Title: BATCH to VBS to Web Content Downloader
>>%t% 'CMD ^> cscript //Nologo %TEMP%\$\%vbs% WebNAME WebCONTENT
>>%t% 'VBS Created on %date% at %time%
>>%t%.
ECHO.
ECHO - VBS file "%vbs%" is done compiling
ECHO.
ECHO - LDraw archive library download path: %OutputPATH%
SET WebCONTENT="%OutputPATH%\%OfficialCONTENT%"
SET WebNAME=http://www.ldraw.org/library/updates/complete.zip
ECHO.
ECHO - Download archive file: %WebCONTENT%...
IF EXIST %WebCONTENT% (
DEL %WebCONTENT%
)
ECHO.
cscript //Nologo %TEMP%\$\%vbs% %WebNAME% %WebCONTENT% && @ECHO off
IF EXIST %OfficialCONTENT% (
ECHO.
ECHO - LDraw archive library %OfficialCONTENT% downloaded
)
EXIT /b
:PLATFORM_ERROR
ECHO.
CALL :USAGE
ECHO.
ECHO -01. (FLAG ERROR) Platform or usage flag is invalid. Use x86, x86_64 or -all [%~nx0 %*].
ECHO See Usage.
GOTO :END
:CONFIGURATION_ERROR
ECHO.
CALL :USAGE
ECHO.
ECHO -02. (FLAG ERROR) Configuration flag is invalid [%~nx0 %*].
ECHO See Usage.
GOTO :END
:COMMAND_ERROR
ECHO.
CALL :USAGE
ECHO.
ECHO -03. (COMMAND ERROR) Invalid command string [%~nx0 %*].
ECHO See Usage.
GOTO :END
:USAGE
ECHO ----------------------------------------------------------------
ECHO.
ECHO LDView Windows auto build script.
ECHO.
ECHO ----------------------------------------------------------------
ECHO Usage:
ECHO build [ -help]
ECHO build [ x86 ^| x86_64 ^| -all ] [ -ins ^| -chk ] [ -chk ]
ECHO.
ECHO ----------------------------------------------------------------
ECHO Build 64bit, Release and perform build check
ECHO build x86_64 -chk
ECHO.
ECHO Build 64bit, Release and perform install and build check
ECHO build x86_64 -ins -chk
ECHO.
ECHO Build 32bit, Release and perform build check
ECHO build x86 -chk
ECHO.
ECHO Build 64bit and32bit, Release and perform build check
ECHO build -all -chk
ECHO.
ECHO Build 64bit and32bit, Release, perform install and build check
ECHO build -all -ins -chk
ECHO.
ECHO Flags:
ECHO ----------------------------------------------------------------
ECHO ^| Flag ^| Pos ^| Type ^| Description
ECHO ----------------------------------------------------------------
ECHO -help......1......Useage flag [Default=Off] Display useage.
ECHO x86........1......Platform flag [Default=Off] Build 32bit architecture.
ECHO x86_64.....1......Platform flag [Default=Off] Build 64bit architecture.
ECHO -all.......1......Configuraiton flag [Default=On ] Build both 32bit and 64bit architectures
ECHO -ins.......2......Project flag [Default=Off] Install distribution as LPub3D 3rd party installation
ECHO -chk.......2,3....Project flag [Default=On ] Perform a quick image redering check using command line ini file
ECHO.
ECHO Be sure the set your LDraw directory in the variables section above if you expect to use the '-chk' option.
ECHO.
ECHO Flags are case sensitive, use lowere case.
ECHO.
ECHO If no flag is supplied, 64bit platform, Release Configuration built by default.
ECHO ----------------------------------------------------------------
EXIT /b
:END
ECHO.
ECHO -%~nx0 [%PACKAGE% v%VERSION%] finished.
ENDLOCAL
EXIT /b