-
Notifications
You must be signed in to change notification settings - Fork 4
/
installerfpc.pas
executable file
·1546 lines (1456 loc) · 61.5 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+}
interface
uses
Classes, SysUtils, installerCore, m_crossinstaller, processutils;
Const
Sequences=
// convention: FPC sequences start with 'FPC'.
//standard fpc build
'Declare FPC;'+
'Cleanmodule FPC;'+
// Create the link early so invalid previous
// versions are overwritten:
'Exec CreateFpcupScript;'+
'Getmodule FPC;'+
'Buildmodule FPC;'+
'End;'+
//standard uninstall
'Declare FPCuninstall;'+
'Uninstallmodule FPC;'+
'End;'+
//standard clean
'Declare FPCclean;'+
'cleanmodule FPC;'+
'End;'+
//selective actions triggered with --only=SequenceName
'Declare FPCCleanOnly;'+
'Cleanmodule FPC;'+
'End;'+
'Declare FPCGetOnly;'+
'Getmodule FPC;'+
'End;'+
'Declare FPCBuildOnly;'+
'Buildmodule FPC;'+
'End;'+
// Crosscompile build
'Declare FPCCrossWin32-64;'+
// Needs to be run after regular compile because of CPU/OS switch
'SetCPU x86_64;'+
'SetOS win64;'+
// Getmodule has already been done
'Cleanmodule fpc;'+
'Buildmodule fpc;'+
'End';
type
{ TFPCInstaller }
TFPCInstaller = class(TInstaller)
private
FBinPath: string; // path where generated compiler lives
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
InitDone: boolean;
protected
// Build module descendant customisation
function BuildModuleCustom(ModuleName:string): boolean; virtual;
// Retrieves compiler version string
function GetCompilerVersion(CompilerPath: string): string;
// Creates fpc proxy script that masks general fpc.cfg
function CreateFPCScript:boolean;
// Downloads bootstrap compiler for relevant platform, reports result.
function DownloadBootstrapCompiler: boolean;
// Another way to get the compiler version string
//todo: choose either GetCompilerVersion or GetFPCVersion
function GetFPCVersion: string;
// internal initialisation, called from BuildModule,CleanModule,GetModule
// and UnInstallModule but executed only once
function InitModule:boolean;
public
//Directory that has compiler needed to compile compiler sources. If compiler doesn't exist, it will be downloaded
property BootstrapCompilerDirectory: string write FBootstrapCompilerDirectory;
//Optional; URL from which to download bootstrap FPC compiler if it doesn't exist yet.
property BootstrapCompilerURL: string write FBootstrapCompilerURL;
// 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;
// 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 CompilerOverrideVersionCheck: boolean read FBootstrapCompilerOverrideVersionCheck;
// Uninstall module
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)
protected
// Build module descendant customisation
function BuildModuleCustom(ModuleName:string): boolean; override;
public
constructor Create;
destructor Destroy; override;
end;
implementation
uses fpcuputil,fileutil
{$IFDEF UNIX}
,baseunix
{$ENDIF UNIX}
;
const
SnipMagicBegin='# begin fpcup do not remove '; //look for this/add this in fpc.cfg cross-compile snippet. Note: normally followed by FPC CPU-os code
SnipMagicEnd='# end fpcup do not remove'; //denotes end of fpc.cfg cross-compile snippet
Win64FallBackUsingCrossCompiler=false; //Set to true to download i386 boostrap compiler and cross compile. Leave to use native win x64 compiler
function 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
var
ConfigText: TStringList;
i:integer;
SnipBegin,SnipEnd: integer;
SnippetText: TStringList;
begin
result:=false;
SnipBegin:=-1;
SnipEnd:=maxint;
ConfigText:=TStringList.Create;
SnippetText:=TStringList.Create;
try
SnippetText.Text:=Snippet;
ConfigText.LoadFromFile(FPCCFG);
// Look for exactly this string:
SnipBegin:=ConfigText.IndexOf(SnippetText.Strings[0]);
if SnipBegin>-1 then
begin
infoln('fpc.cfg: found existing snippet in '+FPCCFG+'. Deleting it and writing new version.',etInfo);
for i:=SnipBegin to ConfigText.Count-1 do
begin
// Once again, look exactly for this text:
if ConfigText.Strings[i]=SnipMagicEnd then
begin
SnipEnd:=i;
break;
end;
end;
if SnipEnd=maxint then
begin
//apparently snippet was not closed
infoln('fpc.cfg: existing snippet was not closed. Replacing it anyway. Please check your fpc.cfg.',etWarning);
SnipEnd:=i;
end;
for i:=SnipEnd downto SnipBegin do
begin
ConfigText.Delete(i);
end;
end;
// Add snippet at bottom after blank line
if ConfigText[ConfigText.Count-1]<>'' then
ConfigText.Add(LineEnding);
ConfigText.Add(Snippet);
ConfigText.SaveToFile(FPCCFG);
result:=true;
finally
ConfigText.Free;
SnippetText.Free;
end;
end;
{ TFPCCrossInstaller }
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.
var
FPCCfg:String; //path+filename of the fpc.cfg configuration file
CrossInstaller:TCrossInstaller;
CrossOptions:String;
ChosenCompiler:String; //Compiler to be used for cross compiling
i:integer;
OldPath:String;
Options:String;
begin
// Make crosscompiler using new compiler
{ Note: command line equivalents for Win32=>Win64 cross compiler:
set path=c:\development\fpc\bin\i386-win32;c:\development\fpcbootstrap
make FPC=c:\development\fpc\bin\i386-win32\fpc.exe --directory=c:\development\fpc INSTALL_PREFIX=c:\development\fpc UPXPROG=echo COPYTREE=echo all OS_TARGET=win64 CPU_TARGET=x86_64
rem already gives compiler\ppcrossx64.exe, compiler\ppcx64.exe
make FPC=c:\development\fpc\bin\i386-win32\fpc.exe --directory=c:\development\fpc INSTALL_PREFIX=c:\development\fpc UPXPROG=echo COPYTREE=echo crossinstall OS_TARGET=win64 CPU_TARGET=x86_64
rem gives bin\i386-win32\ppcrossx64.exe
Note: make install CROSSINSTALL=1 apparently installs, but does NOT install utilities (ld etc?) for that
platform; see posting Jonas Maebe http://lists.freepascal.org/lists/fpc-pascal/2011-August/030084.html
make all install CROSSCOMPILE=1??? find out?
}
result:=false; //fail by default
CrossInstaller:=GetCrossInstaller;
if assigned(CrossInstaller) then
begin
CrossInstaller.SetCrossOpt(CrossOPT); //pass on user-requested cross compile options
if not CrossInstaller.GetBinUtils(FBaseDirectory) then
infoln('Failed to get crossbinutils', etError)
else if not CrossInstaller.GetLibs(FBaseDirectory) then
infoln('Failed to get cross libraries', etError)
else
begin
if CrossInstaller.CompilerUsed=ctInstalled then
ChosenCompiler:=IncludeTrailingPathDelimiter(FBinPath)+'fpc'+GetExeExt {todo if this does not work use ppc386.exe etc}
else //ctBootstrap
ChosenCompiler:=FCompiler;
// Add binutils path to path if necessary
OldPath:=GetPath;
if CrossInstaller.BinUtilsPathInPath then
begin
SetPath(IncludeTrailingPathDelimiter(CrossInstaller.BinUtilsPath),false,true);
end;
// Make all
ProcessEx.Executable := Make;
ProcessEx.CurrentDirectory:=ExcludeTrailingPathDelimiter(FBaseDirectory);
ProcessEx.Parameters.Clear;
{$IFNDEF windows}
{ todo: disabled because make 3.80 is unreliable with multiple jobs on Windows.
Re-enable when changed to make 3.82 }
if FCPUCount>1 then
begin
// parallel processing
ProcessEx.Parameters.Add('--jobs='+inttostr(FCPUCount));
ProcessEx.Parameters.Add('FPMAKEOPT=--threads='+inttostr(FCPUCount));
end;
{$ENDIF}
ProcessEx.Parameters.Add('FPC='+ChosenCompiler);
ProcessEx.Parameters.Add('--directory='+ ExcludeTrailingPathDelimiter(FBaseDirectory));
ProcessEx.Parameters.Add('INSTALL_PREFIX='+ExcludeTrailingPathDelimiter(FBaseDirectory));
// Tell make where to find the target binutils if cross-compiling:
if CrossInstaller.BinUtilsPath<>'' then
ProcessEx.Parameters.Add('CROSSBINDIR='+ExcludeTrailingPathDelimiter(CrossInstaller.BinUtilsPath));
ProcessEx.Parameters.Add('UPXPROG=echo'); //Don't use UPX
ProcessEx.Parameters.Add('COPYTREE=echo'); //fix for examples in Win svn, see build FAQ
// Don't really know if this is necessary, but it can't hurt:
// Override makefile checks that checks for stable compiler in FPC trunk
if FBootstrapCompilerOverrideVersionCheck then
ProcessEx.Parameters.Add('OVERRIDEVERSIONCHECK=1');
//putting all before target might help!?!?
ProcessEx.Parameters.Add('all');
ProcessEx.Parameters.Add('OS_TARGET='+FCrossOS_Target);
ProcessEx.Parameters.Add('CPU_TARGET='+FCrossCPU_Target);
Options:=FCompilerOptions;
// Error checking for some known problems with cross compilers
//todo: this really should go to the cross compiler unit itself but would require a rewrite
if (CrossInstaller.TargetCPU='i8086') and
(CrossInstaller.TargetOS='msdos') then
begin
if (pos('-g',Options)>0) then
begin
infoln('You specified these FPC options: '+Options+'... however, this cross compiler does not support debug symbols. Aborting.',etError);
exit(false);
end;
end;
if CrossInstaller.LibsPath<>''then
Options:=Options+' -Xd -Fl'+CrossInstaller.LibsPath;
if CrossInstaller.BinUtilsPrefix<>'' then
begin
// Earlier, we used regular OPT; using CROSSOPT is apparently more precise
CrossOptions:='CROSSOPT=-XP'+CrossInstaller.BinUtilsPrefix;
ProcessEx.Parameters.Add('BINUTILSPREFIX='+CrossInstaller.BinUtilsPrefix);
end;
if (CrossInstaller.CrossOpt.Count>0) and (CrossOptions='') then
CrossOptions:='CROSSOPT=';
for i:=0 to CrossInstaller.CrossOpt.Count-1 do
begin
CrossOptions:=trimright(CrossOptions+' '+CrossInstaller.CrossOpt[i]);
end;
if CrossOptions<>'' then
ProcessEx.Parameters.Add(CrossOptions);
if Options<>'' then
ProcessEx.Parameters.Add('OPT='+Options);
try
if CrossOptions='' then
infoln('Running Make all (FPC crosscompiler: '+CrossInstaller.TargetCPU+'-'+CrossInstaller.TargetOS+')',etInfo)
else
infoln('Running Make all (FPC crosscompiler: '+CrossInstaller.TargetCPU+'-'+CrossInstaller.TargetOS+') with CROSSOPT: '+CrossOptions,etInfo);
ProcessEx.Execute;
result:=(ProcessEx.ExitStatus=0);
except
on E: Exception do
begin
WritelnLog('FPC: Running cross compiler fpc make all failed with an exception!'+LineEnding+
'Details: '+E.Message,true);
exit(false);
end;
end;
// Return path to previous state
if CrossInstaller.BinUtilsPathInPath then
begin
SetPath(OldPath,false,false);
end;
if not(Result) then
begin
// Not an error but warning for optional modules: crosswin32-64 and crosswin64-32
// These modules need to be optional because FPC 2.6.2 gives an error crosscompiling regarding fpdoc.css or something.
{$ifdef win32}
// if this is crosswin32-64, ignore error as it is optional
if (CrossInstaller.TargetCPU='x86_64') and ((CrossInstaller.TargetOS='win64') or (CrossInstaller.TargetOS='win32')) then
result:=true;
{$endif win32}
{$ifdef win64}
// if this is crosswin64-32, ignore error as it is optional
if (CrossInstaller.TargetCPU='i386') and (CrossInstaller.TargetOS='win32') then
result:=true;
{$endif win64}
FCompiler:='////\\\Error trying to compile FPC\|!';
if result then
infoln('FPC: Running cross compiler fpc make all for '+FCrossCPU_Target+'-'+FCrossOS_Target+' failed with an error code. Optional module; continuing regardless.', etInfo)
else
infoln('FPC: Running cross compiler fpc make all for '+FCrossCPU_Target+'-'+FCrossOS_Target+' failed with an error code.',etError);
// No use in going on, but
// do make sure installation continues if this happened with optional crosscompiler:
exit(result);
end
else
begin
// Install crosscompiler: make crossinstall
// (apparently equivalent to make install CROSSINSTALL=1)
ProcessEx.Executable := Make;
ProcessEx.CurrentDirectory:=ExcludeTrailingPathDelimiter(FBaseDirectory);
ProcessEx.Parameters.Clear;
infoln('Running Make crossinstall (FPC crosscompiler: '+CrossInstaller.TargetCPU+'-'+CrossInstaller.TargetOS+')', etinfo);
{$IFNDEF windows}
{ todo: disabled because make 3.80 is unreliable with multiple jobs on Windows.
Re-enable when changed to make 3.82 }
if FCPUCount>1 then
ProcessEx.Parameters.Add('--jobs='+inttostr(FCPUCount)); // parallel processing
{$ENDIF}
ProcessEx.Parameters.Add('FPC='+ChosenCompiler);
ProcessEx.Parameters.Add('INSTALL_PREFIX='+ExcludeTrailingPathDelimiter(FBaseDirectory));
{$IFDEF UNIX}
ProcessEx.Parameters.Add('INSTALL_BINDIR='+FBinPath);
{$ENDIF UNIX}
// Tell make where to find the target binutils if cross-compiling:
if CrossInstaller.BinUtilsPath<>'' then
ProcessEx.Parameters.Add('CROSSBINDIR='+ExcludeTrailingPathDelimiter(CrossInstaller.BinUtilsPath));
ProcessEx.Parameters.Add('UPXPROG=echo'); //Don't use UPX
ProcessEx.Parameters.Add('COPYTREE=echo'); //fix for examples in Win svn, see build FAQ
//putting crossinstall before target might help!?!?
ProcessEx.Parameters.Add('crossinstall');
ProcessEx.Parameters.Add('OS_TARGET='+FCrossOS_Target); //cross compile for different OS...
ProcessEx.Parameters.Add('CPU_TARGET='+FCrossCPU_Target); // and processor.
if CrossInstaller.BinUtilsPrefix<>'' then
begin
// Earlier, we used regular OPT; using CROSSOPT is apparently more precise
CrossOptions:='CROSSOPT=-XP'+CrossInstaller.BinUtilsPrefix;
ProcessEx.Parameters.Add('BINUTILSPREFIX='+CrossInstaller.BinUtilsPrefix);
end;
if (CrossInstaller.CrossOpt.Count>0) and (CrossOptions='') then
CrossOptions:='CROSSOPT=';
for i:=0 to CrossInstaller.CrossOpt.Count-1 do
begin
CrossOptions:=trimright(CrossOptions+' '+CrossInstaller.CrossOpt[i]);
end;
if CrossOptions<>'' then
ProcessEx.Parameters.Add(CrossOptions);
try
ProcessEx.Execute;
except
on E: Exception do
begin
WritelnLog('FPC: Running cross compiler fpc make crossinstall failed with an exception!'+LineEnding+
'Details: '+E.Message,true);
result:=false;
end;
end;
if ProcessEx.ExitStatus<>0 then
begin
// If anything else than crosswin32-64 or crosswin64-32, fail:
result:=false;
{$ifdef win32}
// if this is crosswin32-64, ignore error as it is optional
if (CrossInstaller.TargetCPU='x86_64') and ((CrossInstaller.TargetOS='win64') or (CrossInstaller.TargetOS='win32')) then
result:=true;
{$endif win32}
{$ifdef win64}
// if this is crosswin64-32, ignore error as it is optional
if (CrossInstaller.TargetCPU='i386') and (CrossInstaller.TargetOS='win32') then
result:=true;
{$endif win64}
if result then
infoln('FPC: Problem installing crosscompiler for '+FCrossCPU_Target+'-'+FCrossOS_Target+'. Optional module; continuing regardless.', etInfo)
else
infoln('FPC: Problem installing crosscompiler for '+FCrossCPU_Target+'-'+FCrossOS_Target+'.', etError);
FCompiler:='////\\\Error trying to compile FPC\|!';
end
else
begin
if CrossInstaller.FPCCFGSnippet<>'' then
begin
// Modify fpc.cfg
FPCCfg := IncludeTrailingPathDelimiter(FBinPath) + 'fpc.cfg';
InsertFPCCFGSnippet(FPCCfg,
SnipMagicBegin+FCrossCPU_target+'-'+FCrossOS_target+LineEnding+
'#cross compile settings dependent on both target OS and target CPU'+LineEnding+
'#IFDEF CPU'+uppercase(FCrossCPU_Target+LineEnding)+
'#IFDEF '+uppercase(FCrossOS_Target)+LineEnding+
'# Inserted by fpcup '+DateTimeToStr(Now)+LineEnding+
CrossInstaller.FPCCFGSnippet+LineEnding+
'#ENDIF'+LineEnding+
'#ENDIF'+LineEnding+
SnipMagicEnd);
end;
{$IFDEF UNIX}
result:=CreateFPCScript;
{$ENDIF UNIX}
GetCompiler;
end;
end;
end
end
else
begin
infoln('FPC: Can''t find cross installer for '+FCrossCPU_Target+'-'+FCrossOS_Target,etwarning);
result:=false;
end;
end;
constructor TFPCCrossInstaller.Create;
begin
inherited create;
end;
destructor TFPCCrossInstaller.Destroy;
begin
inherited Destroy;
end;
{ TFPCNativeInstaller }
function TFPCNativeInstaller.BuildModuleCustom(ModuleName: string): boolean;
var
OperationSucceeded:boolean;
FileCounter:integer;
begin
OperationSucceeded:=true;
// Make all/install, using bootstrap compiler.
// Make all should use generated compiler internally for unit compilation
{$IFDEF UNIX}
// the long way: make all, see where to install, install
FErrorLog.Clear;
ProcessEx.Executable := Make;
ProcessEx.CurrentDirectory:=ExcludeTrailingPathDelimiter(FBaseDirectory);
ProcessEx.Parameters.Clear;
if FCPUCount>1 then
ProcessEx.Parameters.Add('--jobs='+inttostr(FCPUCount)); // parallel processing
ProcessEx.Parameters.Add('FPC='+FCompiler);
ProcessEx.Parameters.Add('--directory='+ExcludeTrailingPathDelimiter(FBaseDirectory));
// Override makefile checks that checks for stable compiler in FPC trunk
if FBootstrapCompilerOverrideVersionCheck then
ProcessEx.Parameters.Add('OVERRIDEVERSIONCHECK=1');
if FCompilerOptions<>'' then
ProcessEx.Parameters.Add('OPT='+FCompilerOptions);
ProcessEx.Parameters.Add('all');
infoln('Running make all for FPC:',etInfo);
try
// At least on 2.7.1 we get access violations running fpc make
// perhaps this try..except isolates that
ProcessEx.Execute;
if ProcessEx.ExitStatus <> 0 then
begin
OperationSucceeded := False;
WritelnLog('FPC: Running fpc make all failed with exit code '+inttostr(ProcessEx.ExitStatus)+LineEnding+
'Details: '+FErrorLog.Text,true);
end;
except
on E: Exception do
begin
OperationSucceeded := False;
WritelnLog('FPC: Running fpc make all failed with an exception!'+LineEnding+
'Details: '+E.Message,true);
end;
end;
if OperationSucceeded then
begin
ProcessEx.Parameters.Clear;
FErrorLog.Clear;
ProcessEx.Parameters.Add('FPC='+FCompiler);
ProcessEx.Parameters.Add('--directory='+ExcludeTrailingPathDelimiter(FBaseDirectory));
ProcessEx.Parameters.Add('INSTALL_PREFIX='+ExcludeTrailingPathDelimiter(FBaseDirectory));
ProcessEx.Parameters.Add('INSTALL_BINDIR='+FBinPath);
ProcessEx.Parameters.Add('install');
infoln('Running make install for FPC:',etInfo);
try
// At least on 2.7.1 Windows we get access violations running fpc make
// perhaps this try..except isolates that
ProcessEx.Execute;
if ProcessEx.ExitStatus <> 0 then
begin
OperationSucceeded := False;
WritelnLog('FPC: Running fpc make install failed with exit code '+inttostr(ProcessEx.ExitStatus)+LineEnding+
'Details: '+FErrorLog.Text,true);
end;
except
on E: Exception do
begin
OperationSucceeded := False;
WritelnLog('FPC: Running fpc make install failed with an exception!'+LineEnding+
'Details: '+E.Message,true);
end;
end;
end;
{$ELSE UNIX} // Windows
ProcessEx.Executable := Make;
FErrorLog.Clear;
ProcessEx.CurrentDirectory:=ExcludeTrailingPathDelimiter(FBaseDirectory);
ProcessEx.Parameters.Clear;
{$IFNDEF windows}
{ todo: disabled because make 3.80 is unreliable with multiple jobs on Windows.
Re-enable when changed to make 3.82 }
if FCPUCount>1 then
ProcessEx.Parameters.Add('--jobs='+inttostr(FCPUCount)); // parallel processing
{$ENDIF}
ProcessEx.Parameters.Add('FPC='+FCompiler);
ProcessEx.Parameters.Add('--directory='+ExcludeTrailingPathDelimiter(FBaseDirectory));
ProcessEx.Parameters.Add('INSTALL_PREFIX='+ExcludeTrailingPathDelimiter(FBaseDirectory));
ProcessEx.Parameters.Add('UPXPROG=echo'); //Don't use UPX
ProcessEx.Parameters.Add('COPYTREE=echo'); //fix for examples in Win svn, see build FAQ
// Override makefile checks that checks for stable compiler in FPC trunk
if FBootstrapCompilerOverrideVersionCheck then
ProcessEx.Parameters.Add('OVERRIDEVERSIONCHECK=1');
if FCompilerOptions <>'' then
ProcessEx.Parameters.Add('OPT='+FCompilerOptions);
ProcessEx.Parameters.Add('all');
ProcessEx.Parameters.Add('install');
infoln('Running make all install for FPC:',etInfo);
try
// At least on 2.7.1 we get access violations running fpc make
// perhaps this try..except isolates that
ProcessEx.Execute;
if ProcessEx.ExitStatus <> 0 then
begin
OperationSucceeded := False;
WritelnLog('FPC: Running fpc make all install failed with exit code '+inttostr(ProcessEx.ExitStatus)+LineEnding+
'Details: '+FErrorLog.Text,true);
end;
except
on E: Exception do
begin
OperationSucceeded := False;
WritelnLog('FPC: Running fpc make all install failed with an exception!'+LineEnding+
'Details: '+E.Message,true);
end;
end;
{$ENDIF UNIX}
{$IFDEF UNIX}
if OperationSucceeded then
begin
if FVerbose then
infoln('Creating fpc script:',etInfo)
else
infoln('Creating fpc script:',etDebug);
OperationSucceeded:=CreateFPCScript;
end;
{$ENDIF UNIX}
// Let everyone know of our shiny new compiler:
if OperationSucceeded then
begin
GetCompiler;
// Verify it exists
if not(FileExistsUTF8(FCompiler)) then
begin
WritelnLog('FPC: error: could not find compiler '+FCompiler+' that should have been created.',true);
OperationSucceeded:=false;
end;
end
else
begin
infoln(ModuleName+': Error trying to compile FPC.',etDebug);
FCompiler:='////\\\Error trying to compile FPC\|!';
end;
{$IFDEF MSWINDOWS}
if OperationSucceeded then
begin
//Copy over binutils to new CompilerName bin directory
try
for FileCounter:=low(FUtilFiles) to high(FUtilFiles) do
begin
if FUtilFiles[FileCounter].Category=ucBinutil then
FileUtil.CopyFile(IncludeTrailingPathDelimiter(FMakeDir)+FUtilFiles[FileCounter].FileName,
IncludeTrailingPathDelimiter(FBinPath)+FUtilFiles[FileCounter].FileName);
end;
// Also, we can change the make/binutils path to our new environment
// Will modify fmake as well.
FMakeDir:=FBinPath;
except
on E: Exception do
begin
writelnlog('FPC: Error copying binutils: '+E.Message,true);
OperationSucceeded:=false;
end;
end;
end;
{$ENDIF MSWINDOWS}
result:=OperationSucceeded;
end;
constructor TFPCNativeInstaller.Create;
begin
inherited create;
end;
destructor TFPCNativeInstaller.Destroy;
begin
inherited Destroy;
end;
{ TFPCInstaller }
function TFPCInstaller.BuildModuleCustom(ModuleName: string): boolean;
begin
result:=true;
end;
function TFPCInstaller.GetCompilerVersion(CompilerPath: string): string;
var
Output: string;
ResultCode: longint;
begin
Output:='';
ResultCode:=ExecuteCommand(CompilerPath+ ' -iW', Output, FVerbose);
Output:=StringReplace(Output,LineEnding,'',[rfReplaceAll,rfIgnoreCase]);
Result:=Output;
end;
function TFPCInstaller.CreateFPCScript: boolean;
{$IFDEF UNIX}
var
FPCScript:string;
TxtFile:Text;
{$ENDIF UNIX}
begin
{$IFDEF UNIX}
// If needed, create fpc.sh, a launcher to fpc that ignores any existing system-wide fpc.cfgs (e.g. /etc/fpc.cfg)
// If this fails, Lazarus compilation will fail...
FPCScript := IncludeTrailingPathDelimiter(FBinPath) + 'fpc.sh';
if FileExists(FPCScript) then
begin
infoln('fpc.sh launcher script already exists ('+FPCScript+'); trying to overwrite it.',etInfo);
if not(sysutils.DeleteFile(FPCScript)) then
begin
infoln('Error deleting existing launcher script for FPC:'+FPCScript,eterror);
Exit(false);
end;
end;
AssignFile(TxtFile,FPCScript);
Rewrite(TxtFile);
writeln(TxtFile,'#!/bin/sh');
writeln(TxtFile,'# This script starts the fpc compiler installed by fpcup');
writeln(TxtFile,'# and ignores any system-wide fpc.cfg files');
writeln(TxtFile,'# Note: maintained by fpcup; do not edit directly, your edits will be lost.');
writeln(TxtFile,IncludeTrailingPathDelimiter(FBinPath),'fpc -n @',
IncludeTrailingPathDelimiter(FBinPath),'fpc.cfg '+
'"$@"');
CloseFile(TxtFile);
Result:=(FPChmod(FPCScript,&700)=0); //Make executable; fails if file doesn't exist=>Operationsucceeded update
if Result then
begin
infoln('Created launcher script for FPC:'+FPCScript,etInfo);
end
else
begin
infoln('Error creating launcher script for FPC:'+FPCScript,eterror);
end;
{$ENDIF UNIX}
end;
function TFPCInstaller.DownloadBootstrapCompiler: boolean;
// Should be done after we have unzip executable (on Windows: in FMakePath)
var
ArchiveDir: string;
BootstrapArchive: string;
CompilerName:string; // File name of compiler in bootstrap archive
ExtractedCompiler: string;
OperationSucceeded: boolean;
begin
OperationSucceeded:=true;
if OperationSucceeded then
begin
OperationSucceeded:=ForceDirectoriesUTF8(FBootstrapCompilerDirectory);
if OperationSucceeded=false then infoln('DownloadBootstrapCompiler error: could not create directory '+FBootstrapCompilerDirectory,eterror);
end;
BootstrapArchive := SysUtils.GetTempFileName;
if OperationSucceeded then
begin
OperationSucceeded:=Download(FBootstrapCompilerURL, BootstrapArchive);
if FileExists(BootstrapArchive)=false then OperationSucceeded:=false;
end;
if OperationSucceeded then
begin
{$IFDEF MSWINDOWS}
ArchiveDir := ExtractFilePath(BootstrapArchive);
CompilerName:=ExtractFileName(FBootstrapCompiler);
// Extract zip, overwriting without prompting
if ExecuteCommand(FUnzip+' -o -d '+ArchiveDir+' '+BootstrapArchive,FVerbose) <> 0 then
begin
infoln('Received non-zero exit code extracting bootstrap compiler. This will abort further processing.',eterror);
OperationSucceeded := False;
end
else
begin
OperationSucceeded := True; // Spelling it out can't hurt sometimes
end;
// Move CompilerName to proper directory
if OperationSucceeded = True then
begin
infoln('Going to rename/move ' + ArchiveDir + CompilerName + ' to ' + FBootstrapCompiler, etinfo);
renamefile(ArchiveDir + CompilerName, FBootstrapCompiler);
end;
{$ENDIF MSWINDOWS}
{$IFDEF LINUX}
// Extract bz2, overwriting without prompting
if ExecuteCommand(FBunzip2+' -d -f -q '+BootstrapArchive,FVerbose) <> 0 then
begin
infoln('Received non-zero exit code extracting bootstrap compiler. This will abort further processing.',eterror);
OperationSucceeded := False;
end
else
begin
ExtractedCompiler:=BootstrapArchive+'.out'; //default bzip2 output filename
OperationSucceeded := True; // Spelling it out can't hurt sometimes
end;
// Move compiler to proper directory; note bzip2 will append .out to file
if OperationSucceeded = True then
begin
infoln('Going to move ' + ExtractedCompiler + ' to ' + FBootstrapCompiler,etInfo);
OperationSucceeded:=MoveFile(ExtractedCompiler,FBootstrapCompiler);
end;
if OperationSucceeded then
begin
// Make executable
OperationSucceeded:=(fpChmod(FBootStrapCompiler, &700)=0); //rwx------
if OperationSucceeded=false then infoln('Bootstrap compiler: chmod failed for '+FBootstrapCompiler,etwarning);
end;
{$ENDIF LINUX}
{$IFDEF BSD} //*BSD, OSX
{$IF defined(FREEBSD) or defined(NETBSD) or defined(OPENBSD)}
//todo: test parameters
//Extract bz2, overwriting without prompting
if ExecuteCommand(FBunzip2+' -d -f -q '+BootstrapArchive,FVerbose) <> 0 then
begin
infoln('Received non-zero exit code extracting bootstrap compiler. This will abort further processing.',eterror);
OperationSucceeded := False;
end
else
begin
ExtractedCompiler:=BootstrapArchive+'.out'; //default bzip2 output filename
OperationSucceeded := True; // Spelling it out can't hurt sometimes
end;
// Move compiler to proper directory; note bzip2 will append .out to file
if OperationSucceeded = True then
begin
infoln('Going to move ' + ExtractedCompiler + ' to ' + FBootstrapCompiler,etInfo);
OperationSucceeded:=MoveFile(ExtractedCompiler,FBootstrapCompiler);
end;
if OperationSucceeded then
begin
// Make executable
OperationSucceeded:=(fpChmod(FBootStrapCompiler, &700)=0); //rwx------
if OperationSucceeded=false then infoln('Bootstrap compiler: chmod failed for '+FBootstrapCompiler,etwarning);
end;
{$ENDIF defined(FREEBSD) or defined(NETBSD) or defined(OPENBSD)}
{$IFDEF DARWIN}
// Extract .tar.bz2, overwriting without prompting
CompilerName:=ExtractFileName(FBootstrapCompiler);
// GNU tar: -x -v -j -f
// BSD tar:
if ExecuteCommand(FTar+' -xf '+BootstrapArchive,FVerbose) <> 0 then
begin
infoln('Received non-zero exit code extracting bootstrap compiler. This will abort further processing.',eterror);
OperationSucceeded := False;
end
else
begin
OperationSucceeded := True; // Spelling it out can't hurt sometimes
end;
// Move compiler to proper directory; note bzip2 will append .out to file
if OperationSucceeded = True then
begin
// todo: currently tar spits out uncompressed file in current dir...
// which might not have proper permissions to actually create file...!?
infoln('Going to rename/move '+CompilerName+' to '+FBootStrapCompiler,etwarning);
sysutils.DeleteFile(FBootStrapCompiler); //ignore errors
// We might be moving files across partitions so we cannot use renamefile
OperationSucceeded:=FileUtil.CopyFile(CompilerName, FBootStrapCompiler);
sysutils.DeleteFile(CompilerName);
end;
if OperationSucceeded then
begin
// Make executable
OperationSucceeded:=(fpChmod(FBootStrapCompiler, &700)=0); //rwx------
if OperationSucceeded=false then infoln('Bootstrap compiler: chmod failed for '+FBootStrapCompiler,eterror);
end;
{$ENDIF DARWIN}
{$ENDIF BSD}
end;
if OperationSucceeded = True then
begin
SysUtils.DeleteFile(BootstrapArchive);
end
else
begin
infoln('Error getting/extracting bootstrap compiler. Archive: '+BootstrapArchive, eterror);
end;
Result := OperationSucceeded;
end;
function TFPCInstaller.GetFPCVersion: string;
var testcompiler:string;
begin
testcompiler:=IncludeTrailingPathDelimiter(FBaseDirectory)+'compiler'+DirectorySeparator+'ppc1';
if not FileExistsUTF8(testcompiler) then
begin //darwin
testcompiler:=IncludeTrailingPathDelimiter(FBaseDirectory)+'compiler'+DirectorySeparator+'ppc';
end;
ExecuteCommand(testcompiler+' -iV',result,FVerbose);
//Remove trailing LF(s) and other control codes:
while (length(result)>0) and (ord(result[length(result)])<$20) do
delete(result,length(result),1);
end;
function TFPCInstaller.InitModule:boolean;
const
// Common path used to get bootstrap compilers.
//todo: replace when enough compilers are available via 2.6.2
FTPPath='ftp.freepascal.org/pub/fpc/dist/2.6.0/bootstrap/';
FTP262Path='ftp.freepascal.org/pub/fpc/dist/2.6.2/bootstrap/';
FTP264Path='ftp.freepascal.org/pub/fpc/dist/2.6.4/bootstrap/';
var
BootstrapVersion: string;
Output: string;
begin
result:=true;
if InitDone then
exit;
if FVerbose then
ProcessEx.OnOutputM:=@DumpOutput;
infoln('TFPCInstaller: initialising...',etDebug);
if FBootstrapCompiler='' then
begin // may need to download it
// We assume we're using the regular latest stable compiler, so don't
// suggest to make to override version checks.
// Useful if we forget to update compiler versions when a new stable is released.
FBootstrapCompilerOverrideVersionCheck:=false;
{$IFDEF MSWINDOWS}
{$ifdef win64}
if Win64FallBackUsingCrossCompiler then
begin
// There is no win64 bootstrap compiler, yet
// Each time we build, we'll make our own starting with the ppc386.exe bootstrap compiler
// This should eliminate issues with the wrong RTL etc (for trunk, only the exact same svn revision is supported)
if FBootstrapCompilerURL='' then
FBootstrapCompilerURL := FTP262Path+'i386-win32-ppc386.zip';
FBootstrapCompiler := IncludeTrailingPathDelimiter(FBootstrapCompilerDirectory)+'ppc386.exe';
FBootstrapCompilerOverrideVersionCheck:=true;
end
else
begin
// Use regular x64 stable compiler
if FBootstrapCompilerURL='' then
FBootstrapCompilerURL := FTP262Path+'x86_64-win64-ppcx64.zip';
FBootstrapCompiler := IncludeTrailingPathDelimiter(FBootstrapCompilerDirectory)+'ppcx64.exe';
end;
{$ELSE}
// Win32
if FBootstrapCompilerURL='' then
FBootstrapCompilerURL := FTP262Path+'i386-win32-ppc386.zip';
FBootstrapCompiler := IncludeTrailingPathDelimiter(FBootstrapCompilerDirectory)+'ppc386.exe';
{$endif win64}
{$ENDIF MSWINDOWS}
{$IFDEF Linux}
//If compiled for x86 32 bit, install 32 bit
//If compiled for x64, install x64 only.
{$IFDEF CPU386}
if FBootstrapCompilerURL='' then
FBootstrapCompilerURL := FTP262Path+'i386-linux-ppc386.bz2';
FBootstrapCompiler := IncludeTrailingPathDelimiter(FBootstrapCompilerDirectory)+'i386-linux-ppc386-1';
{$ELSE}
{$IFDEF cpuarmel} //probably the 2.6.x name for arm
if FBootstrapCompilerURL='' then
FBootstrapCompilerURL := FTP262Path+'arm-linux-ppcarm.bz2';
FBootstrapCompiler := IncludeTrailingPathDelimiter(FBootstrapCompilerDirectory)+'arm-linux-ppcarm';
{$ENDIF cpuarmel}
{$IFDEF cpuarm} //includes armel on FPC 2.7.1
if FBootstrapCompilerURL='' then
FBootstrapCompilerURL := FTP262Path+'arm-linux-ppcarm.bz2';
FBootstrapCompiler := IncludeTrailingPathDelimiter(FBootstrapCompilerDirectory)+'arm-linux-ppcarm';
{$ELSE} // Assume x64 (could also be PowerPC, SPARC I suppose)
infoln('TFPCInstaller: bootstrap compiler detection: assuming this is a x64 processor on Linux',etWarning);
if FBootstrapCompilerURL='' then
FBootstrapCompilerURL := FTP262Path+'x86_64-linux-ppcx64.bz2';
FBootstrapCompiler := IncludeTrailingPathDelimiter(FBootstrapCompilerDirectory)+'x86_64-linux-ppcx64';
{$ENDIF cpuarm}
{$ENDIF CPU386}
{$ENDIF Linux}
{$IFDEF Darwin}
//OSX
//ppcuniversal is not a good bootstrap compiler since it creates a compiler that doesn't handle generics !?!?!?
//We'll make our own ppc386 starting with the ppcuniversal bootstrap compiler
//If we made it already pick it up here
FBootstrapCompiler := IncludeTrailingPathDelimiter(FBootstrapCompilerDirectory)+'ppc386';
if FBootstrapCompilerURL='' then
FBootstrapCompilerURL := FTP264Path+'universal-macosx-10.5-ppcuniversal.tar.bz2';
// If we're using an old compiler to build trunk, we need this:
FBootstrapCompilerOverrideVersionCheck:=true;
{$ENDIF Darwin}
{$IFDEF FREEBSD}
{$IFDEF CPU386}
// Assuming user has FreeBSD 9...
if FBootstrapCompilerURL='' then
FBootstrapCompilerURL := FTP264Path+'i386-freebsd9-ppc386.bz2';
FBootstrapCompiler := IncludeTrailingPathDelimiter(FBootstrapCompilerDirectory)+'i386-freebsd9-ppc386';
{$ENDIF CPU386}
{$IFDEF CPUX86_64}
// Assuming user has FreeBSD 9...
if FBootstrapCompilerURL='' then
FBootstrapCompilerURL := FTP264Path+'x86_64-freebsd9-ppcx64.bz2';
FBootstrapCompiler := IncludeTrailingPathDelimiter(FBootstrapCompilerDirectory)+'x86_64-freebsd9.ppcx64';
{$ENDIF CPUX86_64}
{$ENDIF FREEBSD}
{$IFDEF NETBSD}
{$IFDEF CPU386}