| 1 |
{ |
| 2 |
Copyright 2014-2023 Michalis Kamburelis and FPC team. |
| 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 |
Parts of this file are based on FPC packages/fpmkunit/src/fpmkunit.pp unit, |
| 9 |
which conveniently uses *exactly* the same license as Castle Game Engine. |
| 10 |
|
| 11 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 14 |
|
| 15 |
---------------------------------------------------------------------------- |
| 16 |
} |
| 17 |
|
| 18 |
{ Architectures (OS and CPU) definitions. |
| 19 |
Parts of this are based on FPMkUnit code, this way we use the same names |
| 20 |
as FPMkUnit, so we're consistent with FPC and fpmake command-line options. } |
| 21 |
unit ToolArchitectures; |
| 22 |
|
| 23 |
{$I castleconf.inc} |
| 24 |
|
| 25 |
interface |
| 26 |
|
| 27 |
type |
| 28 |
{ Target of the compilation, which may include many OS/CPU combinations. } |
| 29 |
TTarget = ( |
| 30 |
{ Target a specific chosen OS/CPU. } |
| 31 |
targetCustom, |
| 32 |
{ Target all relevant iOS combinations of OS/CPU. } |
| 33 |
targetIOS, |
| 34 |
{ Target all relevant Android combinations of OS/CPU. } |
| 35 |
targetAndroid, |
| 36 |
{ Build an application for Nintendo Switch. } |
| 37 |
targetNintendoSwitch |
| 38 |
); |
| 39 |
|
| 40 |
{ Processor architectures supported by FPC. Copied from FPMkUnit. } |
| 41 |
TCpu=(cpuNone, |
| 42 |
i386,m68k,powerpc,sparc,x86_64,arm,powerpc64,avr,armeb, |
| 43 |
mips,mipsel,jvm,i8086,aarch64,sparc64 |
| 44 |
); |
| 45 |
TCPUS = Set of TCPU; |
| 46 |
|
| 47 |
{ Operating systems supported by FPC. Copied from FPMkUnit. } |
| 48 |
TOS=(osNone, |
| 49 |
linux,go32v2,win32,os2,freebsd,beos,netbsd, |
| 50 |
amiga,atari, solaris, qnx, netware, openbsd,wdosx, |
| 51 |
palmos,macosclassic,darwin,emx,watcom,morphos,netwlibc, |
| 52 |
win64,wince,gba,nds,embedded,symbian,haiku,iphonesim, |
| 53 |
aix,java,android,nativent,msdos,wii,aros,dragonfly, |
| 54 |
win16,ios |
| 55 |
); |
| 56 |
TOSes = Set of TOS; |
| 57 |
|
| 58 |
Const |
| 59 |
// Aliases |
| 60 |
Amd64 = X86_64; |
| 61 |
PPC = PowerPC; |
| 62 |
PPC64 = PowerPC64; |
| 63 |
DOS = Go32v2; |
| 64 |
MacOSX = Darwin; |
| 65 |
|
| 66 |
AllOSes = [Low(TOS)..High(TOS)]; |
| 67 |
AllCPUs = [Low(TCPU)..High(TCPU)]; |
| 68 |
AllUnixOSes = [Linux,FreeBSD,NetBSD,OpenBSD,Darwin,QNX,BeOS,Solaris,Haiku,iphonesim,aix,Android,dragonfly]; |
| 69 |
AllBSDOSes = [FreeBSD,NetBSD,OpenBSD,Darwin,iphonesim,dragonfly]; |
| 70 |
AllWindowsOSes = [Win32,Win64,WinCE]; |
| 71 |
AllAmigaLikeOSes = [Amiga,MorphOS,AROS]; |
| 72 |
AllLimit83fsOses = [go32v2,os2,emx,watcom,msdos,win16,atari]; |
| 73 |
|
| 74 |
AllSmartLinkLibraryOSes = [Linux,msdos,win16,palmos]; // OSes that use .a library files for smart-linking |
| 75 |
AllImportLibraryOSes = AllWindowsOSes + [os2,emx,netwlibc,netware,watcom,go32v2,macosclassic,nativent,msdos,win16]; |
| 76 |
|
| 77 |
{ This table is kept OS,Cpu because it is easier to maintain (PFV) } |
| 78 |
OSCPUSupported : array[TOS,TCpu] of boolean = ( |
| 79 |
{ os none i386 m68k ppc sparc x86_64 arm ppc64 avr armeb mips mipsel jvm i8086 aarch64 sparc64} |
| 80 |
{ none } ( false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false), |
| 81 |
{ linux } ( false, true, true, true, true, true, true, true, false, true , true , true , false, false, true , true ), |
| 82 |
{ go32v2 } ( false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false), |
| 83 |
{ win32 } ( false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false), |
| 84 |
{ os2 } ( false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false), |
| 85 |
{ freebsd } ( false, true, true, false, false, true, false, false, false, false, false, false, false, false, false, false), |
| 86 |
{ beos } ( false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false), |
| 87 |
{ netbsd } ( false, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false), |
| 88 |
{ amiga } ( false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false), |
| 89 |
{ atari } ( false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false), |
| 90 |
{ solaris } ( false, true, false, false, true, true, false, false, false, false, false, false, false, false, false, false), |
| 91 |
{ qnx } ( false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false), |
| 92 |
{ netware } ( false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false), |
| 93 |
{ openbsd } ( false, true, true, false, false, true, false, false, false, false, false, false, false, false, false, false), |
| 94 |
{ wdosx } ( false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false), |
| 95 |
{ palmos } ( false, false, true, false, false, false, true, false, false, false, false, false, false, false, false, false), |
| 96 |
{ macosclassic }( false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false), |
| 97 |
{ darwin } ( false, true, false, true, false, true, false, true, false, false, false, false, false, false, true , false), |
| 98 |
{ emx } ( false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false), |
| 99 |
{ watcom } ( false, true, false, false, false ,false, false, false, false, false, false, false, false, false, false, false), |
| 100 |
{ morphos } ( false, false, false, true, false ,false, false, false, false, false, false, false, false, false, false, false), |
| 101 |
{ netwlibc }( false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false), |
| 102 |
{ win64 } ( false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false), |
| 103 |
{ wince }( false, true, false, false, false, false, true, false, false, false, false, false, false, false, false, false), |
| 104 |
{ gba } ( false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false), |
| 105 |
{ nds } ( false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false), |
| 106 |
{ embedded }( false, true, true, true, true, true, true, true, true, true , false, true , false, true , false, false), |
| 107 |
{ symbian } ( false, true, false, false, false, false, true, false, false, false, false, false, false, false, false, false), |
| 108 |
{ haiku } ( false, true, false, false, false, true, false, false, false, false, false, false, false, false, false, false), |
| 109 |
{ iphonesim}( false, true, false, false, false, true, false, false, false, false, false, false, false, false, false, false), |
| 110 |
{ aix } ( false, false, false, true, false, false, false, true, false, false, false, false, false, false, false, false), |
| 111 |
{ java } ( false, false, false, false, false, false, false, false, false, false, false, false, true , false, false, false), |
| 112 |
{ android } ( false, true, false, false, false, true, true, false, false, false, false, true, true , false, true, false), |
| 113 |
{ nativent }( false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false), |
| 114 |
{ msdos } ( false, false, false, false, false, false, false, false, false, false, false, false, false, true , false, false), |
| 115 |
{ wii } ( false, false, false, true , false, false, false, false, false, false, false, false, false, false, false, false), |
| 116 |
{ aros } ( false, true, false, false, false, true, true, false, false, false, false, false, false, false, false, false), |
| 117 |
{ dragonfly}( false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false), |
| 118 |
{ win16 } ( false, false, false, false, false, false, false, false, false, false, false, false, false, true , false, false), |
| 119 |
{ ios } ( false, false, false, false, false, false, true, false, false, false, false, false, false, false, true , false) |
| 120 |
); |
| 121 |
|
| 122 |
function TargetToString(const Target: TTarget): String; |
| 123 |
function CPUToString(const CPU: TCPU): String; |
| 124 |
function OSToString(const OS: TOS): String; |
| 125 |
function TargetCompleteToString(const Target: TTarget; const OS: TOS; const CPU: TCPU): String; |
| 126 |
|
| 127 |
function StringToTarget(const S: String): TTarget; |
| 128 |
function StringToCPU(const S: String): TCPU; |
| 129 |
function StringToOS(const S: String): TOS; |
| 130 |
|
| 131 |
const |
| 132 |
DefaultCPU: TCPU = |
| 133 |
{$ifdef CPUi386} i386 {$endif} |
| 134 |
{$ifdef CPUm68k} m68k {$endif} |
| 135 |
{$ifdef CPUpowerpc32} powerpc {$endif} |
| 136 |
{$ifdef CPUsparc} sparc {$endif} |
| 137 |
{$ifdef CPUx86_64} x86_64 {$endif} |
| 138 |
{$ifdef CPUarm} arm {$endif} |
| 139 |
{$ifdef CPUaarch64} aarch64 {$endif} |
| 140 |
{$ifdef CPUpowerpc64} powerpc64 {$endif} |
| 141 |
{$ifdef CPUavr} avr {$endif} |
| 142 |
{$ifdef CPUarmeb} armeb {$endif} |
| •143 |
{$ifdef CPUmipsel} mipsel {$else} |
| 144 |
{$ifdef CPUmips} mips {$endif}{$endif} |
| 145 |
{$ifdef CPUjvm} jvm {$endif} |
| 146 |
{$ifdef CPUi8086} i8086 {$endif} |
| 147 |
{$ifdef CPUsparc64} sparc64 {$endif} |
| 148 |
; |
| 149 |
|
| 150 |
DefaultOS: TOS = |
| 151 |
{$ifdef linux} linux {$endif} |
| 152 |
{$ifdef go32v2} go32v2 {$endif} |
| 153 |
{$ifdef win32} win32 {$endif} |
| 154 |
{$ifdef os2} os2 {$endif} |
| 155 |
{$ifdef freebsd} freebsd {$endif} |
| 156 |
{$ifdef beos} beos {$endif} |
| 157 |
{$ifdef netbsd} netbsd {$endif} |
| 158 |
{$ifdef amiga} amiga {$endif} |
| 159 |
{$ifdef atari} atari {$endif} |
| 160 |
{$ifdef solaris} solaris {$endif} |
| 161 |
{$ifdef qnx} qnx {$endif} |
| 162 |
{$ifdef netware} netware {$endif} |
| 163 |
{$ifdef openbsd} openbsd {$endif} |
| 164 |
{$ifdef wdosx} wdosx {$endif} |
| 165 |
{$ifdef palmos} palmos {$endif} |
| 166 |
{$ifdef macosclassic} macosclassic {$endif} // TODO: what is symbol of this? It used to be macos? |
| 167 |
{$ifdef darwin} darwin {$endif} |
| 168 |
{$ifdef emx} emx {$endif} |
| 169 |
{$ifdef watcom} watcom {$endif} |
| 170 |
{$ifdef morphos} morphos {$endif} |
| 171 |
{$ifdef netwlibc} netwlibc {$endif} |
| 172 |
{$ifdef win64} win64 {$endif} |
| 173 |
{$ifdef wince} wince {$endif} |
| 174 |
{$ifdef gba} gba {$endif} |
| 175 |
{$ifdef nds} nds {$endif} |
| 176 |
{$ifdef embedded} embedded {$endif} |
| 177 |
{$ifdef symbian} symbian {$endif} |
| 178 |
{$ifdef haiku} haiku {$endif} |
| 179 |
{$ifdef iphonesim} iphonesim {$endif} |
| 180 |
{$ifdef aix} aix {$endif} |
| 181 |
{$ifdef java} java {$endif} |
| 182 |
{$ifdef android} android {$endif} |
| 183 |
{$ifdef nativent} nativent {$endif} |
| 184 |
{$ifdef msdos} msdos {$endif} |
| 185 |
{$ifdef wii} wii {$endif} |
| 186 |
; |
| 187 |
|
| 188 |
function TargetOptionHelp: string; |
| 189 |
function OSOptionHelp: string; |
| 190 |
function CPUOptionHelp: string; |
| 191 |
|
| 192 |
function ExeExtensionOS(const OS: TOS): string; |
| 193 |
|
| 194 |
function LibraryExtensionOS(const OS: TOS; const Static: boolean = false): string; |
| 195 |
|
| 196 |
implementation |
| 197 |
|
| 198 |
uses TypInfo, SysUtils, |
| 199 |
CastleUtils, CastleParameters; |
| 200 |
|
| 201 |
resourcestring |
| 202 |
SErrInvalidTarget = 'Invalid target name "%s"'; |
| 203 |
SErrInvalidCPU = 'Invalid CPU name "%s"'; |
| 204 |
SErrInvalidOS = 'Invalid OS name "%s"'; |
| 205 |
|
| 206 |
function CPUToString(const CPU: TCPU): String; |
| 207 |
begin |
| 208 |
Result := LowerCase(GetEnumName(TypeInfo(TCPU), Ord(CPU))); |
| 209 |
end; |
| 210 |
|
| 211 |
function OSToString(const OS: TOS): String; |
| 212 |
begin |
| 213 |
Result := LowerCase(GetEnumName(TypeInfo(TOS), Ord(OS))); |
| 214 |
end; |
| 215 |
|
| 216 |
function StringToCPU(const S : String) : TCPU; |
| 217 |
var |
| 218 |
I : Integer; |
| 219 |
begin |
| 220 |
I := GetEnumValue(TypeInfo(TCPU), S); |
| 221 |
if I = -1 then |
| 222 |
raise Exception.CreateFmt(SErrInvalidCPU, [S]); |
| 223 |
Result := TCPU(I); |
| 224 |
end; |
| 225 |
|
| 226 |
function StringToOS(const S : String) : TOS; |
| 227 |
var |
| 228 |
I : Integer; |
| 229 |
begin |
| 230 |
I := GetEnumValue(TypeInfo(TOS), S); |
| 231 |
if I = -1 then |
| 232 |
raise Exception.CreateFmt(SErrInvalidOS, [S]); |
| 233 |
Result := TOS(I); |
| 234 |
end; |
| 235 |
|
| 236 |
const |
| 237 |
TargetNames: array [TTarget] of string = ('custom', 'ios', 'android', 'nintendo-switch'); |
| 238 |
|
| 239 |
function TargetToString(const Target : TTarget): string; |
| 240 |
begin |
| 241 |
Result := TargetNames[Target]; |
| 242 |
end; |
| 243 |
|
| 244 |
function StringToTarget(const S : String): TTarget; |
| 245 |
var |
| 246 |
SLower: string; |
| 247 |
begin |
| 248 |
SLower := LowerCase(S); |
| 249 |
for Result := Low(Result) to High(Result) do |
| 250 |
if SLower = TargetNames[Result] then |
| 251 |
Exit; |
| 252 |
raise Exception.CreateFmt(SErrInvalidTarget,[S]); |
| 253 |
end; |
| 254 |
|
| 255 |
function TargetCompleteToString(const Target: TTarget; |
| 256 |
const OS: TOS; const CPU: TCPU): String; |
| 257 |
begin |
| 258 |
if Target = targetCustom then |
| 259 |
Result := Format('OS / CPU "%s / %s"', [OSToString(OS), CPUToString(CPU)]) |
| 260 |
else |
| 261 |
Result := Format('target "%s"', [TargetToString(Target)]); |
| 262 |
end; |
| 263 |
|
| 264 |
function TargetOptionHelp: string; |
| 265 |
begin |
| 266 |
Result := OptionDescription('--target=<target>', |
| 267 |
'The target system for which we build/package.' +NL+ |
| 268 |
'Available <target> values: ' +NL+ |
| 269 |
NL + |
| 270 |
'- "custom" (default): Build for a single OS and CPU combination, determined by the --os and --cpu options. These options, in turn, by default indicate the current (host) OS/CPU.' +NL+ |
| 271 |
NL + |
| 272 |
'- "ios": Build for all the platforms necessary for iOS applications. This includes both 32-bit and 64-bit iOS devices and iPhoneSimulator.' +NL+ |
| 273 |
NL + |
| 274 |
'- "android": Build for all the platforms necessary for Android applications. This includes both 32-bit and 64-bit Android devices.' +NL+ |
| 275 |
NL + |
| 276 |
'- "nintendo-switch": Build an application for Nintendo Switch.' +NL+ |
| 277 |
''); |
| 278 |
end; |
| 279 |
|
| 280 |
function CPUOptionHelp: string; |
| 281 |
var |
| 282 |
CPU: TCPU; |
| 283 |
Description, Extra: String; |
| 284 |
begin |
| 285 |
Description := 'Set the target processor for which we build/package.' +NL+ |
| 286 |
'This is ignored if you used --target=<target>, with <target> being something else than "custom".' +NL+ |
| 287 |
'Available <cpu> values: ' +NL; |
| 288 |
for CPU := Low(TCPU) to High(TCPU) do |
| 289 |
if CPU <> cpuNone then |
| 290 |
begin |
| 291 |
case CPU of |
| 292 |
aarch64: Extra := ' (64-bit ARM)'; |
| 293 |
else Extra := ''; |
| 294 |
end; |
| 295 |
Description := Description + ' ' + CPUToString(CPU) + Extra + NL; |
| 296 |
end; |
| 297 |
Result := OptionDescription('--cpu=<cpu>', Description); |
| 298 |
end; |
| 299 |
|
| 300 |
function OSOptionHelp: string; |
| 301 |
var |
| 302 |
OS: TOS; |
| 303 |
Description, Extra: String; |
| 304 |
begin |
| 305 |
Description := 'Set the target operating system for which we build/package.' +NL+ |
| 306 |
'This is ignored if you used --target=<target>, with <target> being something else than "custom".' +NL+ |
| 307 |
'Available <os> values: ' +NL; |
| 308 |
for OS := Low(TOS) to High(TOS) do |
| 309 |
if OS <> osNone then |
| 310 |
begin |
| 311 |
case OS of |
| 312 |
macosclassic: Extra := ' (classic MacOS, that ended with MacOS 9)'; |
| 313 |
darwin: Extra := ' (modern macOS 10.x, caled also Mac OS X)'; |
| 314 |
else Extra := ''; |
| 315 |
end; |
| 316 |
Description := Description + ' ' + OSToString(OS) + Extra + NL; |
| 317 |
end; |
| 318 |
Result := OptionDescription('--os=<os>', Description); |
| 319 |
end; |
| 320 |
|
| 321 |
function ExeExtensionOS(const OS: TOS): string; |
| 322 |
begin |
| 323 |
if OS in AllWindowsOSes then |
| 324 |
Result := '.exe' else |
| 325 |
Result := ''; |
| 326 |
end; |
| 327 |
|
| 328 |
function LibraryExtensionOS(const OS: TOS; const Static: boolean): string; |
| 329 |
begin |
| 330 |
if Static then |
| 331 |
// Correct for Unix, not sure about Windows. This is used only for iOS now. |
| 332 |
Result := '.a' else |
| 333 |
if OS in AllWindowsOSes then |
| 334 |
Result := '.dll' else |
| 335 |
if OS in [Darwin,iphonesim] then |
| 336 |
Result := '.dylib' else |
| 337 |
Result := '.so'; |
| 338 |
end; |
| 339 |
|
| 340 |
end. |