-
Notifications
You must be signed in to change notification settings - Fork 11
/
installerfpc.pas
executable file
·5091 lines (4518 loc) · 188 KB
/
installerfpc.pas
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
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit installerFpc;
{ FPC installer/updater module
Copyright (C) 2012-2014 Ludo Brands, Reinier Olislagers
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version with the following modification:
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent modules,and
to copy and distribute the resulting executable under terms of your choice,
provided that you also meet, for each linked independent module, the terms
and conditions of the license of that module. An independent module is a
module which is not derived from or based on this library. If you modify
this library, you may extend this exception to your version of the library,
but you are not obligated to do so. If you do not wish to do so, delete this
exception statement from your version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
for more details.
You should have received a copy of the GNU Library General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
}
{$mode objfpc}{$H+}
{$i fpcupdefines.inc}
interface
uses
Classes, SysUtils, installerCore, m_crossinstaller, processutils;
Const
Sequences=
// convention: FPC sequences start with 'FPC' [constant _FPC].
//standard fpc build
_DECLARE+_FPC+_SEP+
_CLEANMODULE+_FPC+_SEP+
// Create the link early so invalid previous
// versions are overwritten:
_EXECUTE+_CREATEFPCUPSCRIPT+_SEP+
_CHECKMODULE+_FPC+_SEP+
_GETMODULE+_FPC+_SEP+
_BUILDMODULE+_FPC+_SEP+
_END+
//standard uninstall
_DECLARE+_FPC+_UNINSTALL+_SEP+
//_CLEANMODULE+_FPC+_SEP+
_UNINSTALLMODULE+_FPC+_SEP+
_END+
{$ifdef mswindows}
{$ifdef win32}
// Crosscompile build
_DECLARE+_FPC+_CROSSWIN+_SEP+
_SETCPU+'x86_64'+_SEP +_SETOS+'win64'+_SEP +
// Getmodule has already been done
_CLEANMODULE+_FPC+_SEP+
_BUILDMODULE+_FPC+_SEP+
_SETCPU+'i386'+_SEP+_SETOS+'win32'+_SEP+
_END+
{$endif}
{$ifdef win64}
// Crosscompile build
_DECLARE+_FPC+_CROSSWIN+_SEP+
_SETCPU+'i386'+_SEP+_SETOS+'win32'+_SEP+
// Getmodule has already been done
_CLEANMODULE+_FPC+_SEP+
_BUILDMODULE+_FPC+_SEP+
_SETCPU+'x86_64'+_SEP+_SETOS+'win64'+_SEP+
_END+
{$endif}
{$endif mswindows}
//selective actions triggered with --only=SequenceName
_DECLARE+_FPC+_CHECK+_ONLY+_SEP+_CHECKMODULE+_FPC+_SEP+_END+
_DECLARE+_FPC+_CLEAN+_ONLY+_SEP+_CLEANMODULE+_FPC+_SEP+_END+
_DECLARE+_FPC+_GET+_ONLY+_SEP+_GETMODULE+_FPC+_SEP+_END+
_DECLARE+_FPC+_BUILD+_ONLY+_SEP+_BUILDMODULE+_FPC+_SEP+_END+
//standard clean
_DECLARE+_FPC+_CLEAN+_SEP+
_CLEANMODULE+_FPC+_SEP+
_END+
_DECLARE+_FPCCLEANBUILDONLY+_SEP+
_CLEANMODULE+_FPC+_SEP+
_BUILDMODULE+_FPC+_SEP+
_END+
_DECLARE+_FPCREMOVEONLY+_SEP+
_CLEANMODULE+_FPC+_SEP+
_UNINSTALLMODULE+_FPC+_SEP+
_END+
_DECLARE+_MAKEFILECHECKFPC+_SEP+
_BUILDMODULE+_MAKEFILECHECKFPC+_SEP+
_ENDFINAL;
type
{ TFPCInstaller }
TFPCInstaller = class(TBaseFPCInstaller)
private
FSoftFloat : boolean;
FUseLibc : boolean;
FUseRevInc : boolean;
FTargetCompilerName: string;
FBootstrapCompiler: string;
FBootstrapCompilerDirectory: string;
FBootstrapCompilerURL: string;
FBootstrapCompilerOverrideVersionCheck: boolean; //Indicate to make we really want to compile with this version (e.g. trunk compiler), even if it is not the latest stable version
FNativeFPCBootstrapCompiler: boolean;
InitDone: boolean;
function GetCompilerVersionNumber(aVersion: string; const index:byte=0): integer;
function CleanExtra(aCPU:TCPU=TCPU.cpuNone;aOS:TOS=TOS.osNone):boolean;
protected
function GetUnitsInstallDirectory(WithMagic:boolean):string;
function GetVersionFromUrl(aUrl: string): string;override;
function GetVersionFromSource: string;override;
function GetReleaseCandidateFromSource:integer;override;
// Build module descendant customisation
function BuildModuleCustom(ModuleName:string): boolean; virtual;
// Retrieves compiler version string
function GetCompilerTargetOS(CompilerPath: string): string;
function GetCompilerTargetCPU(CompilerPath: string): string;
function GetBootstrapCompilerVersionFromVersion(aVersion: string): string;
function GetBootstrapCompilerVersionFromSource(aSourcePath: string; GetLowestRequirement:boolean=false): string;
// Creates fpc proxy script that masks general fpc.cfg
function CreateFPCScript:boolean;
// Downloads bootstrap compiler for relevant platform, reports result.
function DownloadBootstrapCompiler: boolean;
function GetFPCRevision: string;
// internal initialisation, called from BuildModule,CleanModule,GetModule
// and UnInstallModule but executed only once
function InitModule(aBootstrapVersion:string=''):boolean;
public
property UseLibc: boolean read FUseLibc;
property SoftFloat: boolean write FSoftFloat;
//Directory that has compiler needed to compile compiler sources. If compiler doesn't exist, it will be downloaded
property BootstrapCompilerDirectory: string write FBootstrapCompilerDirectory;
// Build module
function BuildModule(ModuleName:string): boolean; override;
// Clean up environment
function CleanModule(ModuleName:string): boolean; override;
function ConfigModule(ModuleName:string): boolean; override;
// Install update sources
function GetModule(ModuleName:string): boolean; override;
// Perform some checks on the sources
function CheckModule(ModuleName: string): boolean; override;
// If yes, an override option will be passed to make (OVERRIDEVERSIONCHECK=1)
// If no, the FPC make script enforces that the latest stable FPC bootstrap compiler is used.
// This is required information for setting make file options
property BootstrapCompilerOverrideVersionCheck: boolean read FBootstrapCompilerOverrideVersionCheck;
//Indicate to use FPC bootstrappers from FTP server
property NativeFPCBootstrapCompiler: boolean read FNativeFPCBootstrapCompiler write FNativeFPCBootstrapCompiler;
property TargetCompilerName: string read FTargetCompilerName;
function UnInstallModule(ModuleName:string): boolean; override;
constructor Create;
destructor Destroy; override;
end;
type
{ TFPCNativeInstaller }
TFPCNativeInstaller = class(TFPCInstaller)
protected
// Build module descendant customisation. Runs make all/install for native FPC
function BuildModuleCustom(ModuleName:string): boolean; override;
public
constructor Create;
destructor Destroy; override;
end;
type
{ TFPCCrossInstaller }
TFPCCrossInstaller = class(TFPCInstaller)
private
FCrossCompilerName: string;
function CompilerUpdateNeeded:boolean;
function PackagesNeeded:boolean;
function InsertFPCCFGSnippet(FPCCFG,Snippet: string): boolean;
property CrossCompilerName: string read FCrossCompilerName;
protected
function SubarchTarget:boolean;
// Build module descendant customisation
function BuildModuleCustom(ModuleName:string): boolean; override;
public
constructor Create;
destructor Destroy; override;
function UnInstallModule(ModuleName:string): boolean; override;
procedure SetTarget(aCPU:TCPU;aOS:TOS;aSubArch:TSUBARCH);override;
end;
implementation
uses
StrUtils,
FileUtil,
fpcuputil,
repoclient
{$IFDEF UNIX}
,baseunix
,LazFileUtils
{$ENDIF UNIX}
{$IFDEF BSD}
,math
{$ENDIF}
;
const
DEFINE_FPC_SOFT_FPUX80 = 'FPC_SOFT_FPUX80';
{ TFPCCrossInstaller }
constructor TFPCCrossInstaller.Create;
begin
inherited Create;
FCrossCompilerName:='invalid';
end;
destructor TFPCCrossInstaller.Destroy;
begin
inherited Destroy;
end;
function TFPCCrossInstaller.SubarchTarget:boolean;
begin
result:=false;
if (NOT Assigned(CrossInstaller)) then exit;
result:=((CrossInstaller.TargetCPU<>TCPU.cpuNone) AND (CrossInstaller.TargetOS<>TOS.osNone) AND (CrossInstaller.TargetOS in SUBARCH_OS) AND (CrossInstaller.TargetCPU in SUBARCH_CPU));
end;
function TFPCCrossInstaller.CompilerUpdateNeeded:boolean;
var
NativeVersion,CrossVersion:string;
NativeCompiler,CrossCompiler:string;
NativeAge,CrossAge:Longint;
begin
result:=true;
NativeCompiler:=GetFPCInBinDir;
if (FileExists(NativeCompiler)) then
begin
CrossCompiler:=ExtractFilePath(NativeCompiler)+CrossCompilerName;
if FileExists(CrossCompiler) then
begin
// Look at version and revision
NativeVersion:=CompilerVersion(NativeCompiler);
CrossVersion:=CompilerVersion(CrossCompiler);
if (Length(CrossVersion)>0) AND (CrossVersion<>'0.0.0') AND (CompareVersionStrings(CrossVersion,NativeVersion)=0) then
begin
NativeVersion:=CompilerRevision(NativeCompiler);
CrossVersion:=CompilerRevision(CrossCompiler);
if (Length(CrossVersion)>0) AND (CrossVersion=NativeVersion) then result:=false;
end;
if (NOT result) then
begin
// Look at fileage
NativeAge:=FileAge(NativeCompiler);
CrossAge:=FileAge(CrossCompiler);
if (NativeAge>=CrossAge) then result:=true
end;
end;
end;
end;
function TFPCCrossInstaller.PackagesNeeded:boolean;
begin
result:=true;
// registry.pp does not build for arm-freertos, so disable
if (CrossInstaller.TargetCPU=TCPU.arm) AND (CrossInstaller.TargetOS=TOS.freertos) then result:=false;
// disable by default for avr-embedded (due to unicode not compiled-in)
if (CrossInstaller.TargetCPU=TCPU.avr) AND (CrossInstaller.TargetOS=TOS.embedded) then result:=false;
// Safeguards
if (CrossInstaller.TargetCPU=TCPU.arm) AND (CrossInstaller.TargetOS=TOS.embedded) then result:=false;
// Safeguards
if (CrossInstaller.TargetCPU=TCPU.xtensa) AND (CrossInstaller.TargetOS=TOS.freertos) then result:=false;
end;
function TFPCCrossInstaller.InsertFPCCFGSnippet(FPCCFG,Snippet: string): boolean;
// Adds snippet to fpc.cfg file or replaces if if first line of snippet is present
// Returns success (snippet inserted or added) or failure
const
FPCCFGINFOTEXT='FPCCrossInstaller (InsertFPCCFGSnippet: '+FPCCONFIGFILENAME+'): ';
var
ConfigText: TStringList;
i,j,k:integer;
SnipBegin,SnipEnd: integer;
SnippetText,SubarchText: TStringList;
NewSnipped:boolean;
SUBARCH:TSUBARCH;
Subarchs:TSUBARCHS;
begin
result:=true;
if (NOT Assigned(CrossInstaller)) OR (NOT FileExists(FPCCFG)) then
begin
exit(false);
end;
NewSnipped:=false;
//Set CPU
//s2:=UpperCase(CrossInstaller.TargetCPUName);
//if (CrossInstaller.TargetCPU=TCPU.powerpc) then
//begin
// s2:='POWERPC32'; //Distinguish between 32 and 64 bit powerpc
//end;
ConfigText:=TStringList.Create;
{$IF FPC_FULLVERSION > 30100}
//ConfigText.DefaultEncoding:=TEncoding.ASCII;
{$ENDIF}
SnippetText:=TStringList.Create;
SubarchText:=TStringList.Create;
try
if Length(Snippet)>0 then SnippetText.Text:=Snippet;
ConfigText.LoadFromFile(FPCCFG);
SnipBegin:=StringListSame(ConfigText,SnipMagicBegin+CrossInstaller.RegisterName);
if (SnipBegin<>-1) then
begin
// Now look for the end of the snipped
SnipEnd:=StringListSame(ConfigText,SnipMagicEnd{+CrossInstaller.RegisterName},SnipBegin);
// Also look for the end of the snipped of an old config file
//if (SnipEnd=-1) then
// SnipEnd:=StringListSame(ConfigText,SnipMagicEnd,SnipBegin);
if (SnipEnd=-1) then
begin
Infoln(FPCCFGINFOTEXT+'Existing snippet was not closed correct. Will continue, but please check your '+FPCCONFIGFILENAME+'.',etWarning);
// Snipped not closed correct.
// Look for start of next snipped in any
SnipEnd:=StringListSame(ConfigText,SnipMagicBegin,SnipBegin);
if (SnipEnd=-1) then
begin
// Snipped not closed at all
// We could error out.
// But, for now, set end to end of config file.
// To be improved.
SnipEnd:=ConfigText.Count;
//result:=false;
//Infoln(FPCCFGINFOTEXT+'Existing snippet was not closed at all. Please check your '+FPCCONFIGFILENAME+' for '+SnipMagicEnd+'.',etError);
end
else
begin
Dec(SnipEnd);
end;
end;
end
else
begin
// Snipped not found.
NewSnipped:=true;
if SnippetText.Count>0 then
begin
// Add empty line if needed
if ConfigText[ConfigText.Count-1]<>'' then ConfigText.Append('');
// Simple: new snipped to be appended
ConfigText.Append(SnipMagicBegin+CrossInstaller.RegisterName);
ConfigText.Append('# Inserted by fpcup '+DateTimeToStr(Now));
ConfigText.Append('# Cross compile settings dependent on both target OS and target CPU');
ConfigText.Append('#IFDEF FPC_CROSSCOMPILING');
ConfigText.Append('#IFDEF '+UpperCase(CrossInstaller.TargetOSName));
ConfigText.Append('#IFDEF CPU'+UpperCase(CrossInstaller.TargetCPUName));
// Just add new snipped
if SnippetText.Count>0 then
begin
for i:=0 to (SnippetText.Count-1) do
ConfigText.Append(SnippetText.Strings[i]);
end;
ConfigText.Append('#ENDIF CPU'+UpperCase(CrossInstaller.TargetCPUName));
ConfigText.Append('#ENDIF '+UpperCase(CrossInstaller.TargetOSName));
ConfigText.Append('#ENDIF FPC_CROSSCOMPILING');
ConfigText.Append(SnipMagicEnd{+CrossInstaller.RegisterName});
end;
end;
if result AND (NOT NewSnipped) then
begin
if (SnippetText.Count=0) then
begin
// Remove config for this target
for k:=0 to (SnipEnd-SnipBegin) do if (SnipBegin<ConfigText.Count) then ConfigText.Delete(SnipBegin);
while (SnipBegin<ConfigText.Count) AND (ConfigText[SnipBegin]='') do ConfigText.Delete(SnipBegin);
end
else
begin
// Existing snipped !! The hard part.
// First, locate real config snipped inside config
j:=StringListSame(ConfigText,'#IFDEF CPU'+CrossInstaller.TargetCPUName,SnipBegin);
if (j>SnipEnd) then j:=-1;
if (j=-1) then
begin
// This is a severe error and should never happen
// Do not yet know how to handle it
result:=false;
end
else
begin
i:=StringListSame(ConfigText,'#ENDIF CPU'+CrossInstaller.TargetCPUName,j);
if (i=-1) then
begin
// Old versions of fpcupdeluxe used a simple 3 x #ENDIF ... check for this !!
i:=StringListSame(ConfigText,'#ENDIF',j);
if (i<>-1) then
begin
if ((i+2)>Pred(ConfigText.Count)) OR (ConfigText[i+1]<>'#ENDIF') OR (ConfigText[i+2]<>'#ENDIF') then
i:=-1;
end;
end;
if (i>SnipEnd) then i:=-1;
if (i=-1) then
begin
// This is a severe error and should never happen
// Do not yet know how to handle it
result:=false;
end
else
begin
Inc(j);
Dec(i);
SnipBegin:=j;
SnipEnd:=i;
end;
end;
// SnipBegin and SnipEnd now point to space between #IFDEFS of target CPU
// So everything in between handles general settings and subarch settings
if result then
begin
// Save all subarch settings except for current subarch that needs to be replaced
Subarchs:=GetSubarchs(CrossInstaller.TargetCPU,CrossInstaller.TargetOS);
for SUBARCH in Subarchs do
begin
if (SUBARCH=TSUBARCH.saNone) then continue;
repeat
// Do we have a config with a Subarch define
j:=StringListSame(ConfigText,'#IFDEF CPU'+GetSubarch(SUBARCH),SnipBegin);
if (j>SnipEnd) then j:=-1;
if (j=-1) then break;
i:=StringListSame(ConfigText,'#ENDIF CPU'+GetSubarch(SUBARCH),j);
if (i>SnipEnd) then i:=-1;
if (i=-1) then
begin
// This is a severe error and should never happen
// Do not yet know how to handle it
// Just quit
result:=false;
break;
end
else
begin
// Found subarch part
for k:=0 to (i-j) do
begin
// Save non-matching subarch settings
if (SUBARCH<>CrossInstaller.SubArch) then
SubarchText.Append(ConfigText.Strings[j]);
// Delete this subarch part from config
ConfigText.Delete(j);
Dec(SnipEnd);
end;
end;
until false;
end;
if result then
begin
// Add new subarch settings if any
if (CrossInstaller.SubArch<>TSUBARCH.saNone) then
begin
NewSnipped:=false;
SubarchText.Append('#IFDEF CPU'+UpperCase(CrossInstaller.SubArchName));
repeat
// Do we have a config with a Subarch define
j:=StringListSame(SnippetText,'#IFDEF CPU'+CrossInstaller.SubArchName,0);
if (j=-1) then break;
// We have a subarch
// Now, add only subarch part.
i:=StringListSame(SnippetText,'#ENDIF CPU'+CrossInstaller.SubArchName,j);
if (i=-1) then
begin
// This is a severe error and should never happen
// Do not yet know how to handle it
// Just quit
result:=false;
break;
end
else
begin
// Found subarch part
NewSnipped:=true;
// Delete source #ENDIF CPUXXXXX
SnippetText.Delete(i);
// Delete source #IFDEF CPUXXXXX
SnippetText.Delete(j);
Dec(i,2);
for k:=j to i do
begin
SubarchText.Append(SnippetText.Strings[j]);
SnippetText.Delete(j);
end;
end;
until false;
SubarchText.Append('#ENDIF CPU'+UpperCase(CrossInstaller.SubArchName));
// Bit tricky: remove defines if not used anymore
if (NOT NewSnipped) then
begin
SubarchText.Delete(Pred(SubarchText.Count));
SubarchText.Delete(Pred(SubarchText.Count));
end;
end;
if result then
begin
// We now have a subarchtext with all new and previous defines.
for k:=0 to (SnipEnd-SnipBegin) do ConfigText.Delete(SnipBegin);
// We now have a a cleaned up general config
// Add new subarch snipped into config file
if (SubarchText.Count>0) then
begin
for k:=0 to (SubarchText.Count-1) do
begin
ConfigText.Insert(SnipBegin,SubarchText.Strings[k]);
Inc(SnipBegin);
end;
end;
// Add new config snipped into config file
if (SnippetText.Count>0) then
begin
for k:=0 to (SnippetText.Count-1) do
begin
ConfigText.Insert(SnipBegin,SnippetText.Strings[k]);
Inc(SnipBegin);
end;
end;
// All ok and done !!
end;
end;
end;
end;
end;
if (SnippetText.Count>0) then
begin
//{$ifndef Darwin}
{$ifdef MSWINDOWS}
// remove pipeline assembling for Darwin when cross-compiling !!
// for FPC >= rev 42302 this is not needed anymore: DoPipe:=false; by default on non-unix !!
SnipBegin:=ConfigText.IndexOf('# use pipes instead of temporary files for assembling');
if SnipBegin>-1 then
begin
if ConfigText.Strings[SnipBegin+1]<>'#IFNDEF FPC_CROSSCOMPILING' then
begin
ConfigText.Insert(SnipBegin+1,'#IFNDEF FPC_CROSSCOMPILING');
ConfigText.Insert(SnipBegin+3,'#ENDIF');
end;
end;
{$endif}
end;
ConfigText.SaveToFile(FPCCFG);
result:=true;
finally
SubarchText.Free;
ConfigText.Free;
SnippetText.Free;
end;
Infoln(FPCCFGINFOTEXT+'Inserting snippet in '+FPCCFG+' done.',etInfo);
end;
procedure TFPCCrossInstaller.SetTarget(aCPU:TCPU;aOS:TOS;aSubArch:TSUBARCH);
begin
inherited;
if Assigned(CrossInstaller) then
FCrossCompilerName:=GetCrossCompilerName(CrossInstaller.TargetCPU);
end;
function TFPCCrossInstaller.BuildModuleCustom(ModuleName: string): boolean;
// Runs make/make install for cross compiler.
// Error out on problems; unless module considered optional, i.e. in
// crosswin32-64 and crosswin64-32 steps.
type
{$ifdef crosssimple}
TSTEPS = (st_MakeAll,st_MakeCrossInstall);
{$else}
TSTEPS = (st_Compiler,st_CompilerInstall,st_Rtl,st_RtlInstall,st_Packages,st_PackagesInstall,st_NativeCompiler);
{$endif}
var
FPCCfg:String; //path+filename of the fpc.cfg configuration file
CrossOptions:String;
i,j:integer;
Options:String;
TxtFile:Text;
s1,s2:string;
UnitSearchPath:string;
LibsAvailable,BinsAvailable:boolean;
MakeCycle:TSTEPS;
//ARMArch:TARMARCH;
SupportedList:TStringList;
{$ifdef MSWINDOWS}
Counter:integer;
{$endif}
begin
result:=inherited;
result:=false; //fail by default
if Assigned(CrossInstaller) then
begin
CrossInstaller.Reset;
{$ifdef win32}
// Skip cross-builing towards win64 for old versions of FPC
if (CrossInstaller.TargetCPU=TCPU.x86_64) and ((CrossInstaller.TargetOS=TOS.win64) or (CrossInstaller.TargetOS=TOS.win32)) then
begin
if (SourceVersionNum<CalculateFullVersion(2,4,2)) then
begin
result:=true;
exit;
end;
end;
{$endif win32}
if CrossInstaller.TargetCPU=TCPU.jvm then DownloadJasmin;
CrossInstaller.SetFPCVersion(SourceVersionStr);
CrossInstaller.SetCrossOpt(CrossOPT);
CrossInstaller.SetSubArch(CrossOS_SubArch);
CrossInstaller.SetABI(CrossOS_ABI);
Infoln(infotext+'Looking for crosstools and crosslibs on system. Please wait.',etInfo);
// first, get/set cross binary utils !!
BinsAvailable:=false;
CrossInstaller.SearchModeUsed:=DEFAULTSEARCHSETTING;
if Length(CrossToolsDirectory)>0 then
begin
// we have a crosstools setting
if (CrossToolsDirectory=FPCUP_AUTO_MAGIC)
then CrossInstaller.SearchModeUsed:=TSearchSetting.ssAuto
else CrossInstaller.SearchModeUsed:=TSearchSetting.ssCustom;
end;
if CrossInstaller.SearchModeUsed=TSearchSetting.ssCustom
then BinsAvailable:=CrossInstaller.GetBinUtils(CrossToolsDirectory)
else BinsAvailable:=CrossInstaller.GetBinUtils(BaseDirectory);
if (not BinsAvailable) then Infoln('Failed to get crossbinutils', etError);
// second, get/set cross libraries !!
LibsAvailable:=false;
CrossInstaller.SearchModeUsed:=DEFAULTSEARCHSETTING;
if Length(CrossLibraryDirectory)>0 then
begin
// we have a crosslibrary setting
if (CrossLibraryDirectory=FPCUP_AUTO_MAGIC)
then CrossInstaller.SearchModeUsed:=TSearchSetting.ssAuto
else CrossInstaller.SearchModeUsed:=TSearchSetting.ssCustom;
end;
if CrossInstaller.SearchModeUsed=TSearchSetting.ssCustom
then LibsAvailable:=CrossInstaller.GetLibs(CrossLibraryDirectory)
else LibsAvailable:=CrossInstaller.GetLibs(BaseDirectory);
if (not LibsAvailable) then Infoln('Failed to get crosslibrary', etError);
result:=(BinsAvailable AND LibsAvailable);
if result then
begin
result:=false;
s1:=CompilerVersion(FCompiler);
if (s1<>'0.0.0') then
Infoln('FPC '+CrossInstaller.TargetCPUName+'-'+CrossInstaller.TargetOSName+' cross-builder: Using compiler with version: '+s1, etInfo)
else
Infoln(infotext+'FPC compiler ('+FCompiler+') version error: '+s1+' ! Should never happen: expect many errors !!', etError);
{$ifdef MSWINDOWS}
CreateBinutilsList(CrossInstaller.FPCVersion);
{$endif MSWINDOWS}
FPCCfg := FFPCCompilerBinPath + FPCCONFIGFILENAME;
begin
// Add binutils path to path if necessary
if CrossInstaller.BinUtilsPathInPath then
SetPath(IncludeTrailingPathDelimiter(CrossInstaller.BinUtilsPath),false,true);
for MakeCycle:=Low(TSTEPS) to High(TSTEPS) do
begin
// ARMHF crosscompiler build option
if (MakeCycle=st_Compiler) then
begin
if (CrossInstaller.TargetCPU=TCPU.arm) then
begin
(*
// what to do ...
// always build hardfloat for ARM ?
// or default to softfloat for ARM ?
// FPC sources default (ppcarm.lpi): ARMHF for versions >= 3.2.0
// decision: always build hardfloat for FPC >= 3.2.0
j:=CalculateNumericalVersion(CrossInstaller.FPCVersion);
if (j<>0) AND (j>=CalculateFullVersion(3,2,0)) then
begin
s2:=ARMArchFPCStr[TARMARCH.armhf];
for ARMArch := Low(TARMARCH) to High(TARMARCH) do
begin
s1:=ARMArchFPCStr[ARMArch];
if (Length(s1)>0) and (Pos(s1,FCompilerOptions)>0) then
begin
s2:='';
break;
end;
end;
if (Length(s2)>0) then
begin
Infoln('Adding ARMHF compiler option for FPC >= 3.2.0 !',etWarning);
FCompilerOptions:=FCompilerOptions+' '+s2;
end;
end;
*)
end;
end;
if (MakeCycle=st_Rtl) then
begin
if (CrossInstaller.TargetCPU=TCPU.arm) then
begin
//Check for EABI + FPC_ARMHF combo that is invalid for everything < 3.3
//This is tricky
s2:='-CaEABI';
i:=StringListSame(CrossInstaller.CrossOpt,s2);
if (i<>-1) then
begin
// Get the correct name of the cross-compiler in source-directory
s1:=ConcatPaths([SourceDirectory,'compiler','ppcross'+ppcSuffix[CrossInstaller.TargetCPU]]);
// Get the correct name of the cross-compiler in install-directory
if (NOT FileExists(s1)) then
s1:=FFPCCompilerBinPath+CrossCompilerName;
if FileExists(s1) then
begin
// Get compiler ABI's
s1:=CompilerABI(s1);
if (Length(s1)>0) then
begin
SupportedList:=TStringList.Create;
try
SupportedList.Text:=s1;
j:=StringListSame(SupportedList,'EABI');
if (j=-1) then
begin
// -CaEABI not allowed: remove it from config !!
Infoln('Removing '+s2+' crosscompiler option: not allowed for ARMHF FPC '+CrossInstaller.FPCVersion+' !',etWarning);
CrossInstaller.CrossOpt.Delete(i);
// The cfg snipped might also contains this define: remove it
// Bit tricky
CrossInstaller.ReplaceFPCCFGSnippet(s2,'');
end;
finally
SupportedList.Free;
end;
end;
end;
end;
//Check for FPV4_SP_D16 that is invalid for everything < 3.3
//This is tricky
s2:='-CfFPV4_SP_D16';
i:=StringListSame(CrossInstaller.CrossOpt,s2);
if (i<>-1) then
begin
// Get the correct name of the cross-compiler in source-directory
s1:=ConcatPaths([SourceDirectory,'compiler','ppcross'+ppcSuffix[CrossInstaller.TargetCPU]]);
// Get the correct name of the cross-compiler in install-directory
if (NOT FileExists(s1)) then
s1:=FFPCCompilerBinPath+CrossCompilerName;
if FileExists(s1) then
begin
// Get compiler FPU's
s1:=CompilerFPU(s1);
if (Length(s1)>0) then
begin
SupportedList:=TStringList.Create;
try
SupportedList.Text:=s1;
j:=StringListSame(SupportedList,'FPV4_SP_D16');
if (j=-1) then
begin
// Rename this option: not allowed for FPC < 3.3
s1:='-CfVFPV3_D16';
Infoln('Renaming '+s2+' crosscompiler option to '+s1+' for FPC '+CrossInstaller.FPCVersion+' !',etWarning);
CrossInstaller.CrossOpt[i]:=s1;
// The cfg snipped might also contains this define: rename it
// Bit tricky
CrossInstaller.ReplaceFPCCFGSnippet(s2,s1);
end;
finally
SupportedList.Free;
end;
end;
end;
end;
end;
end;
// Modify fpc.cfg
// always add this, to be able to detect which cross-compilers are installed
// helpfull for later bulk-update of all cross-compilers
if (MakeCycle=Low(TSTEPS)) OR (MakeCycle=High(TSTEPS)) then
begin
//Set basic config text
s1:='# Dummy (blank) config just to replace dedicated settings during build of cross-compiler'+LineEnding;
//Remove dedicated settings of config snippet
if MakeCycle=Low(TSTEPS) then
Infoln(infotext+'Removing '+FPCCONFIGFILENAME+' config snippet for target '+CrossInstaller.RegisterName,etInfo);
//Add config snippet
if (MakeCycle=High(TSTEPS)) then
begin
s1:='';
Infoln(infotext+'Adding '+FPCCONFIGFILENAME+' config snippet for target '+CrossInstaller.RegisterName,etInfo);
if CrossInstaller.FPCCFGSnippet<>'' then
s1:=s1+CrossInstaller.FPCCFGSnippet+LineEnding;
if (CrossInstaller.TargetOS=TOS.java) then
//s1:=s1+'-Fu'+ConcatPaths([InstallDirectory,'units',FPC_TARGET_MAGIC,'rtl','org','freepascal','rtl'])+LineEnding;
s1:=s1+'-Fu'+ConcatPaths([InstallDirectory,'units',CrossInstaller.RegisterName,'rtl','org','freepascal','rtl'])+LineEnding;
if (SubarchTarget) then
begin
UnitSearchPath:=GetUnitsInstallDirectory(true);
s1:=s1+'-Fu'+UnitSearchPath+DirectorySeparator+'rtl'+LineEnding;
s1:=s1+'-Fu'+UnitSearchPath+DirectorySeparator+'packages'+LineEnding;
if (CrossInstaller.TargetOS<>TOS.ultibo) then
begin
// Lazarus gives an error when units are located in a non-standard directory.
// Therefor: create a dummy system.ppu
// Tricky ... :-| ... !!!
//{$ifdef MSWINDOWS}
if (CrossInstaller.TargetOS in [TOS.embedded,TOS.freertos]) then
FileCreate(ConcatPaths([InstallDirectory,'units',CrossInstaller.RegisterName,'system.ppu']));
//{$endif MSWINDOWS}
end;
end;
if (Length(s1)=0) then s1:='# Dummy (blank) config for auto-detect cross-compilers'+LineEnding;
end;
//Edit dedicated settings of config snippet
InsertFPCCFGSnippet(FPCCfg,s1);
if (CrossInstaller.TargetOS=TOS.ultibo) then
begin
// Creating Ultibo configuration files
if (CrossInstaller.TargetCPU=TCPU.arm) then
begin
s1 := FFPCCompilerBinPath + 'RPI.CFG';
if (NOT FileExists(s1)) then
begin
//create RPI.CFG
AssignFile(TxtFile,s1);
Rewrite(TxtFile);
try
writeln(TxtFile,'#');
writeln(TxtFile,'# Raspberry Pi (A/B/A+/B+/Zero) specific config file');
writeln(TxtFile,'#');
writeln(TxtFile,'-CfVFPV2');
writeln(TxtFile,'-CIARM');
writeln(TxtFile,'-CaEABIHF');
writeln(TxtFile,'-OoFASTMATH');
writeln(TxtFile,'-dRPI');
writeln(TxtFile,'-dBCM2708');
s2:=GetUnitsInstallDirectory(true);
s2:=StringReplace(s2,FPC_SUBARCH_MAGIC,GetSubarch(TSUBARCH.armv6),[]);
writeln(TxtFile,'-Fu'+s2+DirectorySeparator+'rtl');
writeln(TxtFile,'-Fu'+s2+DirectorySeparator+'packages');
finally
CloseFile(TxtFile);
end;
end
else
begin
Infoln(infotext+'Found existing '+ExtractFileName(s1)+' in '+ExtractFileDir(s1));
end;
s1 := FFPCCompilerBinPath + 'RPI2.CFG';
if (NOT FileExists(s1)) then
begin
//create RPI2.CFG
AssignFile(TxtFile,s1);
Rewrite(TxtFile);
try
writeln(TxtFile,'#');
writeln(TxtFile,'# Raspberry Pi 2B specific config file');
writeln(TxtFile,'#');
writeln(TxtFile,'-CfVFPV3');
writeln(TxtFile,'-CIARM');
writeln(TxtFile,'-CaEABIHF');
writeln(TxtFile,'-OoFASTMATH');
writeln(TxtFile,'-dRPI2');
writeln(TxtFile,'-dBCM2709');
s2:=GetUnitsInstallDirectory(true);
s2:=StringReplace(s2,FPC_SUBARCH_MAGIC,GetSubarch(TSUBARCH.armv7a),[]);
writeln(TxtFile,'-Fu'+s2+DirectorySeparator+'rtl');
writeln(TxtFile,'-Fu'+s2+DirectorySeparator+'packages');
finally
CloseFile(TxtFile);
end;
end
else
begin
Infoln(infotext+'Found existing '+ExtractFileName(s1)+' in '+ExtractFileDir(s1));
end;
s1 := FFPCCompilerBinPath + 'RPI3.CFG';
if (NOT FileExists(s1)) then
begin
//create RPI3.CFG
AssignFile(TxtFile,s1);
Rewrite(TxtFile);
try
writeln(TxtFile,'#');
writeln(TxtFile,'# Raspberry Pi 3B/3B+/3A+/CM3/Zero2W specific config file');
writeln(TxtFile,'#');
writeln(TxtFile,'#IFDEF CPUARM');
writeln(TxtFile,'-CfVFPV3');
writeln(TxtFile,'-CIARM');
writeln(TxtFile,'-CaEABIHF');
writeln(TxtFile,'-OoFASTMATH');
writeln(TxtFile,'-dRPI3');
writeln(TxtFile,'-dBCM2710');
s2:=GetUnitsInstallDirectory(true);
s2:=StringReplace(s2,FPC_SUBARCH_MAGIC,GetSubarch(TSUBARCH.armv7a),[]);
writeln(TxtFile,'-Fu'+s2+DirectorySeparator+'rtl');
writeln(TxtFile,'-Fu'+s2+DirectorySeparator+'packages');
writeln(TxtFile,'#ENDIF');
writeln(TxtFile,'#IFDEF CPUAARCH64');
writeln(TxtFile,'-CfVFP');
writeln(TxtFile,'-OoFASTMATH');
writeln(TxtFile,'-dRPI3');
writeln(TxtFile,'-dBCM2710');
s2:=GetUnitsInstallDirectory(true);
s2:=StringReplace(s2,FPC_SUBARCH_MAGIC,GetSubarch(TSUBARCH.armv8),[]);
writeln(TxtFile,'-Fu'+s2+DirectorySeparator+'rtl');