reiniero avatar reiniero committed 336b1b9

mips: fix looking in right dirs. Started refactoring crosscompile code, starting with mips

Comments (0)

Files changed (5)

         <PackageName Value="LCL"/>
       </Item2>
     </RequiredPackages>
-    <Units Count="33">
+    <Units Count="34">
       <Unit0>
         <Filename Value="fpcup.lpr"/>
         <IsPartOfProject Value="True"/>
         <IsPartOfProject Value="True"/>
         <UnitName Value="m_win32_to_wincearm"/>
       </Unit32>
+      <Unit33>
+        <Filename Value="m_linux386_to_mips.pas"/>
+        <IsPartOfProject Value="True"/>
+        <UnitName Value="m_linux386_to_mips"/>
+      </Unit33>
     </Units>
   </ProjectOptions>
   <CompilerOptions>

Binary file modified.

m_crossinstaller.pas

 interface
 
 uses
-  Classes, SysUtils;
+  Classes, SysUtils,fpcuputil;
 
 type
 
   protected
     FBinUtilsPath: string; //the cross compile binutils (as, ld etc). Could be the same as regular path if a binutils prefix is used.
     FBinUtilsPrefix: string; //can be empty, if a prefix is used to separate binutils for different archs in the same directory, use it
+    FCrossModuleName: string; //used for identifying module to user in messages
     FFPCCFGSnippet: string;
     FLibsPath: string; //path for target environment libraries
     FTargetCPU: string; //cpu for the target environment. Follows FPC names
     FTargetOS: string; //operating system for the target environment. Follows FPC names
+    // Sets FBinutilspath if AsFile found in Directory. Returns true if found.
+    function SearchBinUtil(Directory, AsFile: string): boolean;
   public
     // In your descendent, implement this function: you can download libraries or check for their existence for normal cross compile libs:
     function GetLibs(Basepath:string):boolean;virtual; abstract;
   CrossInstallers.AddObject(Platform,TObject(Extension));
 end;
 
+function TCrossInstaller.SearchBinUtil(Directory, AsFile: string): boolean;
+begin
+  FBinUtilsPath:=ExcludeTrailingPathDelimiter(ExpandFileName(Directory));
+  result:=FileExists(IncludeTrailingPathDelimiter(FBinUtilsPath)+AsFile);
+  if not result then
+    infoln(FCrossModuleName + ': failed: searching binutil '+AsFile+
+      ' in directory '+FBinUtilsPath, etInfo);
+end;
+
 constructor TCrossInstaller.Create;
 begin
   // Help ensure our implementers do the right thing with the variables

m_linux386_to_mips.pas

 begin
   //todo: factor these path finding repetitions into a function (in the parent class?)
   AsFile:=FBinUtilsPrefix+'as';
