mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-11-25 04:17:12 +01:00
+ Initial implementation of new fpmake system
git-svn-id: trunk@436 -
This commit is contained in:
parent
cc4818be26
commit
7c1ce9f49e
5
.gitattributes
vendored
5
.gitattributes
vendored
@ -3293,6 +3293,11 @@ rtl/bsd/system.pp svneol=native#text/plain
|
||||
rtl/bsd/unxsysch.inc svneol=native#text/plain
|
||||
rtl/bsd/x86_64/syscall.inc svneol=native#text/plain
|
||||
rtl/bsd/x86_64/syscallh.inc svneol=native#text/plain
|
||||
rtl/common/fpmake.lpi svneol=native#text/plain
|
||||
rtl/common/fpmake.pp svneol=native#text/plain
|
||||
rtl/common/fpmkpkg.lpi svneol=native#text/plain
|
||||
rtl/common/fpmkpkg.pp svneol=native#text/plain
|
||||
rtl/common/fpmkunit.pp svneol=native#text/plain
|
||||
rtl/darwin/Makefile -text
|
||||
rtl/darwin/Makefile.fpc svneol=native#text/plain
|
||||
rtl/darwin/console.pp svneol=native#text/plain
|
||||
|
||||
162
rtl/common/fpmake.lpi
Normal file
162
rtl/common/fpmake.lpi
Normal file
@ -0,0 +1,162 @@
|
||||
<?xml version="1.0"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<PathDelim Value="/"/>
|
||||
<Version Value="5"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<MainUnitHasUsesSectionForAllUnits Value="False"/>
|
||||
<MainUnitHasCreateFormStatements Value="False"/>
|
||||
<MainUnitHasTitleStatement Value="False"/>
|
||||
</Flags>
|
||||
<MainUnit Value="0"/>
|
||||
<ActiveEditorIndexAtStart Value="0"/>
|
||||
<IconPath Value="./"/>
|
||||
<TargetFileExt Value=""/>
|
||||
</General>
|
||||
<JumpHistory Count="16" HistoryIndex="15">
|
||||
<Position1>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="200" Column="35" TopLine="161"/>
|
||||
</Position1>
|
||||
<Position2>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="1600" Column="16" TopLine="1600"/>
|
||||
</Position2>
|
||||
<Position3>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="21" Column="1" TopLine="21"/>
|
||||
</Position3>
|
||||
<Position4>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="316" Column="21" TopLine="285"/>
|
||||
</Position4>
|
||||
<Position5>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="1116" Column="28" TopLine="1086"/>
|
||||
</Position5>
|
||||
<Position6>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="316" Column="7" TopLine="316"/>
|
||||
</Position6>
|
||||
<Position7>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="317" Column="30" TopLine="297"/>
|
||||
</Position7>
|
||||
<Position8>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="1145" Column="33" TopLine="1121"/>
|
||||
</Position8>
|
||||
<Position9>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="1116" Column="26" TopLine="1096"/>
|
||||
</Position9>
|
||||
<Position10>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="316" Column="31" TopLine="316"/>
|
||||
</Position10>
|
||||
<Position11>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="1138" Column="22" TopLine="1114"/>
|
||||
</Position11>
|
||||
<Position12>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="1141" Column="21" TopLine="1121"/>
|
||||
</Position12>
|
||||
<Position13>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="1689" Column="10" TopLine="1671"/>
|
||||
</Position13>
|
||||
<Position14>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="634" Column="1" TopLine="603"/>
|
||||
</Position14>
|
||||
<Position15>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="631" Column="17" TopLine="616"/>
|
||||
</Position15>
|
||||
<Position16>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="1787" Column="1" TopLine="1752"/>
|
||||
</Position16>
|
||||
</JumpHistory>
|
||||
<Units Count="6">
|
||||
<Unit0>
|
||||
<CursorPos X="9" Y="22"/>
|
||||
<EditorIndex Value="1"/>
|
||||
<Filename Value="fpmake.pp"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<Loaded Value="True"/>
|
||||
<TopLine Value="1"/>
|
||||
<UnitName Value="fpmake"/>
|
||||
<UsageCount Value="59"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<CursorPos X="1" Y="2588"/>
|
||||
<EditorIndex Value="0"/>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<Loaded Value="True"/>
|
||||
<TopLine Value="2552"/>
|
||||
<UnitName Value="fpmkunit"/>
|
||||
<UsageCount Value="59"/>
|
||||
</Unit1>
|
||||
<Unit2>
|
||||
<CursorPos X="23" Y="27"/>
|
||||
<Filename Value="fpc/rtl/objpas/sysutils/osutilsh.inc"/>
|
||||
<TopLine Value="8"/>
|
||||
<UsageCount Value="9"/>
|
||||
</Unit2>
|
||||
<Unit3>
|
||||
<CursorPos X="3" Y="931"/>
|
||||
<Filename Value="fpc/rtl/unix/sysutils.pp"/>
|
||||
<TopLine Value="908"/>
|
||||
<UnitName Value="sysutils"/>
|
||||
<UsageCount Value="9"/>
|
||||
</Unit3>
|
||||
<Unit4>
|
||||
<CursorPos X="18" Y="610"/>
|
||||
<Filename Value="fpc/rtl/objpas/classes/classesh.inc"/>
|
||||
<TopLine Value="590"/>
|
||||
<UsageCount Value="8"/>
|
||||
</Unit4>
|
||||
<Unit5>
|
||||
<CursorPos X="7" Y="159"/>
|
||||
<Filename Value="fpc/rtl/objpas/classes/streams.inc"/>
|
||||
<TopLine Value="152"/>
|
||||
<UsageCount Value="8"/>
|
||||
</Unit5>
|
||||
</Units>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<IgnoreBinaries Value="False"/>
|
||||
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<local>
|
||||
<FormatVersion Value="1"/>
|
||||
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
|
||||
</local>
|
||||
</RunParams>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="5"/>
|
||||
<CodeGeneration>
|
||||
<Generate Value="Faster"/>
|
||||
</CodeGeneration>
|
||||
<Other>
|
||||
<CompilerPath Value="$(CompPath)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions Count="2">
|
||||
<Item1>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item2>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
||||
24
rtl/common/fpmake.pp
Normal file
24
rtl/common/fpmake.pp
Normal file
@ -0,0 +1,24 @@
|
||||
program fpmake;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
fpmakeunit
|
||||
{ add your units here };
|
||||
|
||||
begin
|
||||
With Installer Do
|
||||
begin
|
||||
StartPackage('Mypackage');
|
||||
Version:='1.0';
|
||||
URL:='http://www.freepascal.org/';
|
||||
Targets.AddUnit('myunit');
|
||||
Targets['myunit'].OS:=[Win32,Linux];
|
||||
Targets['myunit'].Resourcestrings:=True;
|
||||
Targets.AddUnit('testbuild/myotherunit').OS:=[Linux];
|
||||
Targets.AddProgram('myprog');
|
||||
EndPackage;
|
||||
Run;
|
||||
end;
|
||||
end.
|
||||
|
||||
198
rtl/common/fpmkpkg.lpi
Normal file
198
rtl/common/fpmkpkg.lpi
Normal file
@ -0,0 +1,198 @@
|
||||
<?xml version="1.0"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<PathDelim Value="/"/>
|
||||
<Version Value="5"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<MainUnitHasUsesSectionForAllUnits Value="False"/>
|
||||
<MainUnitHasCreateFormStatements Value="False"/>
|
||||
<MainUnitHasTitleStatement Value="False"/>
|
||||
</Flags>
|
||||
<MainUnit Value="0"/>
|
||||
<ActiveEditorIndexAtStart Value="1"/>
|
||||
<IconPath Value="./"/>
|
||||
<TargetFileExt Value=""/>
|
||||
</General>
|
||||
<JumpHistory Count="30" HistoryIndex="29">
|
||||
<Position1>
|
||||
<Filename Value="fpmkpkg.pp"/>
|
||||
<Caret Line="566" Column="3" TopLine="546"/>
|
||||
</Position1>
|
||||
<Position2>
|
||||
<Filename Value="fpmkpkg.pp"/>
|
||||
<Caret Line="565" Column="9" TopLine="546"/>
|
||||
</Position2>
|
||||
<Position3>
|
||||
<Filename Value="fpmkpkg.pp"/>
|
||||
<Caret Line="581" Column="18" TopLine="561"/>
|
||||
</Position3>
|
||||
<Position4>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="677" Column="13" TopLine="667"/>
|
||||
</Position4>
|
||||
<Position5>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="157" Column="88" TopLine="121"/>
|
||||
</Position5>
|
||||
<Position6>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="2577" Column="53" TopLine="2565"/>
|
||||
</Position6>
|
||||
<Position7>
|
||||
<Filename Value="fpmkpkg.pp"/>
|
||||
<Caret Line="929" Column="20" TopLine="906"/>
|
||||
</Position7>
|
||||
<Position8>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="585" Column="25" TopLine="578"/>
|
||||
</Position8>
|
||||
<Position9>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="173" Column="51" TopLine="172"/>
|
||||
</Position9>
|
||||
<Position10>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="670" Column="11" TopLine="667"/>
|
||||
</Position10>
|
||||
<Position11>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="170" Column="25" TopLine="169"/>
|
||||
</Position11>
|
||||
<Position12>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="921" Column="22" TopLine="919"/>
|
||||
</Position12>
|
||||
<Position13>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="931" Column="5" TopLine="882"/>
|
||||
</Position13>
|
||||
<Position14>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="195" Column="80" TopLine="158"/>
|
||||
</Position14>
|
||||
<Position15>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="908" Column="1" TopLine="908"/>
|
||||
</Position15>
|
||||
<Position16>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="1098" Column="1" TopLine="1057"/>
|
||||
</Position16>
|
||||
<Position17>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="851" Column="5" TopLine="802"/>
|
||||
</Position17>
|
||||
<Position18>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="636" Column="15" TopLine="636"/>
|
||||
</Position18>
|
||||
<Position19>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="2700" Column="1" TopLine="2680"/>
|
||||
</Position19>
|
||||
<Position20>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="858" Column="27" TopLine="856"/>
|
||||
</Position20>
|
||||
<Position21>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="2702" Column="5" TopLine="2702"/>
|
||||
</Position21>
|
||||
<Position22>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="932" Column="47" TopLine="932"/>
|
||||
</Position22>
|
||||
<Position23>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="2715" Column="17" TopLine="2706"/>
|
||||
</Position23>
|
||||
<Position24>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="1" Column="1" TopLine="1"/>
|
||||
</Position24>
|
||||
<Position25>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="313" Column="25" TopLine="290"/>
|
||||
</Position25>
|
||||
<Position26>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="347" Column="48" TopLine="325"/>
|
||||
</Position26>
|
||||
<Position27>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="394" Column="25" TopLine="372"/>
|
||||
</Position27>
|
||||
<Position28>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="408" Column="26" TopLine="386"/>
|
||||
</Position28>
|
||||
<Position29>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="1049" Column="19" TopLine="1019"/>
|
||||
</Position29>
|
||||
<Position30>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Caret Line="2162" Column="34" TopLine="2139"/>
|
||||
</Position30>
|
||||
</JumpHistory>
|
||||
<Units Count="2">
|
||||
<Unit0>
|
||||
<CursorPos X="21" Y="738"/>
|
||||
<EditorIndex Value="0"/>
|
||||
<Filename Value="fpmkpkg.pp"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<Loaded Value="True"/>
|
||||
<TopLine Value="733"/>
|
||||
<UnitName Value="fpmkpkg"/>
|
||||
<UsageCount Value="87"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<CursorPos X="1" Y="2210"/>
|
||||
<EditorIndex Value="1"/>
|
||||
<Filename Value="fpmkunit.pp"/>
|
||||
<Loaded Value="True"/>
|
||||
<TopLine Value="2204"/>
|
||||
<UnitName Value="fpmkunit"/>
|
||||
<UsageCount Value="43"/>
|
||||
</Unit1>
|
||||
</Units>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<IgnoreBinaries Value="False"/>
|
||||
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<local>
|
||||
<FormatVersion Value="1"/>
|
||||
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
|
||||
</local>
|
||||
</RunParams>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="5"/>
|
||||
<CodeGeneration>
|
||||
<Generate Value="Faster"/>
|
||||
</CodeGeneration>
|
||||
<Other>
|
||||
<CompilerPath Value="$(CompPath)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<BreakPoints Count="1">
|
||||
<Item1>
|
||||
<Source Value="fpmkpkg.pp"/>
|
||||
<Line Value="662"/>
|
||||
</Item1>
|
||||
</BreakPoints>
|
||||
<Exceptions Count="2">
|
||||
<Item1>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item2>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
||||
961
rtl/common/fpmkpkg.pp
Normal file
961
rtl/common/fpmkpkg.pp
Normal file
@ -0,0 +1,961 @@
|
||||
program fpmkpkg;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
Classes, SysUtils, TypInfo
|
||||
{ add your units here };
|
||||
|
||||
Resourcestring
|
||||
// SErrInValidArgument = 'Invalid command-line argument at position %d : %s';
|
||||
SErrNeedArgument = 'Option at position %d (%s) needs an argument';
|
||||
SErrMissingConfig = 'Missing configuration Makefile.fpc or fpmake.pp';
|
||||
SErrRunning = 'The FPC make tool encountered the following error: %s';
|
||||
SErrFailedToCompileFPCMake = 'Could not compile fpmake driver program';
|
||||
SLogGeneratingFPMake = 'Generating fpmake.pp';
|
||||
SLogCompilingFPMake = 'Compiling fpmake.pp: ';
|
||||
SLogRunningFPMake = 'Running fpmake';
|
||||
|
||||
Type
|
||||
|
||||
TRunMode = (rmHelp,rmCompile,rmBuild,rmInstall,rmArchive,rmClean,rmDownload);
|
||||
|
||||
{ TMakeTool }
|
||||
|
||||
TMakeTool = Class(TObject)
|
||||
Private
|
||||
FConvertOnly,
|
||||
FLogging : Boolean;
|
||||
FCompiler : String;
|
||||
FRunMode : TRunMode;
|
||||
FHaveMakefile : Boolean;
|
||||
FHaveFpmake : Boolean;
|
||||
FFPMakeSrc : String;
|
||||
FFPMakeBin : String;
|
||||
Procedure Log(Msg : String);
|
||||
Procedure Error(Msg : String);
|
||||
Procedure Error(Fmt : String; Args : Array of const);
|
||||
Function GetCompiler : String;
|
||||
Public
|
||||
Procedure ProcessCommandLine;
|
||||
procedure CreateFPMake;
|
||||
procedure CompileFPMake(Extra : Boolean);
|
||||
Function RunFPMake : Integer;
|
||||
Procedure Run;
|
||||
end;
|
||||
|
||||
EMakeToolError = Class(Exception);
|
||||
|
||||
|
||||
{ TMakeFileConverter }
|
||||
TSectionType = (stNone,stPackage,stTarget,stclean,stinstall,stCompiler,
|
||||
stDefault,stRequire,stRules,stPrerules);
|
||||
|
||||
TMakeFileConverter = Class(TObject)
|
||||
FSection : TSectionType;
|
||||
FPackageName,
|
||||
FpackageDir,
|
||||
FPackageOptions,
|
||||
FPackageDeps,
|
||||
FBuilDUnit,
|
||||
FSubName,
|
||||
FPackageVersion : String;
|
||||
// Reading;
|
||||
procedure DoPackageLine(Const S : String);
|
||||
Procedure DoTargetLine(Line : String; Var T,R,D : TStrings);
|
||||
Procedure DoInstallLine(Line : String; Var IFL : TStrings);
|
||||
procedure DoCleanLine(Line : String; Var CFL : TStrings);
|
||||
procedure DoRequireLine(Line : String);
|
||||
procedure DoCompilerLine(Line : String;Var SD : TStrings);
|
||||
// Writing;
|
||||
procedure WriteOSCPUCheck(Src: TStrings;OS,CPU : String);
|
||||
procedure StartPackage(Src : TStrings; Dir,OS : String);
|
||||
procedure EndPackage(Src : TStrings; Dir,OS : String);
|
||||
procedure DoTargets(Src,T,R,SD : TStrings; Dir,Prefix : String);
|
||||
procedure DoCleans(Src,CFL : TStrings);
|
||||
procedure DoInstalls(Src,IFL : TStrings);
|
||||
Procedure StartInstaller(Src : TStrings);
|
||||
Procedure EndInstaller(Src : TStrings);
|
||||
Function GetLine (L : TStrings; Var I : Integer) : String;
|
||||
Public
|
||||
procedure ConvertFile(const AFileName: String; Src: TStrings; Dir,OS : String);
|
||||
Procedure ConvertFile(Const Source,Dest: String);
|
||||
end;
|
||||
|
||||
{ Auxiliary functions }
|
||||
|
||||
Function GetWord(var S : String; Sep : Char) : String;
|
||||
|
||||
Var
|
||||
L : Integer;
|
||||
|
||||
begin
|
||||
L:=Pos(Sep,S);
|
||||
If (L=0) then
|
||||
L:=Length(S)+1;
|
||||
Result:=Copy(S,1,L-1);
|
||||
Delete(S,1,L);
|
||||
S:=Trim(S);
|
||||
end;
|
||||
|
||||
Function GetWord(var S : String) : String;
|
||||
|
||||
begin
|
||||
Result:=GetWord(S,' ');
|
||||
end;
|
||||
|
||||
|
||||
Function IsCPU (S: String) : Boolean;
|
||||
|
||||
begin
|
||||
Result:=Pos(lowercase(S)+',','i386,powerpc,arm,alpha,sparc,')<>0
|
||||
end;
|
||||
|
||||
Function GetOSCPU(L : String; var OS,CPU : String) : String;
|
||||
|
||||
Procedure Add(Var A : String; ad : String);
|
||||
|
||||
begin
|
||||
If (A<>'') then
|
||||
A:=A+',';
|
||||
A:=A+ad;
|
||||
end;
|
||||
|
||||
|
||||
Var
|
||||
S : String;
|
||||
|
||||
begin
|
||||
OS:='';
|
||||
CPU:='';
|
||||
S:=GetWord(L,',');
|
||||
While (S<>'') do
|
||||
begin
|
||||
If (S<>'all') then
|
||||
If IsCPU(S) then
|
||||
Add(CPU,S)
|
||||
else
|
||||
Add(OS,S);
|
||||
S:=GetWord(L,',');
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
{ TMakeFileConverter }
|
||||
|
||||
procedure TMakeFileConverter.StartInstaller(Src: TStrings);
|
||||
|
||||
begin
|
||||
With Src do
|
||||
begin
|
||||
Add('{$mode objfpc}{$H+}');
|
||||
Add('program fpmake;');
|
||||
|
||||
Add('');
|
||||
Add(' { Generated automatically by '+ExtractFileName(Paramstr(0))+' on '+DateToStr(Sysutils.Date)+' }');
|
||||
Add('');
|
||||
Add('uses fpmkunit;');
|
||||
Add('');
|
||||
Add('Var');
|
||||
Add(' T : TTarget;');
|
||||
Add('');
|
||||
Add('begin');
|
||||
Add(' With Installer do ');
|
||||
Add(' begin');
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMakeFileConverter.EndInstaller(Src: TStrings);
|
||||
begin
|
||||
With Src do
|
||||
begin
|
||||
Add(' Run;');
|
||||
Add(' end;');
|
||||
Add('end.');
|
||||
Add('');
|
||||
end;
|
||||
end;
|
||||
|
||||
Function TMakeFileConverter.GetLine (L : TStrings; Var I : Integer) : String;
|
||||
|
||||
Var
|
||||
P : Integer;
|
||||
OK : Boolean;
|
||||
|
||||
begin
|
||||
OK:=False;
|
||||
Result:='';
|
||||
Repeat
|
||||
Result:=Result+L[i];
|
||||
P:=Pos('#',Result);
|
||||
If (P>0) then
|
||||
Result:=Copy(Result,1,P-1);
|
||||
Result:=Trim(Result);
|
||||
P:=Length(Result);
|
||||
If (P>0) and (Result[P]='\') then
|
||||
Result:=Copy(Result,1,P-1)
|
||||
else
|
||||
OK:=(Result<>'');
|
||||
if Not OK then
|
||||
Inc(I);
|
||||
Until OK or (I>L.Count-1);
|
||||
end;
|
||||
|
||||
Function SplitNamevalue(Const S : String; Var AName,AValue : String) : boolean;
|
||||
|
||||
var
|
||||
L : Integer;
|
||||
|
||||
begin
|
||||
L:=Pos('=',S);
|
||||
Result:=(L<>0);
|
||||
If Result then
|
||||
begin
|
||||
AName:=LowerCase(trim(Copy(S,1,L-1)));
|
||||
AValue:=S;
|
||||
Delete(AValue,1,L);
|
||||
AValue:=Trim(Avalue);
|
||||
end
|
||||
else
|
||||
begin
|
||||
AName:='';
|
||||
AValue:='';
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure TMakeFileConverter.StartPackage(Src : TStrings; Dir,OS : String);
|
||||
|
||||
Var
|
||||
S : String;
|
||||
|
||||
begin
|
||||
With Src do
|
||||
begin
|
||||
Add(' { ');
|
||||
Add(' '+FPackageName);
|
||||
Add(' } ');
|
||||
Add(' StartPackage('''+FPackageName+''');');
|
||||
If (Dir<>'') then
|
||||
Add(' Directory:='''+ExcludeTrailingPathDelimiter(Dir)+''';');
|
||||
If (OS<>'') and (OS<>'all') then
|
||||
Add(' OS:=['+OS+'];');
|
||||
If (FPackageVersion<>'') then
|
||||
Add(' Version:='''+FPackageVersion+''';');
|
||||
If (FPackageOptions<>'') then
|
||||
Add(' Options:='''+FPackageOptions+''';');
|
||||
If (FPackageDeps<>'') then
|
||||
begin
|
||||
S:=GetWord(FPackageDeps);
|
||||
While S<>'' do
|
||||
begin
|
||||
Add(' Dependencies.Add('''+S+''');');
|
||||
S:=GetWord(FPackageDeps);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMakeFileConverter.EndPackage(Src : TStrings; Dir,OS : String);
|
||||
|
||||
begin
|
||||
Src.add(' EndPackage;');
|
||||
FPackageName:='';
|
||||
FPackageVersion:='';
|
||||
FPackageOptions:='';
|
||||
FBuilDUnit:='';
|
||||
FPackageDeps:='';
|
||||
end;
|
||||
|
||||
|
||||
procedure TMakeFileConverter.DoPackageLine(Const S : String);
|
||||
|
||||
Var V,N : String;
|
||||
|
||||
begin
|
||||
SplitNameValue(S,N,V);
|
||||
If (N='name') then
|
||||
FPackageName:=V
|
||||
else If (N='version') then
|
||||
FPackageVersion:=V
|
||||
else If (N='main') then
|
||||
begin
|
||||
FPackageName:='sub';
|
||||
FSubName:=V;
|
||||
end
|
||||
else
|
||||
Writeln(StdErr,'Unknown name/value pair in package section :',N);
|
||||
end;
|
||||
|
||||
|
||||
{
|
||||
Convert various entries of type
|
||||
XXYY_OSN=words
|
||||
to entries of type
|
||||
prefix_word=OS1,OS2,OS3
|
||||
OS is never empty, 'all' is default.
|
||||
}
|
||||
Procedure AddStrings(Var L : TStrings; Values,Prefix,OS : String) ;
|
||||
|
||||
Var
|
||||
S,O : String;
|
||||
i : integer;
|
||||
|
||||
begin
|
||||
If (L=Nil) then
|
||||
L:=TstringList.Create;
|
||||
If prefix<>'' then
|
||||
prefix:=prefix+'_';
|
||||
S:=GetWord(Values);
|
||||
While (S<>'') do
|
||||
begin
|
||||
S:=Prefix+S;
|
||||
I:=L.IndexOfName(S);
|
||||
If (I<>-1) then
|
||||
begin
|
||||
O:=L.Values[S];
|
||||
If (O='all') then
|
||||
O:='';
|
||||
If (O<>'') then
|
||||
O:=O+',';
|
||||
O:=O+OS;
|
||||
L.Values[S]:=O;
|
||||
end
|
||||
else
|
||||
L.Add(S+'='+OS);
|
||||
S:=GetWord(Values);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure TMakeFileConverter.DoTargetLine(Line : String; Var T,R,D : TStrings);
|
||||
|
||||
Var
|
||||
V,N,OS : String;
|
||||
P : Integer;
|
||||
|
||||
begin
|
||||
SplitNameValue(Line,N,V);
|
||||
P:=Pos('_',N);
|
||||
If (P=0) then
|
||||
OS:='all'
|
||||
else
|
||||
begin
|
||||
OS:=N;
|
||||
Delete(OS,1,P);
|
||||
N:=Copy(N,1,P-1);
|
||||
end;
|
||||
If (N='dirs') then
|
||||
AddStrings(D,V,'',OS)
|
||||
else If (N='units') then
|
||||
AddStrings(T,V,'unit',OS)
|
||||
else If (N='implicitunits') then
|
||||
AddStrings(T,V,'unit',OS)
|
||||
else If (N='programs') then
|
||||
AddStrings(T,V,'program',OS)
|
||||
else If (N='examples') then
|
||||
AddStrings(T,V,'exampleunit',OS)
|
||||
else If (N='rsts') then
|
||||
AddStrings(R,V,'',OS)
|
||||
else
|
||||
Writeln(StdErr,'Unknown name/value pair in target section : ',Line);
|
||||
end;
|
||||
|
||||
procedure TMakeFileConverter.DoInstallLine(Line : String; Var IFL : TStrings);
|
||||
|
||||
Var
|
||||
S,V,N,OS : String;
|
||||
P : Integer;
|
||||
|
||||
begin
|
||||
SplitNameValue(Line,N,V);
|
||||
P:=Pos('_',N);
|
||||
If (P=0) then
|
||||
OS:='all'
|
||||
else
|
||||
begin
|
||||
OS:=N;
|
||||
Delete(OS,1,P);
|
||||
N:=Copy(N,1,P-1);
|
||||
end;
|
||||
If (N='fpcpackage') then
|
||||
P:=0 // temporary, needs fixing.
|
||||
else If (N='buildunit') then
|
||||
FBuildUnit:=V // temporary, needs fixing.
|
||||
else If (N='units') then
|
||||
begin
|
||||
S:=GetWord(V);
|
||||
While (S<>'') do
|
||||
begin
|
||||
AddStrings(IFL,S+'.o','',OS);
|
||||
AddStrings(IFL,S+'.ppu','',OS);
|
||||
S:=GetWord(V);
|
||||
end;
|
||||
end
|
||||
else
|
||||
Writeln(StdErr,'Unknown name/value pair in install section : ',N);
|
||||
end;
|
||||
|
||||
procedure TMakeFileConverter.DoCleanLine(Line : String; Var CFL : TStrings);
|
||||
|
||||
Var
|
||||
V,N,S,OS : String;
|
||||
P : Integer;
|
||||
|
||||
begin
|
||||
SplitNameValue(Line,N,V);
|
||||
P:=Pos('_',N);
|
||||
If (P=0) then
|
||||
OS:='all'
|
||||
else
|
||||
begin
|
||||
OS:=N;
|
||||
Delete(OS,1,P);
|
||||
N:=Copy(N,1,P-1);
|
||||
end;
|
||||
If (N='fpcpackage') then
|
||||
P:=0 // temporary, needs fixing.
|
||||
else If (N='units') then
|
||||
begin
|
||||
S:=GetWord(V);
|
||||
While (S<>'') do
|
||||
begin
|
||||
AddStrings(CFL,S+'.o','',OS);
|
||||
AddStrings(CFL,S+'.ppu','',OS);
|
||||
S:=GetWord(V);
|
||||
end;
|
||||
end
|
||||
else
|
||||
Writeln(StdErr,'Unknown name/value pair in clean section : ',N);
|
||||
end;
|
||||
|
||||
procedure TMakeFileConverter.DoRequireLine(Line : String);
|
||||
|
||||
Var
|
||||
V,N,OS : String;
|
||||
P : Integer;
|
||||
|
||||
begin
|
||||
SplitNameValue(Line,N,V);
|
||||
P:=Pos('_',N);
|
||||
If (P=0) then
|
||||
OS:='all'
|
||||
else
|
||||
begin
|
||||
OS:=N;
|
||||
Delete(OS,1,P);
|
||||
N:=Copy(N,1,P-1);
|
||||
end;
|
||||
if (N='packages') then
|
||||
FPackageDeps:=V
|
||||
else If (N='libc') and (Upcase(V)='Y') then
|
||||
P:=0 // Set options ?
|
||||
else
|
||||
Writeln(StdErr,'Unknown name/value pair in require section : ',N);
|
||||
end;
|
||||
|
||||
|
||||
procedure TMakeFileConverter.DoCompilerLine(Line : String;Var SD : TStrings);
|
||||
|
||||
Var
|
||||
V,N,OS : String;
|
||||
P : Integer;
|
||||
|
||||
begin
|
||||
SplitNameValue(Line,N,V);
|
||||
P:=Pos('_',N);
|
||||
If (P=0) then
|
||||
OS:='all'
|
||||
else
|
||||
begin
|
||||
OS:=N;
|
||||
Delete(OS,1,P);
|
||||
N:=Copy(N,1,P-1);
|
||||
end;
|
||||
If (N='includedir') then
|
||||
FPackageOptions:=Trim(FPackageOptions+' -Fi'+V)
|
||||
else If (N='options') then
|
||||
FPackageOptions:=Trim(FPackageOptions+' '+V)
|
||||
else If (N='targetdir') then
|
||||
P:=0 // Ignore
|
||||
else if (N='sourcedir') or (N='unitdir') then
|
||||
begin
|
||||
If (SD=Nil) then
|
||||
SD:=TStringList.Create;
|
||||
SD.Add(OS+'='+V);
|
||||
end
|
||||
else
|
||||
Writeln(StdErr,'Unknown name/value pair in compiler section : ',N);
|
||||
end;
|
||||
|
||||
Function SearchInDirs(Prefix,AName, Dirs : String) : string;
|
||||
|
||||
Var
|
||||
D,S : String;
|
||||
|
||||
begin
|
||||
S:=GetWord(Dirs);
|
||||
Result:='';
|
||||
While (Result='') and (S<>'') do
|
||||
begin
|
||||
D:=Prefix+S+PathDelim;
|
||||
If FileExists(D+AName+'.pp') or FileExists(D+AName+'.pas') then
|
||||
Result:=S;
|
||||
S:=GetWord(Dirs);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMakeFileConverter.DoTargets(Src,T,R,SD : TStrings; Dir,Prefix : String);
|
||||
|
||||
Var
|
||||
I,J,P : Integer;
|
||||
Pre,N,V,D,DOS,OS,CPU : String;
|
||||
Res : Boolean;
|
||||
|
||||
begin
|
||||
If (Dir<>'') then
|
||||
Dir:=IncludeTrailingPathDelimiter(Dir);
|
||||
If (Prefix<>'') then
|
||||
Prefix:=IncludeTrailingPathDelimiter(Prefix);
|
||||
Dir:=Prefix+Dir;
|
||||
Res:=False;
|
||||
If Assigned(T) then
|
||||
For I:=0 to T.Count-1 do
|
||||
begin
|
||||
T.GetNamevalue(I,N,V);
|
||||
P:=Pos('_',N);
|
||||
If (P<>0) then
|
||||
begin
|
||||
Pre:=Copy(N,1,P-1);
|
||||
Delete(N,1,P);
|
||||
end;
|
||||
If Assigned(R) then
|
||||
Res:=R.IndexOfName(N)<>-1;
|
||||
GetOSCPU(V,OS,CPU);
|
||||
Pre[1]:=Upcase(Pre[1]);
|
||||
Src.Add(' T:=Targets.Add'+Pre+'('''+Prefix+N+''');');
|
||||
If (CPU<>'') then
|
||||
Src.Add(' T.CPU:=['+CPU+'];');
|
||||
If (OS<>'') then
|
||||
Src.Add(' T.OS:=['+OS+'];');
|
||||
If res then
|
||||
Src.add(' T.ResourceStrings:=True;');
|
||||
If (CompareText(FBuildUnit,N)=0) then
|
||||
Src.add(' T.Install:=False;');
|
||||
if Assigned(SD) then
|
||||
for J:=0 to SD.Count-1 do
|
||||
begin
|
||||
SD.GetNameValue(J,DOS,D);
|
||||
If (DOS<>'all') then
|
||||
Src.Add(' if (Defaults.OS='+DOS+') then');
|
||||
Src.add(' T.Directory:='''+SearchInDirs(Dir,N,D)+''';');
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMakeFileConverter.WriteOSCPUCheck(Src: TStrings;OS,CPU : String);
|
||||
|
||||
Var
|
||||
S : String;
|
||||
|
||||
begin
|
||||
If (CPU<>'') then
|
||||
S:='(Defaults.CPU='+CPU+')';
|
||||
If (OS<>'') then
|
||||
begin
|
||||
IF (S<>'') then
|
||||
S:=S+' OR ';
|
||||
S:=S+'(Defaults.OS='+CPU+')';
|
||||
end;
|
||||
If (S<>'') then
|
||||
Src.Add(' If '+S+' then');
|
||||
end;
|
||||
|
||||
procedure TMakeFileConverter.DoInstalls(Src,IFL : TStrings);
|
||||
|
||||
Var
|
||||
I,J,P : Integer;
|
||||
Pre,N,V,D,DOS,OS,CPU : String;
|
||||
|
||||
begin
|
||||
If Assigned(IFL) then
|
||||
For I:=0 to IFL.Count-1 do
|
||||
begin
|
||||
IFL.GetNamevalue(I,N,V);
|
||||
GetOSCPU(V,OS,CPU);
|
||||
WriteOSCPUCheck(Src,OS,CPU);
|
||||
Src.add(' InstallFiles.Add('''+N+''');');
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMakeFileConverter.DoCleans(Src,CFL : TStrings);
|
||||
|
||||
Var
|
||||
I,J,P : Integer;
|
||||
N,V,DOS,OS,CPU : String;
|
||||
|
||||
|
||||
begin
|
||||
If Assigned(CFL) then
|
||||
For I:=0 to CFL.Count-1 do
|
||||
begin
|
||||
CFL.GetNamevalue(I,N,V);
|
||||
GetOSCPU(V,OS,CPU);
|
||||
WriteOSCPUCheck(Src,OS,CPU);
|
||||
Src.add(' CleanFiles.Add('''+N+''');');
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
procedure TMakeFileConverter.ConvertFile(const AFileName: String; Src: TStrings; Dir,OS : String);
|
||||
|
||||
Function IsSection(var S : String) : Boolean;
|
||||
|
||||
Var
|
||||
L : Integer;
|
||||
|
||||
begin
|
||||
L:=Length(S);
|
||||
Result:=(L>0) and (S[1]='[') and (S[L]=']');
|
||||
If Result then
|
||||
S:=trim(Copy(S,2,L-2));
|
||||
end;
|
||||
|
||||
Var
|
||||
R,L,T,D,S,SD,IFL,CFL : TStrings;
|
||||
I,J : Integer;
|
||||
Prefix,Line,DN : String;
|
||||
B : Boolean;
|
||||
|
||||
begin
|
||||
Writeln('Converting '+AFileName);
|
||||
T:=Nil;
|
||||
D:=Nil;
|
||||
S:=Nil;
|
||||
SD:=Nil;
|
||||
R:=Nil;
|
||||
IFL:=Nil;
|
||||
CFL:=Nil;
|
||||
FPackageOptions:='';
|
||||
FPackageDir:='';
|
||||
L:=TStringList.Create;
|
||||
try
|
||||
L.LoadFromFile(AFileName);
|
||||
I:=0;
|
||||
While (I<L.Count) do
|
||||
begin
|
||||
Line:=GetLine(L,I);
|
||||
If IsSection(Line) then
|
||||
begin
|
||||
J:=GetEnumValue(TypeInfo(TSectionType),'st'+Line);
|
||||
If (J=-1) then
|
||||
begin
|
||||
FSection:=stNone;
|
||||
Writeln(stdErr,'Unsupported section: ',Line);
|
||||
end
|
||||
else
|
||||
FSection:=TSectiontype(J);
|
||||
end
|
||||
else
|
||||
case FSection of
|
||||
stPackage : DoPackageLine(Line);
|
||||
stTarget : DoTargetLine(Line,T,R,D);
|
||||
stInstall : DoInstallLine(Line,IFL);
|
||||
stClean : DoCleanLine(Line,CFL);
|
||||
stCompiler : DoCompilerLine(Line,SD);
|
||||
strequire : DoRequireLine(Line);
|
||||
end;
|
||||
inc(I);
|
||||
end;
|
||||
// If there are only 'dir' entries, then there is no package name.
|
||||
B:=False;
|
||||
if (FPackageName<>'') then
|
||||
begin
|
||||
Prefix:='';
|
||||
B:=FPackageName<>'sub';
|
||||
If B then
|
||||
StartPackage(Src,Dir,OS)
|
||||
else
|
||||
Prefix:=Dir;
|
||||
DoTargets(Src,T,R,SD,Dir,Prefix);
|
||||
DoInstalls(Src,IFL);
|
||||
DoCleans(Src,CFL);
|
||||
end;
|
||||
If Assigned(D) then
|
||||
begin
|
||||
If (Dir<>'') then
|
||||
Dir:=IncludeTrailingPathDelimiter(Dir);
|
||||
For I:=0 to D.Count-1 do
|
||||
begin
|
||||
D.GetNameValue(I,DN,Line);
|
||||
If (Line<>'all') and (Line<>'') then
|
||||
OS:=Line;
|
||||
DN:=Dir+DN+PathDelim;
|
||||
If FileExists(DN+'Makefile.fpc') then
|
||||
ConvertFile(DN+'Makefile.fpc',Src,DN,OS);
|
||||
end;
|
||||
end;
|
||||
If B then
|
||||
EndPackage(Src,Dir,OS);
|
||||
Finally
|
||||
S.Free;
|
||||
IFL.Free;
|
||||
CFL.Free;
|
||||
D.Free;
|
||||
SD.Free;
|
||||
T.Free;
|
||||
L.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMakeFileConverter.ConvertFile(const Source, Dest: String);
|
||||
|
||||
Var
|
||||
L : TStrings;
|
||||
|
||||
begin
|
||||
L:=TStringList.Create;
|
||||
Try
|
||||
StartInstaller(L);
|
||||
ConvertFile(Source,L,'','');
|
||||
EndInstaller(L);
|
||||
L.SaveToFile(Dest);
|
||||
Finally
|
||||
L.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TMakeTool }
|
||||
|
||||
procedure TMakeTool.CompileFPMake(Extra: Boolean);
|
||||
|
||||
Var
|
||||
O,C : String;
|
||||
|
||||
begin
|
||||
C:=GetCompiler;
|
||||
O:=FFPmakeSrc;
|
||||
If Extra then
|
||||
O:='-Fafpmakeex '+O;
|
||||
Log(SLogCompilingFPMake+C+' '+O);
|
||||
If ExecuteProcess(C,O)<>0 then
|
||||
Error(SErrFailedToCompileFPCMake)
|
||||
end;
|
||||
|
||||
procedure TMakeTool.CreateFPMake;
|
||||
begin
|
||||
Log(SLogGeneratingFPMake);
|
||||
With TMakeFileConverter.Create do
|
||||
try
|
||||
ConvertFile('Makefile.fpc','fpmake.pp');
|
||||
finally
|
||||
Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
Function TMakeTool.RunFPMake : Integer;
|
||||
|
||||
Function MaybeQuote(Const S : String) : String;
|
||||
|
||||
begin
|
||||
If Pos(' ',S)=0 then
|
||||
Result:=S
|
||||
else
|
||||
Result:='"'+S+'"';
|
||||
end;
|
||||
|
||||
|
||||
Var
|
||||
I : integer;
|
||||
D,O : String;
|
||||
|
||||
begin
|
||||
Log(SLogRunningFPMake);
|
||||
D:=IncludeTrailingPathDelimiter(GetCurrentDir);
|
||||
O:='';
|
||||
For I:=1 to ParamCount do
|
||||
begin
|
||||
If (O<>'') then
|
||||
O:=O+' ';
|
||||
O:=O+MaybeQuote(ParamStr(I));
|
||||
end;
|
||||
Result:=ExecuteProcess(D+FFPMakeBin,O);
|
||||
end;
|
||||
|
||||
procedure TMakeTool.Log(Msg: String);
|
||||
begin
|
||||
If FLogging then
|
||||
Writeln(stdErr,Msg);
|
||||
end;
|
||||
|
||||
procedure TMakeTool.Error(Msg: String);
|
||||
begin
|
||||
Raise EMakeToolError.Create(Msg);
|
||||
end;
|
||||
|
||||
procedure TMakeTool.Error(Fmt: String; Args: array of const);
|
||||
begin
|
||||
Raise EMakeToolError.CreateFmt(Fmt,Args);
|
||||
end;
|
||||
|
||||
function TMakeTool.GetCompiler: String;
|
||||
begin
|
||||
If (FCompiler='') then
|
||||
begin
|
||||
{$if defined(cpui386)}
|
||||
FCompiler:='ppc386';
|
||||
{$elseif defined(cpuAlpha)}
|
||||
FCompiler:='ppcaxp';
|
||||
{$elseif defined(cpusparc)}
|
||||
FCompiler:='ppcsparc';
|
||||
{$elseif defined(cpuarm)}
|
||||
FCompiler:='ppcarm';
|
||||
{$elseif defined(cpum68k)}
|
||||
FCompiler:='ppcm68k';
|
||||
{$elseif defined(cpupowerpc)}
|
||||
FCompiler:='ppcppc';
|
||||
{$else}
|
||||
{$Fatal Unknown architecture}
|
||||
{$endif}
|
||||
end;
|
||||
If (ExtractFilePath(FCompiler)<>'') then
|
||||
Result:=FCompiler
|
||||
else
|
||||
begin
|
||||
Result:=FileSearch(FCompiler,GetEnvironmentVariable('PATH'));
|
||||
If (Result='') then
|
||||
Result:=FCompiler;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure TMakeTool.ProcessCommandLine;
|
||||
|
||||
Function CheckOption(Index : Integer;Short,Long : String): Boolean;
|
||||
|
||||
var
|
||||
O : String;
|
||||
|
||||
begin
|
||||
O:=Paramstr(Index);
|
||||
Result:=(O='-'+short) or (O='--'+long) or (copy(O,1,Length(Long)+3)=('--'+long+'='));
|
||||
end;
|
||||
|
||||
Function OptionArg(Var Index : Integer) : String;
|
||||
|
||||
Var
|
||||
P : Integer;
|
||||
|
||||
begin
|
||||
if (Length(ParamStr(Index))>1) and (Paramstr(Index)[2]<>'-') then
|
||||
begin
|
||||
If Index<ParamCount then
|
||||
begin
|
||||
Inc(Index);
|
||||
Result:=Paramstr(Index);
|
||||
end
|
||||
else
|
||||
Error(SErrNeedArgument,[Index,ParamStr(Index)]);
|
||||
end
|
||||
else If length(ParamStr(Index))>2 then
|
||||
begin
|
||||
P:=Pos('=',Paramstr(Index));
|
||||
If (P=0) then
|
||||
Error(SErrNeedArgument,[Index,ParamStr(Index)])
|
||||
else
|
||||
begin
|
||||
Result:=Paramstr(Index);
|
||||
Delete(Result,1,P);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
Var
|
||||
I : Integer;
|
||||
|
||||
begin
|
||||
I:=0;
|
||||
FLogging:=False;
|
||||
FRunMode:=rmhelp;
|
||||
FConvertOnly:=False;
|
||||
While (I<ParamCount) do
|
||||
begin
|
||||
Inc(I);
|
||||
if Checkoption(I,'n','convert') then
|
||||
FConvertOnly:=True
|
||||
else if Checkoption(I,'m','compile') then
|
||||
FRunMode:=rmCompile
|
||||
else if Checkoption(I,'b','build') then
|
||||
FRunMode:=rmBuild
|
||||
else if CheckOption(I,'i','install') then
|
||||
FRunMode:=rmInstall
|
||||
else if CheckOption(I,'c','clean') then
|
||||
FRunMode:=rmClean
|
||||
else if CheckOption(I,'a','archive') then
|
||||
FRunMode:=rmarchive
|
||||
else if CheckOption(I,'d','download') then
|
||||
FRunMode:=rmDownload
|
||||
else if CheckOption(I,'h','help') then
|
||||
FRunMode:=rmhelp
|
||||
// Check.
|
||||
else if CheckOption(I,'r','compiler') then
|
||||
FCompiler:=OptionArg(I)
|
||||
else if CheckOption(I,'v','verbose') then
|
||||
Flogging:=Pos('info',Lowercase(OptionArg(I)))<>0;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure TMakeTool.Run;
|
||||
|
||||
|
||||
begin
|
||||
Try
|
||||
ProcessCommandLine;
|
||||
If FConvertOnly then
|
||||
CreateFPMake
|
||||
else
|
||||
begin
|
||||
FHaveMakefile:=FileExists('Makefile.fpc');
|
||||
FFPMakeSrc:='fpmake.pp';
|
||||
FHaveFpmake:=FileExists(FFPMakeSrc);
|
||||
If Not FHaveFPMake then
|
||||
begin
|
||||
FHaveFPMake:=FileExists('fpmake.pas');
|
||||
If FHaveFPMake then
|
||||
FFPMakeSrc:='fpmake.pas';
|
||||
end;
|
||||
if Not (FHaveFPMake or FHaveMakeFile) then
|
||||
Error(SErrMissingConfig);
|
||||
If (Not FHaveFPMake) or (FileAge(FFPMakeSrc)<FileAge('Makefile.fpc')) then
|
||||
CreateFPMake;
|
||||
{$ifndef unix}
|
||||
FFPMakeBin:='fpmake.exe';
|
||||
{$else}
|
||||
FFPMakeBin:='fpmake';
|
||||
{$endif}
|
||||
if FileAge(FFPMakeBin)<FileAge(FFPMakeSrc) then
|
||||
CompileFPMake(FRunMode in [rmArchive,rmDownload]);
|
||||
Halt(RunFPMake);
|
||||
end;
|
||||
except
|
||||
On E : Exception do
|
||||
begin
|
||||
Writeln(StdErr,Format(SErrRunning,[E.Message]));
|
||||
Halt(1);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
begin
|
||||
With TMakeTool.Create do
|
||||
try
|
||||
run;
|
||||
finally
|
||||
Free;
|
||||
end;
|
||||
end.
|
||||
|
||||
2779
rtl/common/fpmkunit.pp
Normal file
2779
rtl/common/fpmkunit.pp
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user