Browse Source

* Enabling crosscompiling from Windows towards Darwin. Patch from Alfred (mantis 31099). Thanks! :)

git-svn-id: trunk@36168 -
maciej-izak 8 years ago
parent
commit
fa75f25fac
1 changed files with 68 additions and 17 deletions
  1. 68 17
      compiler/systems/t_bsd.pas

+ 68 - 17
compiler/systems/t_bsd.pas

@@ -147,8 +147,8 @@ begin
        begin
        begin
          if not(target_info.system in systems_darwin) then
          if not(target_info.system in systems_darwin) then
            begin
            begin
-             ExeCmd[1]:='ld $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -L. -o $EXE $CATRES';
-             DllCmd[1]:='ld $TARGET $EMUL $OPT -shared -L. -o $EXE $CATRES'
+             ExeCmd[1]:='ld $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -L. -o $EXE $CATRES $FILELIST';
+             DllCmd[1]:='ld $TARGET $EMUL $OPT -shared -L. -o $EXE $CATRES $FILELIST'
            end
            end
          else
          else
            begin
            begin
@@ -167,16 +167,16 @@ begin
                programs with problems that require Valgrind will have more
                programs with problems that require Valgrind will have more
                than 60KB of data (first 4KB of address space is always invalid)
                than 60KB of data (first 4KB of address space is always invalid)
              }
              }
-               ExeCmd[1]:='ld $PRTOBJ $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -multiply_defined suppress -L. -o $EXE $CATRES';
+               ExeCmd[1]:='ld $PRTOBJ $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -multiply_defined suppress -L. -o $EXE $CATRES $FILELIST';
              if not(cs_gdb_valgrind in current_settings.globalswitches) then
              if not(cs_gdb_valgrind in current_settings.globalswitches) then
                ExeCmd[1]:=ExeCmd[1]+' -pagezero_size 0x10000';
                ExeCmd[1]:=ExeCmd[1]+' -pagezero_size 0x10000';
 {$else ndef cpu64bitaddr}
 {$else ndef cpu64bitaddr}
-             ExeCmd[1]:='ld $PRTOBJ $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -multiply_defined suppress -L. -o $EXE $CATRES';
+             ExeCmd[1]:='ld $PRTOBJ $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -multiply_defined suppress -L. -o $EXE $CATRES $FILELIST';
 {$endif ndef cpu64bitaddr}
 {$endif ndef cpu64bitaddr}
              if (apptype<>app_bundle) then
              if (apptype<>app_bundle) then
-               DllCmd[1]:='ld $PRTOBJ $TARGET $EMUL $OPT $GCSECTIONS -dynamic -dylib -multiply_defined suppress -L. -o $EXE $CATRES'
+               DllCmd[1]:='ld $PRTOBJ $TARGET $EMUL $OPT $GCSECTIONS -dynamic -dylib -multiply_defined suppress -L. -o $EXE $CATRES $FILELIST'
              else
              else
-               DllCmd[1]:='ld $PRTOBJ $TARGET $EMUL $OPT $GCSECTIONS -dynamic -bundle -multiply_defined suppress -L. -o $EXE $CATRES'
+               DllCmd[1]:='ld $PRTOBJ $TARGET $EMUL $OPT $GCSECTIONS -dynamic -bundle -multiply_defined suppress -L. -o $EXE $CATRES $FILELIST'
            end
            end
        end
        end
      else
      else
@@ -388,6 +388,7 @@ end;
 Function TLinkerBSD.WriteResponseFile(isdll:boolean) : Boolean;
 Function TLinkerBSD.WriteResponseFile(isdll:boolean) : Boolean;
 Var
 Var
   linkres      : TLinkRes;
   linkres      : TLinkRes;
+  FilesList    : TLinkRes;
   i            : longint;
   i            : longint;
   cprtobj,
   cprtobj,
   gprtobj,
   gprtobj,
