forked from doublecmd/doublecmd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fpmake.pp
executable file
·357 lines (308 loc) · 9.42 KB
/
fpmake.pp
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
program fpmake;
{$coperators on}
{$mode objfpc}{$H+}
uses
fpmkunit, SysUtils, Classes;
const
AllMyUnixOSes = AllUnixOSes - [Darwin];
const
CommonComponents: array[1..9] of String =
(
'components\chsdet\chsdet.lpk',
'components\CmdLine\cmdbox.lpk',
'components\multithreadprocs\multithreadprocslaz.lpk',
'components\dcpcrypt\dcpcrypt.lpk',
'components\doublecmd\doublecmd_common.lpk',
'components\KASToolBar\kascomp.lpk',
'components\viewer\viewerpackage.lpk',
'components\gifanim\pkg_gifanim.lpk',
'components\synunihighlighter\synuni.lpk'
);
CommonPlugins: array[1..8] of String =
(
'plugins/wcx/deb/src/deb.lpi',
'plugins/wcx/rpm/src/rpm.lpi',
'plugins/wcx/unrar/src/unrar.lpi',
'plugins/wcx/zip/src/Zip.lpi',
'plugins/wdx/rpm_wdx/src/rpm_wdx.lpi',
'plugins/wdx/deb_wdx/src/deb_wdx.lpi',
'plugins/wdx/audioinfo/src/AudioInfo.lpi',
'plugins/wfx/ftp/src/ftp.lpi'
);
UnixPlugins: array[1..4] of String =
(
'plugins/wcx/cpio/src/cpio.lpi',
'plugins/wfx/samba/src/samba.lpi',
'plugins/wlx/WlxMplayer/src/wlxMplayer.lpi',
'plugins/dsx/DSXLocate/src/DSXLocate.lpi'
);
DarwinPlugins: array[1..1] of String =
(
'plugins/wcx/cpio/src/cpio.lpi'
);
WindowsPlugins: array[1..1] of String =
(
'plugins/wcx/sevenzip/src/SevenZipWcx.lpi'
);
DeleteFiles: array[1..6] of String =
(
'doublecmd',
'doublecmd.exe',
'doublecmd.dbg',
'doublecmd.zdli',
'src\doublecmd.res',
'tools\extractdwrflnfo'
);
var
FLazBuild: String = 'lazbuild';
type
{ TDCDefaults }
TDCDefaults = class(TFPCDefaults)
private
FWS: String;
public
procedure CompilerDefaults; override;
property WS: String read FWS write FWS;
end;
{ TDCBuildEngine }
TDCBuildEngine = class(TBuildEngine)
end;
{ TDCInstaller }
TDCInstaller = class(TCustomInstaller)
private
FLazBuildParams: String;
private
procedure CleanDirectory(const Directory: String);
procedure CleanComponents;
procedure BuildComponents;
procedure CleanPlugins;
procedure BuildPlugins;
procedure Clean; overload;
procedure Build;
function ReadOutputDirectory(const FileName: String): String;
procedure CleanOutputDirectory(const FileName: String);
protected
procedure Clean(AllTargets: boolean); override;
public
constructor Create(AOwner : TComponent); override;
end;
{ TDCDefaults }
procedure TDCDefaults.CompilerDefaults;
var
AValue: String;
begin
if Defaults.OS = osNone then
begin
AValue:= GetEnvironmentVariable('OS_TARGET');
if Length(AValue) > 0 then Defaults.OS:= StringToOS(AValue);
end;
if Defaults.CPU = cpuNone then
begin
AValue:= GetEnvironmentVariable('CPU_TARGET');
if Length(AValue) > 0 then Defaults.CPU:= StringToCPU(AValue);
end;
AValue:= GetEnvironmentVariable('LCL_PLATFORM');
if Length(AValue) > 0 then (Defaults as TDCDefaults).FWS:= AValue;
inherited CompilerDefaults;
end;
procedure TDCInstaller.BuildComponents;
var
I: Integer;
Args : String;
begin
for I:= Low(CommonComponents) to High(CommonComponents) do
begin
Args:= SetDirSeparators(CommonComponents[I]) + FLazBuildParams;
BuildEngine.ExecuteCommand(FLazBuild, Args);
end;
end;
procedure TDCInstaller.CleanPlugins;
var
I: Integer;
begin
for I:= Low(CommonPlugins) to High(CommonPlugins) do
begin
CleanOutputDirectory(CommonPlugins[I]);
end;
end;
function TDCInstaller.ReadOutputDirectory(const FileName: String): String;
var
I: Integer;
AFile: TStringList;
begin
try
AFile:= TStringList.Create;
try
AFile.LoadFromFile(SetDirSeparators(FileName));
I:= Pos('UnitOutputDirectory Value', AFile.Text);
if I = 0 then Exit;
Result:= Copy(AFile.Text, I + 27, MaxInt);
I:= Pos('"', Result);
if I = 0 then Exit;
Result:= ExtractFilePath(FileName) + Copy(Result, 1, I - 1);
Result:= StringReplace(Result, '$(TargetOS)', OSToString(Defaults.OS), [rfReplaceAll, rfIgnoreCase]);
Result:= StringReplace(Result, '$(TargetCPU)', CPUToString(Defaults.CPU), [rfReplaceAll, rfIgnoreCase]);
Result:= SetDirSeparators(Result);
finally
AFile.Free;
end;
except
Result:= EmptyStr;
end;
end;
procedure TDCInstaller.CleanOutputDirectory(const FileName: String);
begin
CleanDirectory(ReadOutputDirectory(FileName));
end;
procedure TDCInstaller.Clean(AllTargets: boolean);
begin
// Clean components
CleanComponents;
// Clean plugins
CleanPlugins;
// Clean Double Commander
Clean;
end;
constructor TDCInstaller.Create(AOwner: TComponent);
begin
Defaults:= TDCDefaults.Create;
Defaults.IgnoreInvalidOptions:= True;
inherited Create(AOwner);
end;
procedure TDCInstaller.BuildPlugins;
var
I: Integer;
begin
for I:= Low(CommonPlugins) to High(CommonPlugins) do
BuildEngine.ExecuteCommand(FLazBuild, SetDirSeparators(CommonPlugins[I]) + FLazBuildParams);
if Defaults.OS in AllMyUnixOSes then
begin
for I:= Low(UnixPlugins) to High(UnixPlugins) do
BuildEngine.ExecuteCommand(FLazBuild, SetDirSeparators(UnixPlugins[I]) + FLazBuildParams);
end;
if Defaults.OS = Darwin then
begin
for I:= Low(DarwinPlugins) to High(DarwinPlugins) do
BuildEngine.ExecuteCommand(FLazBuild, SetDirSeparators(DarwinPlugins[I]) + FLazBuildParams);
end;
if Defaults.OS in AllWindowsOSes then
begin
for I:= Low(WindowsPlugins) to High(WindowsPlugins) do
BuildEngine.ExecuteCommand(FLazBuild, SetDirSeparators(WindowsPlugins[I]) + FLazBuildParams);
end;
end;
procedure TDCInstaller.Clean;
const
OutputPath = 'units' + PathDelim;
var
I: Integer;
AInfo : TSearchRec;
begin
// Clean output directories
if FindFirst(OutputPath + AllFilesMask, faAnyFile - faHidden, AInfo) = 0 then
repeat
if ((AInfo.Attr and faDirectory) = faDirectory) and (AInfo.Name <> '.') and (AInfo.Name <> '..') then
CleanDirectory(OutputPath + AInfo.Name);
until FindNext(AInfo) <> 0;
FindClose(AInfo);
TDCBuildEngine(BuildEngine).SysDeleteTree('tools' + PathDelim + 'lib');
// Clean files
for I:= Low(DeleteFiles) to High(DeleteFiles) do
TDCBuildEngine(BuildEngine).SysDeleteFile(SetDirSeparators(DeleteFiles[I]));
// Clean debug directory
if Defaults.OS = Darwin then
begin
TDCBuildEngine(BuildEngine).SysDeleteTree('doublecmd.dSYM');
end;
// Clean fpmake output files
TDCBuildEngine(BuildEngine).SysDeleteFile('fpmake.o');
end;
procedure TDCInstaller.Build;
begin
// Build components
BuildComponents;
// Build plugins
BuildPlugins;
// Set default build mode
if Pos('--bm=', FLazBuildParams) = 0 then
FLazBuildParams+= ' --bm=beta';
// Build Double Commander
BuildEngine.ExecuteCommand(FLazBuild, SetDirSeparators('src/doublecmd.lpi') + FLazBuildParams);
if Pos('--bm=beta', FLazBuildParams) > 0 then
begin
// Build Dwarf LineInfo Extractor
BuildEngine.ExecuteCommand(FLazBuild, SetDirSeparators('tools/extractdwrflnfo.lpi'));
// Extract debug line info
if Defaults.OS = Darwin then
begin
BuildEngine.CmdRenameFile('doublecmd.dSYM/Contents/Resources/DWARF/doublecmd', 'doublecmd.dbg');
end;
BuildEngine.ExecuteCommand(SetDirSeparators('tools/extractdwrflnfo'), 'doublecmd.dbg');
end;
end;
procedure TDCInstaller.CleanDirectory(const Directory: String);
var
List: TStrings;
begin
List:= TStringList.Create;
try
SearchFiles(IncludeTrailingPathDelimiter(Directory) + AllFilesMask, EmptyStr, False, List);
BuildEngine.CmdDeleteFiles(List);
finally
List.Free;
end;
end;
procedure TDCInstaller.CleanComponents;
var
I: Integer;
begin
for I:= Low(CommonComponents) to High(CommonComponents) do
begin
CleanOutputDirectory(CommonComponents[I]);
end;
end;
var
I: Integer;
var
OptArg: String;
BuildTarget: String;
begin
AddCustomFpmakeCommandlineOption('bm', 'Override the project build mode.');
AddCustomFpmakeCommandlineOption('ws', 'Override the project widgetset, e.g. gtk2 qt qt5 win32 cocoa.');
with Installer(TDCInstaller) as TDCInstaller do
begin
CreateBuildEngine;
BuildTarget:= ParamStr(1);
FLazBuildParams:= ' --os=' + OSToString(Defaults.OS);
FLazBuildParams+= ' --cpu=' + CPUToString(Defaults.CPU);
if BuildTarget = 'clean' then
begin
Clean(True);
Exit;
end;
for I:= 0 to ParamCount do WriteLn(ParamStr(I));
OptArg:= GetCustomFpmakeCommandlineOptionValue('bm');
if Length(OptArg) > 0 then begin
FLazBuildParams+= ' --bm=' + OptArg;
end;
OptArg:= GetCustomFpmakeCommandlineOptionValue('ws');
if Length(OptArg) > 0 then begin
FLazBuildParams+= ' --ws=' + OptArg;
end;
if (Defaults.HaveOptions) then begin
FLazBuildParams+= ' ' + TDCDefaults(Defaults).CmdLineOptions;
end;
if BuildEngine.Verbose then begin
FLazBuildParams+= ' --verbose';
end;
if (Pos('--ws', FLazBuildParams) = 0) and (Length((Defaults as TDCDefaults).WS) > 0) then
FLazBuildParams+= ' --ws=' + (Defaults as TDCDefaults).WS;
WriteLn(FLazBuildParams);
if BuildTarget = 'components' then
BuildComponents
else if BuildTarget = 'plugins' then
BuildPlugins
else
Build;
end;
end.