t_go32v1.pas 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. {$IFDEF NEWST}
  59. HPath : PStringItem;
  60. {$ELSE}
  61. HPath : PStringQueueItem;
  62. {$ENDIF}
  63. s : string;
  64. linklibc : boolean;
  65. begin
  66. WriteResponseFile:=False;
  67. { Open link.res file }
  68. LinkRes.Init(outputexedir+Info.ResName);
  69. { Write path to search libraries }
  70. HPath:=current_module^.locallibrarysearchpath.First;
  71. while assigned(HPath) do
  72. begin
  73. LinkRes.Add('-L'+HPath^.Data^);
  74. HPath:=HPath^.Next;
  75. end;
  76. HPath:=LibrarySearchPath.First;
  77. while assigned(HPath) do
  78. begin
  79. LinkRes.Add('-L'+HPath^.Data^);
  80. HPath:=HPath^.Next;
  81. end;
  82. { add objectfiles, start with prt0 always }
  83. LinkRes.AddFileName(FindObjectFile('prt0'));
  84. while not ObjectFiles.Empty do
  85. begin
  86. s:=ObjectFiles.Get;
  87. if s<>'' then
  88. LinkRes.AddFileName(s);
  89. end;
  90. { Write staticlibraries }
  91. if not StaticLibFiles.Empty then
  92. begin
  93. LinkRes.Add('-(');
  94. While not StaticLibFiles.Empty do
  95. begin
  96. S:=StaticLibFiles.Get;
  97. LinkRes.AddFileName(s)
  98. end;
  99. LinkRes.Add('-)');
  100. end;
  101. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  102. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  103. linklibc:=false;
  104. While not SharedLibFiles.Empty do
  105. begin
  106. S:=SharedLibFiles.Get;
  107. if s<>'c' then
  108. begin
  109. i:=Pos(target_os.sharedlibext,S);
  110. if i>0 then
  111. Delete(S,i,255);
  112. LinkRes.Add('-l'+s);
  113. end
  114. else
  115. begin
  116. LinkRes.Add('-l'+s);
  117. linklibc:=true;
  118. end;
  119. end;
  120. { be sure that libc&libgcc is the last lib }
  121. if linklibc then
  122. begin
  123. LinkRes.Add('-lc');
  124. LinkRes.Add('-lgcc');
  125. end;
  126. { Write and Close response }
  127. linkres.writetodisk;
  128. linkres.done;
  129. WriteResponseFile:=True;
  130. end;
  131. function TLinkergo32v1.MakeExecutable:boolean;
  132. var
  133. binstr,
  134. cmdstr : string;
  135. success : boolean;
  136. StripStr : string[40];
  137. begin
  138. if not(cs_link_extern in aktglobalswitches) then
  139. Message1(exec_i_linking,current_module^.exefilename^);
  140. { Create some replacements }
  141. StripStr:='';
  142. if (cs_link_strip in aktglobalswitches) then
  143. StripStr:='-s';
  144. { Write used files and libraries }
  145. WriteResponseFile(false);
  146. { Call linker }
  147. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  148. Replace(cmdstr,'$EXE',current_module^.exefilename^);
  149. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  150. Replace(cmdstr,'$RES',outputexedir+Info.ResName);
  151. Replace(cmdstr,'$STRIP',StripStr);
  152. success:=DoExec(FindUtil(BinStr),cmdstr,true,false);
  153. { Remove ReponseFile }
  154. if (success) and not(cs_link_extern in aktglobalswitches) then
  155. RemoveFile(outputexedir+Info.ResName);
  156. MakeExecutable:=success; { otherwise a recursive call to link method }
  157. end;
  158. end.
  159. {
  160. $Log$
  161. Revision 1.9 2000-02-28 17:23:57 daniel
  162. * Current work of symtable integration committed. The symtable can be
  163. activated by defining 'newst', but doesn't compile yet. Changes in type
  164. checking and oop are completed. What is left is to write a new
  165. symtablestack and adapt the parser to use it.
  166. Revision 1.8 2000/02/09 13:23:06 peter
  167. * log truncated
  168. Revision 1.7 2000/01/09 00:55:51 pierre
  169. * GROUP of smartlink units put before the C libraries
  170. to allow for smartlinking code that uses C code.
  171. Revision 1.6 2000/01/07 01:14:42 peter
  172. * updated copyright to 2000
  173. Revision 1.5 1999/11/16 23:39:04 peter
  174. * use outputexedir for link.res location
  175. Revision 1.4 1999/11/12 11:03:50 peter
  176. * searchpaths changed to stringqueue object
  177. Revision 1.3 1999/11/04 10:55:31 peter
  178. * TSearchPathString for the string type of the searchpaths, which is
  179. ansistring under FPC/Delphi
  180. Revision 1.2 1999/10/22 14:42:40 peter
  181. * reset linklibc
  182. Revision 1.1 1999/10/21 14:29:38 peter
  183. * redesigned linker object
  184. + library support for linux (only procedures can be exported)
  185. }