|
@@ -24,15 +24,21 @@ uses
|
|
procedure CheckSourceName(const Filename: string);
|
|
procedure CheckSourceName(const Filename: string);
|
|
procedure CommentShebang(Src: TStringList);
|
|
procedure CommentShebang(Src: TStringList);
|
|
function GetCacheDir: string;
|
|
function GetCacheDir: string;
|
|
|
|
+procedure SetCacheDir(AValue : string);
|
|
function IsCacheValid(Src: TStringList;
|
|
function IsCacheValid(Src: TStringList;
|
|
const CachedSrcFile, CachedExeFile: string): boolean;
|
|
const CachedSrcFile, CachedExeFile: string): boolean;
|
|
procedure Compile(const CacheFilename, OutputFilename: string);
|
|
procedure Compile(const CacheFilename, OutputFilename: string);
|
|
function GetCompiler: string;
|
|
function GetCompiler: string;
|
|
|
|
+procedure SetCompiler(AValue : string);
|
|
function GetCompilerParameters(const SrcFilename, OutputFilename: string): string;
|
|
function GetCompilerParameters(const SrcFilename, OutputFilename: string): string;
|
|
procedure Run(const Filename: string);
|
|
procedure Run(const Filename: string);
|
|
|
|
|
|
implementation
|
|
implementation
|
|
|
|
|
|
|
|
+Var
|
|
|
|
+ CmdCacheDir : String;
|
|
|
|
+ CmdCompiler : String;
|
|
|
|
+
|
|
procedure AddParam(p: string; var Line: string);
|
|
procedure AddParam(p: string; var Line: string);
|
|
begin
|
|
begin
|
|
if p='' then exit;
|
|
if p='' then exit;
|
|
@@ -71,14 +77,26 @@ begin
|
|
Src[0]:=copy(Line,1,i-1)+'//'+copy(Line,i,length(Line));
|
|
Src[0]:=copy(Line,1,i-1)+'//'+copy(Line,i,length(Line));
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+
|
|
|
|
+procedure SetCacheDir(AValue : string);
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ CmdCacheDir:=AValue;
|
|
|
|
+end;
|
|
|
|
+
|
|
function GetCacheDir: string;
|
|
function GetCacheDir: string;
|
|
begin
|
|
begin
|
|
- Result:=GetEnvironmentVariable('INSTANTFPCCACHE');
|
|
|
|
- if Result='' then begin
|
|
|
|
- Result:=GetEnvironmentVariable('HOME');
|
|
|
|
- if Result<>'' then
|
|
|
|
- Result:=IncludeTrailingPathDelimiter(Result)+'.cache'+PathDelim+'instantfpc';
|
|
|
|
- end;
|
|
|
|
|
|
+ Result:=CmdCacheDir;
|
|
|
|
+ if (Result='') then
|
|
|
|
+ begin
|
|
|
|
+ Result:=GetEnvironmentVariable('INSTANTFPCCACHE');
|
|
|
|
+ if Result='' then
|
|
|
|
+ begin
|
|
|
|
+ Result:=GetEnvironmentVariable('HOME');
|
|
|
|
+ if Result<>'' then
|
|
|
|
+ Result:=IncludeTrailingPathDelimiter(Result)+'.cache'+PathDelim+'instantfpc';
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
if Result='' then begin
|
|
if Result='' then begin
|
|
writeln('missing environment variable: HOME or INSTANTFPCCACHE');
|
|
writeln('missing environment variable: HOME or INSTANTFPCCACHE');
|
|
Halt(1);
|
|
Halt(1);
|
|
@@ -113,9 +131,14 @@ begin
|
|
{$ENDIF}
|
|
{$ENDIF}
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure SetCompiler(AValue : string);
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ CmdCompiler:=AValue;
|
|
|
|
+end;
|
|
|
|
+
|
|
function GetCompiler: string;
|
|
function GetCompiler: string;
|
|
-const
|
|
|
|
- CompilerParam = '--compiler=';
|
|
|
|
|
|
+
|
|
var
|
|
var
|
|
Path: String;
|
|
Path: String;
|
|
p: Integer;
|
|
p: Integer;
|
|
@@ -124,28 +147,28 @@ var
|
|
CompFile: String;
|
|
CompFile: String;
|
|
i: Integer;
|
|
i: Integer;
|
|
Param: String;
|
|
Param: String;
|
|
|
|
+
|
|
begin
|
|
begin
|
|
- for i:=1 to Paramcount do begin
|
|
|
|
- Param:=ParamStr(i);
|
|
|
|
- if (Param='') or (Param[1]<>'-') then break;
|
|
|
|
- if copy(Param,1,length(CompilerParam))=CompilerParam then begin
|
|
|
|
- CompFile:=copy(Param,length(CompilerParam)+1,length(Param));
|
|
|
|
- Result:=ExpandFileName(CompFile);
|
|
|
|
- if not FileExists(Result) then begin
|
|
|
|
- writeln('Error: '+CompFile+' not found, check the ',CompilerParam,' parameter.');
|
|
|
|
- Halt(1);
|
|
|
|
|
|
+ Result:=CmdCompiler;
|
|
|
|
+ if (Result<>'') then
|
|
|
|
+ begin
|
|
|
|
+ Result:=ExpandFileName(Result);
|
|
|
|
+ if not FileExists(Result) then
|
|
|
|
+ begin
|
|
|
|
+ writeln('Error: '+Result+' not found, check the --compiler parameter.');
|
|
|
|
+ Halt(1);
|
|
end;
|
|
end;
|
|
- exit;
|
|
|
|
|
|
+ exit;
|
|
end;
|
|
end;
|
|
- end;
|
|
|
|
|
|
|
|
{$IFDEF Windows}
|
|
{$IFDEF Windows}
|
|
CompFile:='fpc.exe';
|
|
CompFile:='fpc.exe';
|
|
{$ELSE}
|
|
{$ELSE}
|
|
CompFile:='fpc';
|
|
CompFile:='fpc';
|
|
{$ENDIF}
|
|
{$ENDIF}
|
|
|
|
+ Result:=ExeSearch(CompFile);
|
|
Path:=GetEnvironmentVariable('PATH');
|
|
Path:=GetEnvironmentVariable('PATH');
|
|
- if PATH<>'' then begin
|
|
|
|
|
|
+{ if PATH<>'' then begin
|
|
p:=1;
|
|
p:=1;
|
|
while p<=length(Path) do begin
|
|
while p<=length(Path) do begin
|
|
StartPos:=p;
|
|
StartPos:=p;
|
|
@@ -158,8 +181,12 @@ begin
|
|
inc(p);
|
|
inc(p);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
- writeln('Error: '+CompFile+' not found in PATH');
|
|
|
|
- Halt(1);
|
|
|
|
|
|
+}
|
|
|
|
+ if (Result='') then
|
|
|
|
+ begin
|
|
|
|
+ writeln('Error: '+CompFile+' not found in PATH');
|
|
|
|
+ Halt(1);
|
|
|
|
+ end;
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure Compile(const CacheFilename, OutputFilename: string);
|
|
procedure Compile(const CacheFilename, OutputFilename: string);
|
|
@@ -204,13 +231,17 @@ function GetCompilerParameters(const SrcFilename, OutputFilename: string): strin
|
|
}
|
|
}
|
|
var
|
|
var
|
|
p: String;
|
|
p: String;
|
|
|
|
+ i : integer;
|
|
begin
|
|
begin
|
|
Result:='';
|
|
Result:='';
|
|
- if (Paramcount>0) then begin
|
|
|
|
- p:=ParamStr(1);
|
|
|
|
- if (p<>'') and (p[1]='-') then
|
|
|
|
- Result:=p; // copy compile params from the script
|
|
|
|
- end;
|
|
|
|
|
|
+ I:=1;
|
|
|
|
+ While (I<=ParamCount) and (Copy(ParamStr(i),1,1)='-') do
|
|
|
|
+ begin
|
|
|
|
+ p:=ParamStr(i);
|
|
|
|
+ if (Copy(p,1,1)='-') and (copy(p,1,2)<>'--') then
|
|
|
|
+ AddParam(P,Result);
|
|
|
|
+ inc(I);
|
|
|
|
+ end;
|
|
AddParam('-o'+OutputFilename {$IFDEF HASEXEEXT} + '.exe' {$ENDIF},Result);
|
|
AddParam('-o'+OutputFilename {$IFDEF HASEXEEXT} + '.exe' {$ENDIF},Result);
|
|
AddParam(SrcFilename,Result);
|
|
AddParam(SrcFilename,Result);
|
|
end;
|
|
end;
|