@@ -588,16 +589,44 @@ begin
          else if librarysearchpath.FindFile('crtbegin.o',false,s) then
          else if librarysearchpath.FindFile('crtbegin.o',false,s) then
              LinkRes.AddFileName(s);
              LinkRes.AddFileName(s);
    end;
    end;
+
   { main objectfiles }
   { main objectfiles }
-  while not ObjectFiles.Empty do
+
+  { Generate linkfiles.res file if needed }
+  { Only needed on Windows, due to the limitation of 8196 characters for command line }
+  if (LdSupportsNoResponseFile) and
+     (source_info.system in systems_all_windows) then
    begin
    begin
-     s:=ObjectFiles.GetFirst;
-     if s<>'' then
-      if LdSupportsNoResponseFile then
-        LinkRes.AddFileName(s)
-      else
-        LinkRes.AddFileName(maybequoted(s));
+     FilesList:=TLinkRes.Create(outputexedir+'linkfiles.res',false);
+     while not ObjectFiles.Empty do
+      begin
+        s:=ObjectFiles.GetFirst;
+        if s<>'' then
+         begin
+           repeat
+             i:=Pos(source_info.dirsep,s);
+             if i>0 then 
+               s[i]:=target_info.dirsep;
+           until i=0;
+           FilesList.Add(s);
+         end;
+      end;
+     FilesList.writetodisk;
+     FilesList.Free;
+   end
+  else
+   begin
+     while not ObjectFiles.Empty do
+      begin
+        s:=ObjectFiles.GetFirst;
+        if s<>'' then
+          if LdSupportsNoResponseFile then
+            LinkRes.AddFileName(s)
+          else
+            LinkRes.AddFileName(maybequoted(s));
+      end;
    end;
    end;
+
   if not LdSupportsNoResponseFile then
   if not LdSupportsNoResponseFile then
    LinkRes.Add(')');
    LinkRes.Add(')');
 
 
@@ -784,6 +813,10 @@ begin
   Replace(cmdstr,'$EMUL',EmulStr);
   Replace(cmdstr,'$EMUL',EmulStr);
   Replace(cmdstr,'$CATRES',CatFileContent(outputexedir+Info.ResName));
   Replace(cmdstr,'$CATRES',CatFileContent(outputexedir+Info.ResName));
   Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
   Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
+  if (LdSupportsNoResponseFile) and (source_info.system in systems_all_windows) then
+    Replace(cmdstr,'$FILELIST','-filelist '+maybequoted(outputexedir+'linkfiles.res'))
+  else
+    Replace(cmdstr,'$FILELIST','');
   Replace(cmdstr,'$STATIC',StaticStr);
   Replace(cmdstr,'$STATIC',StaticStr);
   Replace(cmdstr,'$STRIP',StripStr);
   Replace(cmdstr,'$STRIP',StripStr);
   Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
   Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
@@ -807,14 +840,17 @@ begin
      not(cs_link_nolink in current_settings.globalswitches) then
      not(cs_link_nolink in current_settings.globalswitches) then
     begin
     begin
       { we have to use a script to use the IFS hack }
       { we have to use a script to use the IFS hack }
-      linkscript:=TAsmScriptUnix.create(outputexedir+'ppaslink');
+      linkscript:=GenerateScript(outputexedir+'ppaslink');
       linkscript.AddLinkCommand(BinStr,CmdStr,'');
       linkscript.AddLinkCommand(BinStr,CmdStr,'');
       if (extdbgcmdstr<>'') then
       if (extdbgcmdstr<>'') then
         linkscript.AddLinkCommand(extdbgbinstr,extdbgcmdstr,'');
         linkscript.AddLinkCommand(extdbgbinstr,extdbgcmdstr,'');
       linkscript.WriteToDisk;
       linkscript.WriteToDisk;
       BinStr:=linkscript.fn;
       BinStr:=linkscript.fn;
       if not path_absolute(BinStr) then
       if not path_absolute(BinStr) then
