| 1 |
{ |
| 2 |
Copyright 2022-2022 Michalis Kamburelis. |
| 3 |
|
| 4 |
This file is part of "Castle Game Engine". |
| 5 |
|
| 6 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 7 |
included in this distribution, for details about the copyright. |
| 8 |
|
| 9 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 |
|
| 13 |
---------------------------------------------------------------------------- |
| 14 |
} |
| 15 |
|
| 16 |
{ Proxy program to call the real FPC with proper command-line options. |
| 17 |
Passes own command-line options to FPC, |
| 18 |
adds options to set standard units path. |
| 19 |
|
| 20 |
This assumes the simple layout of FPC bundled with Castle Game Engine. |
| 21 |
It assumes that fpc-cge executable is exactly alongside the fpc executable, |
| 22 |
in bin/ subdurectory, and ../units/$fpctarget/* are the standard RTL units. |
| 23 |
|
| 24 |
It is used for now only when this FPC needs to be executed by CodeTools |
| 25 |
(used in turn by the LSP server, see https://castle-engine.io/vscode ). |
| 26 |
In other cases, CGE editor executes real FPC and calculates and passes |
| 27 |
the appropriate parameters from the outside -- which is a bit more reliable, |
| 28 |
as it doesn't rely on ExeName (and ExeName is only guaranteed on Windows |
| 29 |
and Linux). |
| 30 |
In case of FPC for LSP it may acceptable, we always pass full FPC path, |
| 31 |
so even fallback ExeName implementation ("ParamStr(0)") should work OK |
| 32 |
in this case. |
| 33 |
} |
| 34 |
|
| 35 |
uses SysUtils, CastleUtils, CastleFilesUtils; |
| 36 |
|
| 37 |
var |
| 38 |
FpcExe, UnitsPath: String; |
| 39 |
I: Integer; |
| 40 |
Parameters: array of String; |
| 41 |
begin |
| 42 |
FpcExe := ExtractFilePath(ExeName) + 'fpc' + ExeExtension; |
| 43 |
UnitsPath := ExtractFileDir(ExtractFileDir(ExeName)) + PathDelim + |
| 44 |
'units' + PathDelim + '$fpctarget' + PathDelim + '*'; |
| 45 |
|
| 46 |
SetLength(Parameters, ParamCount + 3); |
| 47 |
|
| 48 |
{ Add parameters to bundled FPC just like tools/build-tool/code/toolcompile.pas |
| 49 |
does, passing standard units on the command-line. } |
| 50 |
Parameters[0] := '-Fu' + UnitsPath; |
| 51 |
Parameters[1] := '-n'; |
| 52 |
Parameters[2] := '-viwn'; |
| 53 |
|
| 54 |
{ Copy all parameters from our command-line. } |
| 55 |
for I := 1 to ParamCount do |
| 56 |
Parameters[I + 2] := ParamStr(I); |
| 57 |
|
| 58 |
{ debug } |
| 59 |
// for I := 0 to Length(Parameters) - 1 do |
| 60 |
// Writeln('Parameters[', I, '] = ', Parameters[I]); |
| 61 |
|
| 62 |
{ Execute FpcExe, passing stdin/out/err as our. |
| 63 |
Exit with the same exit code. } |
| 64 |
ExitCode := ExecuteProcess(FpcExe, Parameters); |
| 65 |
end. |