Repository navigation
Expand file tree
/
Copy pathbuild.cmd
More file actions
83 lines (77 loc) · 2.56 KB
/
Copy pathbuild.cmd
File metadata and controls
83 lines (77 loc) · 2.56 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
@echo off
rem Build one of the engine's own programs with FPC (Windows).
rem INTERNAL TOOL of the engine repository: demos, tests and tools for development
rem and CI. It is not a build system for projects on the engine - such a project
rem writes its own build script around build.cfg (see build.cfg).
rem Usage: build.cmd <Name|path> [extra fpc options...]
rem <Name> - a demo folder name, e.g. SimpleDemo (-> demo\SimpleDemo)
rem <path> - a program folder or .dpr in the repository, e.g. tools\upgrade5.dpr
rem The program is <folder>\<folder>.dpr, or the only .dpr in the folder.
rem Options come from build.cfg (engine-wide) and <folder>\build.cfg (if present).
rem The executable goes to bin64\ (or bin\ for a 32-bit FPC), next to the DLLs;
rem units go to <folder>\_fpc. Linux/macOS counterpart: build.sh.
setlocal EnableDelayedExpansion
if "%~1"=="" (
echo Usage: %~nx0 ^<Name^|path^> [extra fpc options...]
exit /b 1
)
set "ROOT=%~dp0"
set "ROOT=%ROOT:~0,-1%"
set "TARGET=%~1"
rem collect extra options (everything after the first argument)
set "EXTRA="
shift
:nextarg
if "%~1"=="" goto argsdone
set "EXTRA=!EXTRA! %1"
shift
goto nextarg
:argsdone
set "DPR="
set "DIR="
for %%F in ("%TARGET%") do if /I "%%~xF"==".dpr" if exist "%%~fF" set "DPR=%%~fF"
if not defined DPR (
if exist "%TARGET%\*" (
for %%D in ("%TARGET%") do set "DIR=%%~fD"
) else if exist "%ROOT%\demo\%TARGET%\*" (
set "DIR=%ROOT%\demo\%TARGET%"
) else (
echo ERROR: project not found: %TARGET%
exit /b 2
)
)
if not defined DPR (
for %%D in ("!DIR!") do set "DPR=!DIR!\%%~nxD.dpr"
if not exist "!DPR!" (
set "DPR="
set "COUNT=0"
rem the extension check skips .dproj, which *.dpr also matches via 8.3 names
for %%F in ("!DIR!\*.dpr") do if /I "%%~xF"==".dpr" (
set "DPR=%%~fF"
set /a COUNT+=1
)
if not "!COUNT!"=="1" (
echo ERROR: expected a .dpr named after the folder or a single .dpr in !DIR!
exit /b 2
)
)
)
for %%F in ("%DPR%") do set "DIR=%%~dpF"
set "DIR=%DIR:~0,-1%"
rem 64-bit FPC -> bin64, 32-bit -> bin (the DLLs for each are there)
set "BIN=bin64"
for /f %%C in ('fpc -iTP') do if /I "%%C"=="i386" set "BIN=bin"
set "OPTS=@"%ROOT%\build.cfg""
if exist "%DIR%\build.cfg" set "OPTS=%OPTS% @"%DIR%\build.cfg""
if not exist "%DIR%\_fpc" mkdir "%DIR%\_fpc"
rem build.cfg paths are relative to the repository root
pushd "%ROOT%"
echo Building %DPR%
fpc %OPTS% -Fu"%DIR%" -FU"%DIR%\_fpc" -FE"%ROOT%\%BIN%" %EXTRA% "%DPR%"
set "ERR=%ERRORLEVEL%"
popd
if not "%ERR%"=="0" (
echo Build FAILED with error %ERR%.
exit /b %ERR%
)
exit /b 0