-        BinStr:='./'+BinStr;
+        if cs_link_on_target in current_settings.globalswitches then
+          BinStr:='.'+target_info.dirsep+BinStr
+        else
+          BinStr:='.'+source_info.dirsep+BinStr;
       CmdStr:='';
       CmdStr:='';
     end;
     end;
 
 
@@ -836,6 +872,10 @@ begin
        end;
        end;
    end;
    end;
 
 
+  { Remove linkfiles.res }
+  if (success) and (LdSupportsNoResponseFile) and (source_info.system in systems_all_windows) then
+    DeleteFile(outputexedir+'linkfiles.res');
+
   MakeExecutable:=success;   { otherwise a recursive call to link method }
   MakeExecutable:=success;   { otherwise a recursive call to link method }
 end;
 end;
 
 
@@ -902,6 +942,10 @@ begin
   Replace(cmdstr,'$TARGET',targetstr);
   Replace(cmdstr,'$TARGET',targetstr);
   Replace(cmdstr,'$EMUL',EmulStr);
   Replace(cmdstr,'$EMUL',EmulStr);
   Replace(cmdstr,'$CATRES',CatFileContent(outputexedir+Info.ResName));
   Replace(cmdstr,'$CATRES',CatFileContent(outputexedir+Info.ResName));
+  if (LdSupportsNoResponseFile) and (source_info.system in systems_all_windows) then
+    Replace(cmdstr,'$FILELIST','-filelist '+maybequoted(outputexedir+'linkfiles.res'))
+  else
+    Replace(cmdstr,'$FILELIST','');
   Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
   Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
   Replace(cmdstr,'$INIT',InitStr);
   Replace(cmdstr,'$INIT',InitStr);
   Replace(cmdstr,'$FINI',FiniStr);
   Replace(cmdstr,'$FINI',FiniStr);
@@ -941,14 +985,17 @@ begin
      not(cs_link_nolink in current_settings.globalswitches) then
      not(cs_link_nolink in current_settings.globalswitches) then
     begin
     begin
       { we have to use a script to use the IFS hack }
       { we have to use a script to use the IFS hack }
-      linkscript:=TAsmScriptUnix.create(outputexedir+'ppaslink');
+      linkscript:=GenerateScript(outputexedir+'ppaslink');
       linkscript.AddLinkCommand(BinStr,CmdStr,'');
       linkscript.AddLinkCommand(BinStr,CmdStr,'');
       if (extdbgbinstr<>'') then
       if (extdbgbinstr<>'') then
         linkscript.AddLinkCommand(extdbgbinstr,extdbgcmdstr,'');
         linkscript.AddLinkCommand(extdbgbinstr,extdbgcmdstr,'');
       linkscript.WriteToDisk;
       linkscript.WriteToDisk;
       BinStr:=linkscript.fn;
       BinStr:=linkscript.fn;
       if not path_absolute(BinStr) then
       if not path_absolute(BinStr) then
-        BinStr:='./'+BinStr;
+        if cs_link_on_target in current_settings.globalswitches then
+          BinStr:='.'+target_info.dirsep+BinStr
+        else
+          BinStr:='.'+source_info.dirsep+BinStr;
       CmdStr:='';
       CmdStr:='';
     end;
     end;
 
 
@@ -979,6 +1026,10 @@ begin
         DeleteFile(outputexedir+'linksyms.fpc');
         DeleteFile(outputexedir+'linksyms.fpc');
     end;
     end;
 
 
+  { Remove linkfiles.res }
+  if (success) and (LdSupportsNoResponseFile) and (source_info.system in systems_all_windows) then
+    DeleteFile(outputexedir+'linkfiles.res');
+
   MakeSharedLibrary:=success;   { otherwise a recursive call to link method }
   MakeSharedLibrary:=success;   { otherwise a recursive call to link method }
 end;
 end;