-  FBinUtilsPath:=IncludeTrailingPathDelimiter(BasePath)+'bin'+DirectorySeparator+DirName;
-  result:=FileExists(FBinUtilsPath+DirectorySeparator+AsFile);
-  if not result then
-  begin
-    // Show path info etc so the user can fix his setup if errors occur
-    infoln(CrossModuleName + ': failed: searched binutil '+AsFile+' in directory '+FBinUtilsPath,etInfo);
-    //todo: fix fallback to separate dir; use real argument from command line to control it
-    FBinUtilsPath:=ExpandFileName(IncludeTrailingPathDelimiter(BasePath)+'..\cross\bin\'+DirName);
-    result:=FileExists(FBinUtilsPath+DirectorySeparator+AsFile);
-    if not result then
-      infoln(CrossModuleName + ': failed: searched binutil '+AsFile+' in directory '+FBinUtilsPath,etInfo);
-  end;
+  result:=false;
 
-  // Try /usr/local/bin/mipsel-linux
-  if not result then
-  begin
-    FBinUtilsPath:='/usr/local/bin/'+DirectorySeparator+DirName;
-    result:=FileExists(FBinUtilsPath+DirectorySeparator+AsFile);
-    if not result then
-      infoln(CrossModuleName + ': failed: searched binutil '+AsFile+' in directory '+FBinUtilsPath,etInfo);
-  end;
+  if not result then { try $(fpcdir)/bin/<dirprefix>/ }
+    result:=SearchBinUtil(IncludeTrailingPathDelimiter(BasePath)+'bin'+DirectorySeparator+DirName,
+      AsFile);
 
-  // Try /usr/local/bin/
-  if not result then
-  begin
-    FBinUtilsPath:='/usr/local/bin';
-    result:=FileExists(FBinUtilsPath+DirectorySeparator+AsFile);
-    if not result then
-      infoln(CrossModuleName + ': failed: searched binutil '+AsFile+' in directory '+FBinUtilsPath,etInfo);
-  end;
+  if not result then { try cross/bin/<dirprefix>/ }
+    result:=SearchBinUtil(IncludeTrailingPathDelimiter(BasePath)+'..\cross\bin\'+DirName,
+      AsFile);
+
+  if not result then { try /usr/local/bin/<dirprefix>/ }
+    result:=SearchBinUtil('/usr/local/bin/'+DirName,
+      AsFile);
+
+  if not result then { try /usr/local/bin/ }
+    result:=SearchBinUtil('/usr/local/bin',
+      AsFile);
 
   if result then
   begin
     FFPCCFGSnippet:=FFPCCFGSnippet+LineEnding+
     '-FD'+IncludeTrailingPathDelimiter(FBinUtilsPath)+LineEnding+ {search this directory for compiler utilities}
     '-XP'+FBinUtilsPrefix+LineEnding {Prepend the binutils names};
-    infoln(CrossModuleName + ': found binutil '+AsFile+' in directory '+FBinUtilsPath,etInfo);
+    infoln(FCrossModuleName + ': found binutil '+AsFile+' in directory '+FBinUtilsPath,etInfo);
   end;
 end;
 

m_linux386_to_mipsel.pas

   Classes, SysUtils, m_crossinstaller,fpcuputil;
 
 implementation
-const
-  CrossModuleName='TLinux386_mipsel';
+
 
 type
 
   if not result then
   begin
     // Show path info etc so the user can fix his setup if errors occur
-    infoln(CrossModuleName + ': failed: searched libspath '+FLibsPath,etInfo);
+    infoln(FCrossModuleName + ': failed: searched libspath '+FLibsPath,etInfo);
     FLibsPath:=ExpandFileName(IncludeTrailingPathDelimiter(BasePath)+'..'+DirectorySeparator+
       'cross'+DirectorySeparator+
       'lib'+DirectorySeparator+
       DirName);
     result:=DirectoryExists(FLibsPath);
     if not result then
-      infoln(CrossModuleName + ': failed: searched libspath '+FLibsPath,etInfo);
+      infoln(FCrossModuleName + ': failed: searched libspath '+FLibsPath,etInfo);
   end;
   if result then
   begin
     '-Fl'+IncludeTrailingPathDelimiter(FLibsPath)+LineEnding+ {buildfaq 1.6.4/3.3.1: the directory to look for the target  libraries}
     '-Xr/usr/lib'+LineEnding+ {buildfaq 3.3.1: makes the linker create the binary so that it searches in the specified directory on the target system for libraries}
     '-FL/usr/lib/ld-linux.so.2' {buildfaq 3.3.1: the name of the dynamic linker on the target};
-    infoln(CrossModuleName + ': found libspath '+FLibsPath,etInfo);
+    infoln(FCrossModuleName + ': found libspath '+FLibsPath,etInfo);
   end;
 end;
 
 begin
   //todo: factor these path finding repetitions into a function (in the parent class?)
   AsFile:=FBinUtilsPrefix+'as';
-  FBinUtilsPath:=IncludeTrailingPathDelimiter(BasePath)+'bin'+DirectorySeparator+DirName;
-  result:=FileExists(FBinUtilsPath+DirectorySeparator+AsFile);
-  if not result then
-  begin
-    // Show path info etc so the user can fix his setup if errors occur
-    infoln(CrossModuleName + ': failed: searched binutil '+AsFile+' in directory '+FBinUtilsPath,etInfo);
-    //todo: fix fallback to separate dir; use real argument from command line to control it
-    FBinUtilsPath:=ExpandFileName(IncludeTrailingPathDelimiter(BasePath)+'..\cross\bin\'+DirName);
-    result:=FileExists(FBinUtilsPath+DirectorySeparator+AsFile);
-    if not result then
-      infoln(CrossModuleName + ': failed: searched binutil '+AsFile+' in directory '+FBinUtilsPath,etInfo);
-  end;
+  result:=false;
 
-  // Try /usr/local/bin/mipsel-linux
-  if not result then
-  begin
-    FBinUtilsPath:='/usr/local/bin/'+DirectorySeparator+DirName;
-    result:=FileExists(FBinUtilsPath+DirectorySeparator+AsFile);
-    if not result then
-      infoln(CrossModuleName + ': failed: searched binutil '+AsFile+' in directory '+FBinUtilsPath,etInfo);
-  end;
+  if not result then { try $(fpcdir)/bin/<dirprefix>/ }
+    result:=SearchBinUtil(IncludeTrailingPathDelimiter(BasePath)+'bin'+DirectorySeparator+DirName,
+      AsFile);
 
-  // Try /usr/local/bin/
-  if not result then
-  begin
-    FBinUtilsPath:='/usr/local/bin';
-    result:=FileExists(FBinUtilsPath+DirectorySeparator+AsFile);
-    if not result then
-      infoln(CrossModuleName + ': failed: searched binutil '+AsFile+' in directory '+FBinUtilsPath,etInfo);
-  end;
+  if not result then { try cross/bin/<dirprefix>/ }
+    result:=SearchBinUtil(IncludeTrailingPathDelimiter(BasePath)+'..\cross\bin\'+DirName,
+      AsFile);
+
+  if not result then { try /usr/local/bin/<dirprefix>/ }
+    result:=SearchBinUtil('/usr/local/bin/'+DirName,
+      AsFile);
+
+  if not result then { try /usr/local/bin/ }
+    result:=SearchBinUtil('/usr/local/bin',
+      AsFile);
 
   if result then
   begin
     FFPCCFGSnippet:=FFPCCFGSnippet+LineEnding+
     '-FD'+IncludeTrailingPathDelimiter(FBinUtilsPath)+LineEnding+ {search this directory for compiler utilities}
     '-XP'+FBinUtilsPrefix+LineEnding {Prepend the binutils names};
-    infoln(CrossModuleName + ': found binutil '+AsFile+' in directory '+FBinUtilsPath,etInfo);
+    infoln(FCrossModuleName + ': found binutil '+AsFile+' in directory '+FBinUtilsPath,etInfo);
   end;
 end;
 
   inherited Create;
   FBinUtilsPrefix:='mipsel-linux-';
   FBinUtilsPath:='';
+  FCrossModuleName:='TLinux386_mipsel'; //used in messages to user
   FFPCCFGSnippet:='';
   FLibsPath:='';
   FTargetCPU:='mipsel';
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.