-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathinstallerlazarus.pas
executable file
·2733 lines (2429 loc) · 105 KB
/
installerlazarus.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 installerLazarus;
{ Lazarus/LCL installer/updater module
Copyright (C) 2012-2014 Reinier Olislagers, Ludo Brands
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, strutils;
//todo: use processex callback to report on errors like it's done in installerfpc
const
Sequences =
//standard lazarus build
_DECLARE+_LAZARUS+_SEP +
_EXECUTE+_CHECKDEVLIBS+_SEP+
_CLEANMODULE+_LAZARUS+_SEP +
_CHECKMODULE+_LAZARUS+_SEP +
_GETMODULE+_LAZARUS+_SEP +
_CONFIGMODULE+_LAZARUS+_SEP +
_DO+_USERIDE+_SEP +
_BUILDMODULE+_STARTLAZARUS+_SEP +
_DO+_UNIVERSALDEFAULT+_SEP+
_DO+_HELPLAZARUS+_SEP+
_BUILDMODULE+_INSTALLLAZARUS+_SEP +
_EXECUTE+_CREATELAZARUSSCRIPT+_SEP +
_END +
_DECLARE+_LAZARUSSIMPLE+_SEP +
_EXECUTE+_CHECKDEVLIBS+_SEP+
_CLEANMODULE+_LAZARUS+_SEP +
_CHECKMODULE+_LAZARUS+_SEP +
_GETMODULE+_LAZARUS+_SEP +
_CONFIGMODULE+_LAZARUS+_SEP +
_BUILDMODULE+_LAZARUS+_SEP +
_BUILDMODULE+_STARTLAZARUS+_SEP +
_BUILDMODULE+_INSTALLLAZARUS+_SEP +
_EXECUTE+_CREATELAZARUSSCRIPT+_SEP +
_END +
//standard clean
_DECLARE+_LAZARUS+_CLEAN+_SEP+
_CLEANMODULE+_LAZARUS+_SEP +
_END +
//standard uninstall
_DECLARE+_LAZARUS+_UNINSTALL+_SEP+
//_CLEANMODULE+_LAZARUS+_SEP+
_UNINSTALLMODULE+_LAZARUS+_SEP +
_EXECUTE+_DELETELAZARUSSCRIPT+_SEP +
_END +
//selective actions triggered with --only=SequenceName
_DECLARE+_LAZARUS+_CHECK+_ONLY+_SEP + _CHECKMODULE+_LAZARUS+_SEP + _END +
_DECLARE+_LAZARUS+_CLEAN+_ONLY+_SEP + _CLEANMODULE+_LAZARUS+_SEP + _END +
_DECLARE+_LAZARUS+_GET+_ONLY+_SEP + _GETMODULE+_LAZARUS+_SEP + _END +
_DECLARE+_LAZARUS+_BUILD+_ONLY+_SEP + _BUILDMODULE+_LAZARUS+_SEP + _END +
_DECLARE+_LAZARUS+_CONFIG+_ONLY+_SEP + _CONFIGMODULE+_LAZARUS+_SEP + _END +
_DECLARE+_LAZARUSCLEANBUILDONLY+_SEP +
_CLEANMODULE+_LAZARUS+_SEP +
_CONFIGMODULE+_LAZARUS+_SEP +
_DO+_USERIDE+_SEP +
_BUILDMODULE+_STARTLAZARUS+_SEP +
_DO+_UNIVERSALDEFAULT+_SEP+
_EXECUTE+_CREATELAZARUSSCRIPT+_SEP +
_END +
_DECLARE+_LAZARUSREMOVEONLY+_SEP +
_CLEANMODULE+_LAZARUS+_SEP +
_CONFIGMODULE+_LAZARUS+_SEP +
//_UNINSTALLMODULE+_LAZARUS+_SEP +
_END +
// Compile only LCL
_DECLARE+_LCL+_SEP +
_CLEANMODULE+_LCL+_SEP +
_BUILDMODULE+_LCL+_SEP +
_END +
// Clean (remove only LCL
_DECLARE+_LCLREMOVEONLY+_SEP +
_CLEANMODULE+_LCL+_SEP +
_UNINSTALLMODULE+_LCL+_SEP +
_END +
// Clean (remove only components)
_DECLARE+_COMPONENTSREMOVEONLY+_SEP +
_CLEANMODULE+_COMPONENTS+_SEP +
_UNINSTALLMODULE+_COMPONENTS+_SEP +
_END +
// Clean (remove only packager)
_DECLARE+_PACKAGERREMOVEONLY+_SEP +
_CLEANMODULE+_PACKAGER+_SEP +
_UNINSTALLMODULE+_PACKAGER+_SEP +
_END +
_DECLARE+_LCLALLREMOVEONLY+_SEP +
_DO+_LCLREMOVEONLY+_SEP +
_DO+_COMPONENTSREMOVEONLY+_SEP +
_DO+_PACKAGERREMOVEONLY+_SEP +
_END +
//standard lazbuild build
_DECLARE+_LAZBUILD+_SEP +
_BUILDMODULE+_LAZBUILD+_SEP +
_END +
//special lazbuild standalone build (for docker use)
_DECLARE+_LAZBUILD+_ONLY+_SEP +
_CLEANMODULE+_LAZBUILD+_SEP +
_CHECKMODULE+_LAZBUILD+_SEP +
_GETMODULE+_LAZBUILD+_SEP +
_CONFIGMODULE+_LAZBUILD+_SEP +
_BUILDMODULE+_LAZBUILD+_SEP +
_END +
//standard useride build
_DECLARE+_USERIDE+_SEP +
_BUILDMODULE+_LAZBUILD+_SEP +
_BUILDMODULE+_USERIDE+_SEP +
_END +
{$ifdef mswindows}
{$ifdef win32}
// Crosscompile build
_DECLARE+_LAZARUS+_CROSSWIN+_SEP +
_SETCPU+'x86_64'+_SEP + _SETOS+'win64'+_SEP +
_DO+_LCL+_SEP+
_SETCPU+'i386'+_SEP+ _SETOS+'win32'+_SEP+
_END +
{$endif}
{$ifdef win64}
_DECLARE+_LAZARUS+_CROSSWIN+_SEP +
_SETCPU+'i386'+_SEP+ _SETOS+'win32'+_SEP+
_DO+_LCL+_SEP+
_SETCPU+'x86_64'+_SEP + _SETOS+'win64'+_SEP +
_END +
{$endif}
{$endif mswindows}
// Crosscompile only LCL native widgetset (needs to be run at end)
_DECLARE+_LCLCROSS+_SEP +
_RESETLCL+_SEP + //module code itself will select proper widgetset
_CLEANMODULE+_LCLCROSS+_SEP+
_BUILDMODULE+_LCLCROSS+_SEP +
_END+
_DECLARE+_CONFIG+_LAZARUS+_SEP +
_CONFIGMODULE+_LAZARUS+_SEP +
_END +
_DECLARE+_MAKEFILECHECKLAZARUS+_SEP+
_BUILDMODULE+_MAKEFILECHECKLAZARUS+_SEP+
_ENDFINAL;
DEFAULTLPI =
'<?xml version="1.0" encoding="UTF-8"?>'+LineEnding+
'<CONFIG>'+LineEnding+
' <ProjectOptions>'+LineEnding+
' <General>'+LineEnding+
' <SessionStorage Value="InProjectDir"/>'+LineEnding+
' <MainUnit Value="0"/>'+LineEnding+
' <Title Value="project1"/>'+LineEnding+
' </General>'+LineEnding+
' <BuildModes Count="1">'+LineEnding+
' <Item1 Name="Default" Default="True"/>'+LineEnding+
' </BuildModes>'+LineEnding+
' <Units Count="1">'+LineEnding+
' <Unit0>'+LineEnding+
' <Filename Value="project1.lpr"/>'+LineEnding+
' <IsPartOfProject Value="True"/>'+LineEnding+
' </Unit0>'+LineEnding+
' </Units>'+LineEnding+
' </ProjectOptions>'+LineEnding+
'</CONFIG>';
DEFAULTLPR =
'program project1;'+LineEnding+
''+LineEnding+
'begin'+LineEnding+
' writeln(''Hello world from fpcupdeluxe !'');'+LineEnding+
'end.';
LAZARUSCFG = 'lazarus.cfg'; //file to store primary config argument in
type
{ TLazarusInstaller }
TLazarusInstaller = class(TBaseLazarusInstaller)
private
FLCL_Platform: string;
FPrimaryConfigPath: string;
InitDone: boolean;
function LCLCrossActionNeeded:boolean;
protected
function GetVersionFromSource(aSourcePath:string):string;override;
function GetVersionFromUrl(aUrl:string):string;override;
function GetReleaseCandidateFromSource(aSourcePath:string):integer;override;
// Build module descendant customisation
function BuildModuleCustom(ModuleName: string): boolean; virtual;
function GetLazarusVersion: string;
// internal initialisation, called from BuildModule,CleanModule,GetModule
// and UnInstallModule but executed only once
function InitModule: boolean;
public
// LCL widget set to be built (NOT OS/CPU combination)
property LCL_Platform: string write FLCL_Platform;
// Lazarus primary config path
property PrimaryConfigPath: string write FPrimaryConfigPath;
// Build module
function BuildModule(ModuleName: string): boolean; override;
// Create configuration in PrimaryConfigPath
function ConfigModule(ModuleName: string): boolean; override;
// Clean up environment
function CleanModule(ModuleName: string): boolean; override;
// Install update sources, Qt bindings if needed
function GetModule(ModuleName: string): boolean; override;
// Perform some checks on the sources
function CheckModule(ModuleName: string): boolean; override;
// Uninstall module
function UnInstallModule(ModuleName: string): boolean; override;
constructor Create;
destructor Destroy; override;
end;
{ TLazarusNativeInstaller }
TLazarusNativeInstaller = class(TLazarusInstaller)
protected
// Build module descendant customisation
function BuildModuleCustom(ModuleName: string): boolean; override;
public
constructor Create;
destructor Destroy; override;
end;
{ TLazarusCrossInstaller }
TLazarusCrossInstaller = class(TLazarusInstaller)
protected
// Build module descendant customisation
function BuildModuleCustom(ModuleName: string): boolean; override;
public
function UnInstallModule(ModuleName:string): boolean; override;
constructor Create;
destructor Destroy; override;
end;
implementation
uses
{$ifdef Unix}
BaseUnix,
{$ifdef LCLQT5}
LazFileUtils,
{$endif}
{$endif}
FileUtil,
fpcuputil,
repoclient,
updatelazconfig;
{ TLazarusCrossInstaller }
function TLazarusCrossInstaller.BuildModuleCustom(ModuleName: string): boolean;
var
Options: string;
LazBuildApp: string;
{$ifdef MSWindows}
OldPath:string;
s:string;
{$endif}
begin
Result:=inherited;
FErrorLog.Clear;
if Assigned(CrossInstaller) then
begin
//No need to Reset
//Just use the values as available
//CrossInstaller.Reset;
// Actually not using crossopts - they're only for building an FPC compiler; the
// relevant options should have been written as a snippet to fpc.cfg and picked
// up from there.
CrossInstaller.SetFPCVersion(CompilerVersion(FCompiler));
CrossInstaller.SetCrossOpt(CrossOPT); //pass on user-requested cross compile options
CrossInstaller.SetSubArch(CrossOS_SubArch);
CrossInstaller.SetABI(CrossOS_ABI);
if not CrossInstaller.GetBinUtils(FBaseDirectory) then
Infoln(infotext+'Failed to get crossbinutils', etError)
else if not CrossInstaller.GetLibs(FBaseDirectory) then
Infoln(infotext+'Failed to get cross libraries', etError)
else if not CrossInstaller.GetLibsLCL(FLCL_Platform, FBaseDirectory) then
Infoln(infotext+'Failed to get LCL cross libraries', etError)
else
// Cross compiling prerequisites in place. Let's compile.
begin
// If we're "crosscompiling" with the native compiler and binutils - "cross compiling [lite]" - use lazbuild.
// Advantages:
// - dependencies are taken care of
// - it won't trigger a rebuild of the LCL when the user compiles his first cross project.
// Otherwise, use make; advantages:
// - can deal with various bin tools
// - can deal with compiler options
// - doesn't need existing lazbuild (+nogui LCL)
LazBuildApp := IncludeTrailingPathDelimiter(FInstallDirectory) + LAZBUILDNAME + GetExeExt;
if CheckExecutable(LazBuildApp, ['--help'], LAZBUILDNAME) = false then
begin
WritelnLog(etWarning, infotext+'Lazbuild could not be found ... using make to cross-build '+ModuleName, true);
LazBuildApp := '';
end;
// Since April 2012, LCL requires lazutils which requires registration
// https://wiki.lazarus.freepascal.org/Getting_Lazarus#Make_targets
//https://lists.lazarus-ide.org/pipermail/lazarus/2012-April/138168.html
if Length(LazBuildApp)=0 then
begin
// Use make for cross compiling
// Check unwanted forced update through ViaMakefile and .compiled
Processor.Executable := Make;
Processor.Process.Parameters.Clear;
{$IFDEF MSWINDOWS}
if Length(Shell)>0 then Processor.Process.Parameters.Add('SHELL='+Shell);
{$ENDIF}
Processor.Process.CurrentDirectory := ExcludeTrailingPathDelimiter(FSourceDirectory);
Processor.Process.Parameters.Add('--directory='+Processor.Process.CurrentDirectory);
{$IF DEFINED(CPUARM) AND DEFINED(LINUX)}
Processor.Process.Parameters.Add('--jobs=1');
{$ELSE}
//Still not clear if jobs can be enabled for Lazarus make builds ... :-|
//if (NOT FNoJobs) then
// Processor.Process.Parameters.Add('--jobs='+IntToStr(FCPUCount));
{$ENDIF}
Processor.Process.Parameters.Add('FPC=' + FCompiler);
Processor.Process.Parameters.Add('PP=' + ExtractFilePath(FCompiler)+GetCompilerName(GetTargetCPU));
Processor.Process.Parameters.Add('USESVN2REVISIONINC=0');
Processor.Process.Parameters.Add('PREFIX='+ExcludeTrailingPathDelimiter(FInstallDirectory));
Processor.Process.Parameters.Add('INSTALL_PREFIX='+ExcludeTrailingPathDelimiter(FInstallDirectory));
Processor.Process.Parameters.Add('LAZARUS_INSTALL_DIR='+IncludeTrailingPathDelimiter(FInstallDirectory));
//Make sure our FPC units can be found by Lazarus
Processor.Process.Parameters.Add('FPCDIR=' + ExcludeTrailingPathDelimiter(FFPCSourceDir));
//Make sure Lazarus does not pick up these tools from other installs
Processor.Process.Parameters.Add('FPCMAKE=' + FFPCCompilerBinPath+'fpcmake'+GetExeExt);
Processor.Process.Parameters.Add('PPUMOVE=' + FFPCCompilerBinPath+'ppumove'+GetExeExt);
{$ifdef Windows}
Processor.Process.Parameters.Add('UPXPROG=echo'); //Don't use UPX
{$else}
//Processor.Process.Parameters.Add('INSTALL_BINDIR='+FBinPath);
{$endif}
Processor.Process.Parameters.Add('OS_SOURCE=' + GetTargetOS);
Processor.Process.Parameters.Add('CPU_SOURCE=' + GetTargetCPU);
Processor.Process.Parameters.Add('OS_TARGET=' + CrossInstaller.TargetOSName);
Processor.Process.Parameters.Add('CPU_TARGET=' + CrossInstaller.TargetCPUName);
//Prevents the Makefile to search for the (native) ppc compiler which is used to do the latest build
//Todo: to be investigated
//Processor.Process.Parameters.Add('FPCFPMAKE=' + ExtractFilePath(FCompiler)+GetCompilerName(GetTargetCPU));
//Set standard options
Options := STANDARDCOMPILERVERBOSITYOPTIONS;
//Always limit the search for fpc.cfg to our own fpc.cfg
//Only needed on Windows. On Linux, we have already our own fpc.sh
{$ifdef Windows}
Options := Options+' -n @'+FFPCCompilerBinPath+'fpc.cfg';
{$endif}
// Add remaining options
Options := Options+' '+FCompilerOptions;
while Pos(' ',Options)>0 do
begin
Options:=StringReplace(Options,' ',' ',[rfReplaceAll]);
end;
Options:=Trim(Options);
if Length(Options)>0 then Processor.Process.Parameters.Add('OPT='+Options);
if FLCL_Platform <> '' then
Processor.Process.Parameters.Add('LCL_PLATFORM=' + FLCL_Platform);
//Processor.Process.Parameters.Add('all');
Processor.Process.Parameters.Add('registration');
Processor.Process.Parameters.Add('lazutils');
Processor.Process.Parameters.Add('lcl');
Processor.Process.Parameters.Add('basecomponents');
end
else
begin
// Use lazbuild for cross compiling
Processor.Executable := LazBuildApp;
Processor.Process.CurrentDirectory := ExcludeTrailingPathDelimiter(FSourceDirectory);
Processor.Process.Parameters.Clear;
{$IFDEF DEBUG}
Processor.Process.Parameters.Add('--verbose');
{$ELSE}
// See compileroptions.pp
// Quiet:=ConsoleVerbosity<=-3;
Processor.Process.Parameters.Add('--quiet');
{$ENDIF}
Processor.Process.Parameters.Add('--pcp=' + DoubleQuoteIfNeeded(FPrimaryConfigPath));
// Apparently, the .compiled file, that are used to check for a rebuild, do not contain a cpu setting if cpu and cross-cpu do not differ !!
// So, use this test to prevent a rebuild !!!
if (GetTargetCPU<>CrossInstaller.TargetCPUName) then
Processor.Process.Parameters.Add('--cpu=' + CrossInstaller.TargetCPUName);
// See above: the same for OS !
if (GetTargetOS<>CrossInstaller.TargetOSName) then
Processor.Process.Parameters.Add('--os=' + CrossInstaller.TargetOSName);
if FLCL_Platform <> '' then
Processor.Process.Parameters.Add('--ws=' + FLCL_Platform);
Processor.Process.Parameters.Add(ConcatPaths([{$IF DEFINED(FPC_FULLVERSION) AND (FPC_FULLVERSION < 30200)}UnicodeString{$ENDIF}('packager'),'registration'])+DirectorySeparator+'fcl.lpk');
Processor.Process.Parameters.Add(ConcatPaths([{$IF DEFINED(FPC_FULLVERSION) AND (FPC_FULLVERSION < 30200)}UnicodeString{$ENDIF}('components'),'lazutils'])+DirectorySeparator+'lazutils.lpk');
Processor.Process.Parameters.Add(ConcatPaths([{$IF DEFINED(FPC_FULLVERSION) AND (FPC_FULLVERSION < 30200)}UnicodeString{$ENDIF}('lcl'),'interfaces'])+DirectorySeparator+'lcl.lpk');
// Also add the basecomponents !
Processor.Process.Parameters.Add(ConcatPaths([{$IF DEFINED(FPC_FULLVERSION) AND (FPC_FULLVERSION < 30200)}UnicodeString{$ENDIF}('components'),'synedit'])+DirectorySeparator+'synedit.lpk');
Processor.Process.Parameters.Add(ConcatPaths([{$IF DEFINED(FPC_FULLVERSION) AND (FPC_FULLVERSION < 30200)}UnicodeString{$ENDIF}('components'),'lazcontrols'])+DirectorySeparator+'lazcontrols.lpk');
Processor.Process.Parameters.Add(ConcatPaths([{$IF DEFINED(FPC_FULLVERSION) AND (FPC_FULLVERSION < 30200)}UnicodeString{$ENDIF}('components'),'ideintf'])+DirectorySeparator+'ideintf.lpk');
end;
if FLCL_Platform = '' then
Infoln(infotext+'Compiling LCL for ' + GetFPCTarget(false) + ' using ' + ExtractFileName(Processor.Executable), etInfo)
else
Infoln(infotext+'Compiling LCL for ' + GetFPCTarget(false) + '/' + FLCL_Platform + ' using ' + ExtractFileName(Processor.Executable), etInfo);
try
{$ifdef MSWindows}
//Prepend FPC binary directory to PATH to prevent pickup of strange tools
OldPath:=Processor.Environment.GetVar(PATHVARNAME);
s:=ExcludeTrailingPathDelimiter(FFPCCompilerBinPath);
if OldPath<>'' then
Processor.Environment.SetVar(PATHVARNAME, s+PathSeparator+OldPath)
else
Processor.Environment.SetVar(PATHVARNAME, s);
{$endif}
ProcessorResult:=Processor.ExecuteAndWait;
Result := (ProcessorResult = 0);
if (not Result) then
WritelnLog(etError,infotext+'Error compiling LCL for ' + GetFPCTarget(false) + ' ' + FLCL_Platform + LineEnding +
'Details: ' + FErrorLog.Text, true);
{$ifdef MSWindows}
Processor.Environment.SetVar(PATHVARNAME, OldPath);
{$endif}
except
on E: Exception do
begin
Result := false;
WritelnLog(etError,infotext+'Exception compiling LCL for ' + GetFPCTarget(false) + LineEnding +
'Details: ' + E.Message, true);
end;
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=TCPU.x86_64) and ((CrossInstaller.TargetOS=TOS.win64) or (CrossInstaller.TargetOS=TOS.win32)) then
Result := true;
{$endif win32}
{$ifdef win64}
// if this is crosswin64-32, ignore error as it is optional
if (CrossInstaller.TargetCPU=TCPU.i386) and (CrossInstaller.TargetOS=TOS.win32) then
Result := true;
{$endif win64}
if Result then
Infoln(infotext+'Cross compiling LCL for ' + GetFPCTarget(false) +
' failed. Optional module; continuing regardless.', etWarning)
else
Infoln(infotext+'Cross compiling LCL for ' + GetFPCTarget(false) + ' failed.', etError);
// No use in going on, but
// do make sure installation continues if this happened with optional crosscompiler:
exit(Result);
end;
end; //prereqs in place
end //valid cross compile setup
else
Infoln(infotext+'Can''t find cross installer for ' + GetFPCTarget(false), etError);
end;
function TLazarusCrossInstaller.UnInstallModule(ModuleName:string): boolean;
var
aDir:string;
begin
result:=true; //succeed by default
if not DirectoryExists(FInstallDirectory) then
begin
Infoln(infotext+'No Lazarus install [yet] ... nothing to be done',etInfo);
end;
if CheckDirectory(FInstallDirectory) then exit;
Result := InitModule;
if not Result then exit;
FErrorLog.Clear;
//if (NOT CrossCompilerPresent) then exit;
if assigned(CrossInstaller) AND (Length(FBaseDirectory)>0) AND (NOT CheckDirectory(FBaseDirectory)) then
begin
if ((CrossInstaller.TargetCPU=TCPU.cpuNone) OR (CrossInstaller.TargetOS=TOS.osNone)) then exit;
CrossInstaller.Reset;
CrossInstaller.SetFPCVersion(CompilerVersion(FCompiler));
case ModuleName of
_LCL:
begin
aDir:=IncludeTrailingPathDelimiter(FInstallDirectory)+'lcl'+DirectorySeparator+'units'+DirectorySeparator+GetFPCTarget(false);
if DirectoryExists(aDir) then if DeleteDirectoryEx(aDir)=false then
begin
WritelnLog(infotext+'Error deleting '+ModuleName+' directory '+aDir);
end;
end;
_PACKAGER:
begin
aDir:=IncludeTrailingPathDelimiter(FInstallDirectory)+'packager'+DirectorySeparator+'units'+DirectorySeparator+GetFPCTarget(false);
if DirectoryExists(aDir) then if DeleteDirectoryEx(aDir)=false then
begin
WritelnLog(infotext+'Error deleting '+ModuleName+' directory '+aDir);
end;
end;
_COMPONENTS:
begin
aDir:=IncludeTrailingPathDelimiter(FInstallDirectory)+'components'+DirectorySeparator+'lazutils'+DirectorySeparator+'lib'+DirectorySeparator+GetFPCTarget(false);
if DirectoryExists(aDir) then if DeleteDirectoryEx(aDir)=false then
begin
WritelnLog(infotext+'Error deleting '+ModuleName+' directory '+aDir);
end;
end;
_LCLCROSS:
begin
end;
end;
end;
end;
constructor TLazarusCrossInstaller.Create;
begin
inherited Create;
end;
destructor TLazarusCrossInstaller.Destroy;
begin
inherited Destroy;
end;
{ TLazarusNativeInstaller }
function TLazarusNativeInstaller.BuildModuleCustom(ModuleName: string): boolean;
var
i,j,ExitCode: integer;
s,s2,LazBuildApp,FPCDirStore: string;
{$ifdef MSWindows}
OldPath:string;
{$endif}
OperationSucceeded: boolean;
LazarusConfig: TUpdateLazConfig;
IDEConfig:TStringList;
begin
Result:=inherited;
OperationSucceeded := true;
//Get Freetype and Zlib for ao fpreport ... just to be sure
{$IFDEF MSWINDOWS}
//DownloadFreetype;
//DownloadZlib;
{$ENDIF}
LazBuildApp := IncludeTrailingPathDelimiter(FInstallDirectory) + LAZBUILDNAME + GetExeExt;
if (ModuleName=_LAZARUS) OR (ModuleName=_LAZBUILD) then
begin
if (Length(ActualRevision)=0) OR (ActualRevision='failure') then
begin
s2:=GetRevision(ModuleName);
if Length(s2)>0 then FActualRevision:=s2;
end;
if (ModuleName=_LAZARUS) then Infoln(infotext+'Now building '+ModuleName+' revision '+ActualRevision,etInfo);
end;
//Note: available in more recent Lazarus : use "make lazbuild useride" to build ide with installed packages
{$ifdef FORCELAZBUILD}
if (ModuleName<>_USERIDE) then
{$else}
if ((ModuleName<>_USERIDE) OR (SourceVersionNum>=CalculateFullVersion(1,6,2))) then
{$endif}
begin
// Make all (should include lcl & ide), lazbuild, lcl etc
// distclean was already run; otherwise specify make clean all
FErrorLog.Clear;
Processor.Executable := Make;
Processor.Process.Parameters.Clear;
{$IFDEF MSWINDOWS}
if Length(Shell)>0 then Processor.Process.Parameters.Add('SHELL='+Shell);
{$ENDIF}
Processor.Process.CurrentDirectory := ExcludeTrailingPathDelimiter(FSourceDirectory);
Processor.Process.Parameters.Add('--directory='+Processor.Process.CurrentDirectory);
{$IF DEFINED(CPUARM) AND DEFINED(LINUX)}
Processor.Process.Parameters.Add('--jobs=1');
{$ELSE}
//Still not clear if jobs can be enabled for Lazarus make builds ... :-|
//if (NOT FNoJobs) then
// Processor.Process.Parameters.Add('--jobs='+IntToStr(FCPUCount));
{$ENDIF}
Processor.Process.Parameters.Add('FPC=' + FCompiler);
Processor.Process.Parameters.Add('PP=' + ExtractFilePath(FCompiler)+GetCompilerName(GetTargetCPU));
Processor.Process.Parameters.Add('USESVN2REVISIONINC=0');
Processor.Process.Parameters.Add('PREFIX='+ExcludeTrailingPathDelimiter(FInstallDirectory));
Processor.Process.Parameters.Add('INSTALL_PREFIX='+ExcludeTrailingPathDelimiter(FInstallDirectory));
Processor.Process.Parameters.Add('LAZARUS_INSTALL_DIR='+IncludeTrailingPathDelimiter(FInstallDirectory));
//Make sure our FPC units can be found by Lazarus
Processor.Process.Parameters.Add('FPCDIR=' + ExcludeTrailingPathDelimiter(FFPCSourceDir));
//Processor.Process.Parameters.Add('FPCDIR=' + ExcludeTrailingPathDelimiter(FFPCInstallDir));
//Make sure Lazarus does not pick up these tools from other installs
Processor.Process.Parameters.Add('FPCMAKE=' + FFPCCompilerBinPath+'fpcmake'+GetExeExt);
Processor.Process.Parameters.Add('PPUMOVE=' + FFPCCompilerBinPath+'ppumove'+GetExeExt);
{$ifdef Windows}
Processor.Process.Parameters.Add('UPXPROG=echo'); //Don't use UPX
{$else}
//Processor.Process.Parameters.Add('INSTALL_BINDIR='+FBinPath);
{$endif}
//Prevents the Makefile to search for the (native) ppc compiler which is used to do the latest build
//Todo: to be investigated
//Processor.Process.Parameters.Add('FPCFPMAKE=' + ExtractFilePath(FCompiler)+GetCompilerName(GetTargetCPU));
if FLCL_Platform <> '' then
Processor.Process.Parameters.Add('LCL_PLATFORM=' + FLCL_Platform);
//Set standard options
s:=STANDARDCOMPILERVERBOSITYOPTIONS;
//Always limit the search for fpc.cfg to our own fpc.cfg
//Only needed on Windows. On Linux, we have already our own fpc.sh
{$ifdef Windows}
//s:=s+' -n @'+FFPCCompilerBinPath+'fpc.cfg';
{$endif}
// Add remaining options
s:=s+' '+FCompilerOptions;
//Lazbuild MUST be build without giving any extra optimization options
//At least on Linux anything else gives errors when trying to use lazbuild ... :-(
if ModuleName=_LAZBUILD then
begin
i:=Pos('-O',s);
if i>0 then
begin
if s[i+2] in ['0'..'9'] then
begin
Delete(s,i,3);
end;
end;
end;
{$ifdef Unix}
{$ifndef Darwin}
{$ifdef LCLQT}
{$endif}
{$ifdef LCLQT5}
// Did we copy the QT5 libs ??
// If so, add some linker help.
if (NOT LibWhich(LIBQT5)) AND (FileExists(IncludeTrailingPathDelimiter(FInstallDirectory)+LIBQT5)) then
begin
s:=s+' -k"-rpath=./"';
s:=s+' -k"-rpath=$$ORIGIN"';
s:=s+' -k"-rpath=\\$$$$$\\ORIGIN"';
s:=s+' -Fl'+ExcludeTrailingPathDelimiter(FInstallDirectory);
end;
{$endif}
{$endif}
{$endif}
// remove double spaces
while Pos(' ',s)>0 do
begin
s:=StringReplace(s,' ',' ',[rfReplaceAll]);
end;
s:=Trim(s);
if Length(s)>0 then Processor.Process.Parameters.Add('OPT='+s);
case ModuleName of
_USERIDE:
begin
{$ifdef DISABLELAZBUILDJOBS}
Processor.Process.Parameters.Add('LAZBUILDJOBS=1');//prevent runtime 217 errors
{$else}
Processor.Process.Parameters.Add('LAZBUILDJOBS='+IntToStr(FCPUCount));
{$endif}
Processor.Process.Parameters.Add('useride');
s:=IncludeTrailingPathDelimiter(FPrimaryConfigPath)+DefaultIDEMakeOptionFilename;
{
IDEConfig:=TStringList.Create;
try
if FileExists(s) then IDEConfig.LoadFromFile(s);
i:=StringListStartsWith(IDEConfig,'-T');
if (i=-1) then
IDEConfig.Append('-T'+GetTargetOS)
else
IDEConfig.Strings[i]:='-T'+GetTargetOS;
i:=StringListStartsWith(IDEConfig,'-P');
if (i=-1) then
IDEConfig.Append('-P'+GetTargetCPU)
else
IDEConfig.Strings[i]:='-P'+GetTargetCPU;
IDEConfig.SaveToFile(s);
finally
IDEConfig.Free;
end;
}
//if FileExists(s) then
Processor.Process.Parameters.Add('CFGFILE=' + s);
Infoln(infotext+'Running: make useride', etInfo);
(*
s:=IncludeTrailingPathDelimiter(FPrimaryConfigPath)+DefaultIDEMakeOptionFilename;
if FileExists(s) then
begin
// this uses lazbuild as per definition in the Lazarus Makefile
Processor.Process.Parameters.Add('LAZBUILDJOBS='+IntToStr(FCPUCount));
// Add the ide config build file when it is there
Processor.Process.Parameters.Add('CFGFILE=' + s);
Processor.Process.Parameters.Add('useride');
Infoln(infotext+'Running: make useride', etInfo);
end
else
begin
// sometimes, we get an error 217 when buidling lazarus for the first time.
// the below tries to prevent this by not using lazbuild on a fresh install.
Processor.Process.Parameters.Add('registration');
Processor.Process.Parameters.Add('lazutils');
Processor.Process.Parameters.Add('lcl');
Processor.Process.Parameters.Add('basecomponents');
Processor.Process.Parameters.Add('ide');
Infoln(infotext+'Running: make registration lazutils lcl basecomponents ide', etInfo);
end;
*)
end;
_IDE:
begin
Processor.Process.Parameters.Add('idepkg');
Infoln(infotext+'Running: make idepkg', etInfo);
end;
_BIGIDE:
begin
Processor.Process.Parameters.Add('idebig');
Infoln(infotext+'Running: make idebig', etInfo);
end;
_LAZARUS:
begin
Processor.Process.Parameters.Add('all');
Infoln(infotext+'Running: make all', etInfo);
end;
_STARTLAZARUS:
begin
if FileExists(IncludeTrailingPathDelimiter(FSourceDirectory) + 'startlazarus' + GetExeExt) then
begin
Infoln(infotext+'StartLazarus already available ... skip building it.', etInfo);
OperationSucceeded := true;
Result := true;
exit;
end;
Processor.Process.Parameters.Add('starter');
Infoln(infotext+'Running: make starter', etInfo);
end;
_LAZBUILD:
begin
if FileExists(IncludeTrailingPathDelimiter(FSourceDirectory) + LAZBUILDNAME + GetExeExt) then
begin
Infoln(infotext+'Lazbuild already available ... skip building it.', etInfo);
OperationSucceeded := true;
Result := true;
exit;
end;
Processor.Process.Parameters.Add('lazbuild');
Infoln(infotext+'Running: make lazbuild', etInfo);
end;
_LCL:
begin
// April 2012: lcl now requires lazutils and registration
// https://wiki.lazarus.freepascal.org/Getting_Lazarus#Make_targets
// https://lists.lazarus-ide.org/pipermail/lazarus/2012-April/138168.html
Processor.Process.Parameters.Add('registration');
Processor.Process.Parameters.Add('lazutils');
Processor.Process.Parameters.Add('lcl');
// always build standard LCL for native system ... other widgetsets to be done by LCLCROSS: see below
//if FCrossLCL_Platform<>'' then Processor.Process.Parameters.Add('LCL_PLATFORM=' + FCrossLCL_Platform);
Infoln(infotext+'Running: make registration lazutils lcl', etInfo);
end;
_LCLCROSS:
begin
if LCLCrossActionNeeded then
begin
Processor.Process.Parameters.Add('-C '+ConcatPaths([FSourceDirectory,'lcl']));
Processor.Process.Parameters.Add('intf');
Infoln(infotext+'Running: make -C lcl intf', etInfo);
end
else
begin
// nothing to be done: exit graceously
Infoln(infotext+'No extra LCL_PLATFORM defined ... nothing to be done', etInfo);
OperationSucceeded := true;
Result := true;
exit;
end;
end;
_INSTALLLAZARUS:
begin
if ((SourceVersionNum<>0) AND (SourceVersionNum<CalculateFullVersion(1,8,0))) then
begin
Infoln(infotext+'Deleting '+FPCDefines+' to force rescan of FPC sources.', etInfo);
s:=IncludeTrailingPathDelimiter(FPrimaryConfigPath)+FPCDefines;
SysUtils.DeleteFile(s);
end;
if (FInstallDirectory<>FSourceDirectory) then
begin
Processor.Process.Parameters.Add('install');
Infoln(infotext+'Running: make install', etInfo);
end
else
begin
Processor.Process.Parameters.Add('--help'); // this should render make harmless
WritelnLog(etInfo, infotext+'Skipping install step: Lazarus source and install locations are the same.', true);
OperationSucceeded := true;
Result := true;
exit;
end;
end;
_MAKEFILECHECKLAZARUS:
begin
Processor.Process.Parameters.Add('fpc_baseinfo');
Infoln(infotext+'Running: make fpc_baseinfo', etInfo);
end
else //raise error;
begin
Processor.Process.Parameters.Add('--help'); // this should render make harmless
WritelnLog(etError, infotext+'Invalid module name ' + ModuleName + ' specified! Please fix the code.', true);
OperationSucceeded := false;
Result := false;
exit;
end;
if FLCL_Platform<>'' then Processor.Process.Parameters.Add('LCL_PLATFORM=' + FLCL_Platform);
end;
try
{$ifdef MSWindows}
//Prepend FPC binary directory to PATH to prevent pickup of strange tools
OldPath:=Processor.Environment.GetVar(PATHVARNAME);
s:=ExcludeTrailingPathDelimiter(FFPCCompilerBinPath);
if OldPath<>'' then
Processor.Environment.SetVar(PATHVARNAME, s+PathSeparator+OldPath)
else
Processor.Environment.SetVar(PATHVARNAME, s);
{$endif}
ProcessorResult:=Processor.ExecuteAndWait;
ExitCode := ProcessorResult;
if ExitCode <> 0 then
begin
WritelnLog(etError, infotext+ExtractFileName(Processor.Executable)+' returned exit status #'+IntToStr(ExitCode), true);
OperationSucceeded := false;
Result := false;
end;
{$ifdef MSWindows}
Processor.Environment.SetVar(PATHVARNAME, OldPath);
{$endif}
except
on E: Exception do
begin
WritelnLog(etError, infotext+ExtractFileName(Processor.Executable)+' exception.'+LineEnding+'Exception details: '+E.Message, true);
OperationSucceeded := false;
Result := false;
end;
end;
//Special check for lazbuild as that is known to go wrong
if (OperationSucceeded) and (ModuleName=_LAZBUILD) then
begin
if CheckExecutable(IncludeTrailingPathDelimiter(FSourceDirectory) + LAZBUILDNAME + GetExeExt, ['--help'], LAZBUILDNAME) = false then
begin
WritelnLog(etError, infotext+'Lazbuild could not be found, so cannot build USERIDE.', true);
Result := false;
exit;
end;
end;
end
else
begin
// For building useride for Lazarus versions
// useride; using lazbuild.
// Check for valid lazbuild.
// Note: we don't check if we have a valid primary config path, but that will come out
// in the next steps.
if CheckExecutable(LazBuildApp, ['--help'], LAZBUILDNAME) = false then
begin
WritelnLog(etError, infotext+'Lazbuild could not be found, so cannot build USERIDE.', true);
Result := false;
exit;
end
else
begin
// First build IDE using lazbuild... then...
Processor.Executable := LazBuildApp;
FErrorLog.Clear;
Processor.Process.CurrentDirectory := ExcludeTrailingPathDelimiter(FSourceDirectory);
Processor.Process.Parameters.Clear;
//SysUtils.GetEnvironmentVariable('FPCDIR');
//Makefile could pickup this FPCDIR setting, so try to set it for fpcupdeluxe
FPCDirStore:=Processor.Environment.GetVar('FPCDIR');
Processor.Environment.SetVar('FPCDIR',ExcludeTrailingPathDelimiter(FFPCSourceDir));
{$IFDEF DEBUG}
Processor.Process.Parameters.Add('--verbose');
{$ELSE}
// See compileroptions.pp
// Quiet:=ConsoleVerbosity<=-3;
Processor.Process.Parameters.Add('--quiet');
{$ENDIF}
Processor.Process.Parameters.Add('--pcp=' + DoubleQuoteIfNeeded(FPrimaryConfigPath));
Processor.Process.Parameters.Add('--cpu=' + GetTargetCPU);
Processor.Process.Parameters.Add('--os=' + GetTargetOS);