t_go32v1.pas 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Peter Vreman
  4. This unit implements support import,export,link routines
  5. for the (i386) go32v1 target
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************
  18. }
  19. unit t_go32v1;
  20. interface
  21. uses
  22. link;
  23. type
  24. plinkergo32v1=^tlinkergo32v1;
  25. tlinkergo32v1=object(tlinker)
  26. private
  27. Function WriteResponseFile(isdll:boolean) : Boolean;
  28. public
  29. constructor Init;
  30. procedure SetDefaultInfo;virtual;
  31. function MakeExecutable:boolean;virtual;
  32. end;
  33. implementation
  34. uses
  35. globtype,globals,cobjects,systems,verbose,script,files;
  36. {****************************************************************************
  37. TLinkergo32v1
  38. ****************************************************************************}
  39. Constructor TLinkergo32v1.Init;
  40. begin
  41. Inherited Init;
  42. { allow duplicated libs (PM) }
  43. SharedLibFiles.doubles:=true;
  44. StaticLibFiles.doubles:=true;
  45. end;
  46. procedure TLinkergo32v1.SetDefaultInfo;
  47. begin
  48. with Info do
  49. begin
  50. ExeCmd[1]:='ld -oformat coff-go32 $OPT $STRIP -o $EXE @$RES';
  51. ExeCmd[2]:='aout2exe $EXE';
  52. end;
  53. end;
  54. Function TLinkergo32v1.WriteResponseFile(isdll:boolean) : Boolean;
  55. Var
  56. linkres : TLinkRes;
  57. i : longint;
  58. HPath : PStringQueueItem;
  59. s : string;
  60. linklibc : boolean;
  61. begin
  62. WriteResponseFile:=False;
  63. { Open link.res file }
  64. LinkRes.Init(outputexedir+Info.ResName);
  65. { Write path to search libraries }
  66. HPath:=current_module^.locallibrarysearchpath.First;
  67. while assigned(HPath) do
  68. begin
  69. LinkRes.Add('-L'+HPath^.Data^);
  70. HPath:=HPath^.Next;
  71. end;
  72. HPath:=LibrarySearchPath.First;
  73. while assigned(HPath) do
  74. begin
  75. LinkRes.Add('-L'+HPath^.Data^);
  76. HPath:=HPath^.Next;
  77. end;
  78. { add objectfiles, start with prt0 always }
  79. LinkRes.AddFileName(FindObjectFile('prt0'));
  80. while not ObjectFiles.Empty do
  81. begin
  82. s:=ObjectFiles.Get;
  83. if s<>'' then
  84. LinkRes.AddFileName(s);
  85. end;
  86. { Write staticlibraries }
  87. if not StaticLibFiles.Empty then
  88. begin
  89. LinkRes.Add('-(');
  90. While not StaticLibFiles.Empty do
  91. begin
  92. S:=StaticLibFiles.Get;
  93. LinkRes.AddFileName(s)
  94. end;
  95. LinkRes.Add('-)');
  96. end;
  97. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  98. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  99. linklibc:=false;
  100. While not SharedLibFiles.Empty do
  101. begin
  102. S:=SharedLibFiles.Get;
  103. if s<>'c' then
  104. begin
  105. i:=Pos(target_os.sharedlibext,S);
  106. if i>0 then
  107. Delete(S,i,255);
  108. LinkRes.Add('-l'+s);
  109. end
  110. else
  111. begin
  112. LinkRes.Add('-l'+s);
  113. linklibc:=true;
  114. end;
  115. end;
  116. { be sure that libc&libgcc is the last lib }
  117. if linklibc then
  118. begin
  119. LinkRes.Add('-lc');
  120. LinkRes.Add('-lgcc');
  121. end;
  122. { Write and Close response }
  123. linkres.writetodisk;
  124. linkres.done;
  125. WriteResponseFile:=True;
  126. end;
  127. function TLinkergo32v1.MakeExecutable:boolean;
  128. var
  129. binstr,
  130. cmdstr : string;
  131. success : boolean;
  132. StripStr : string[40];
  133. begin
  134. if not(cs_link_extern in aktglobalswitches) then
  135. Message1(exec_i_linking,current_module^.exefilename^);
  136. { Create some replacements }
  137. StripStr:='';
  138. if (cs_link_strip in aktglobalswitches) then
  139. StripStr:='-s';
  140. { Write used files and libraries }
  141. WriteResponseFile(false);
  142. { Call linker }
  143. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  144. Replace(cmdstr,'$EXE',current_module^.exefilename^);
  145. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  146. Replace(cmdstr,'$RES',outputexedir+Info.ResName);
  147. Replace(cmdstr,'$STRIP',StripStr);
  148. success:=DoExec(FindUtil(BinStr),cmdstr,true,false);
  149. { Remove ReponseFile }
  150. if (success) and not(cs_link_extern in aktglobalswitches) then
  151. RemoveFile(outputexedir+Info.ResName);
  152. MakeExecutable:=success; { otherwise a recursive call to link method }
  153. end;
  154. end.
  155. {
  156. $Log$
  157. Revision 1.8 2000-02-09 13:23:06 peter
  158. * log truncated
  159. Revision 1.7 2000/01/09 00:55:51 pierre
  160. * GROUP of smartlink units put before the C libraries
  161. to allow for smartlinking code that uses C code.
  162. Revision 1.6 2000/01/07 01:14:42 peter
  163. * updated copyright to 2000
  164. Revision 1.5 1999/11/16 23:39:04 peter
  165. * use outputexedir for link.res location
  166. Revision 1.4 1999/11/12 11:03:50 peter
  167. * searchpaths changed to stringqueue object
  168. Revision 1.3 1999/11/04 10:55:31 peter
  169. * TSearchPathString for the string type of the searchpaths, which is
  170. ansistring under FPC/Delphi
  171. Revision 1.2 1999/10/22 14:42:40 peter
  172. * reset linklibc
  173. Revision 1.1 1999/10/21 14:29:38 peter
  174. * redesigned linker object
  175. + library support for linux (only procedures can be exported)
  176. }