t_go32v1.pas 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. {
  2. $Id$
  3. Copyright (c) 1999 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 : TSearchPathString;
  59. s,s2 : string;
  60. linklibc : boolean;
  61. begin
  62. WriteResponseFile:=False;
  63. { Open link.res file }
  64. LinkRes.Init(Info.ResName);
  65. { Write path to search libraries }
  66. if assigned(current_module^.locallibrarysearchpath) then
  67. begin
  68. HPath:=current_module^.locallibrarysearchpath^;
  69. while HPath<>'' do
  70. begin
  71. s2:=GetPathFromList(HPath);
  72. LinkRes.Add('-L'+s2);
  73. end;
  74. end;
  75. HPath:=LibrarySearchPath;
  76. while HPath<>'' do
  77. begin
  78. s2:=GetPathFromList(HPath);
  79. LinkRes.Add('-L'+s2);
  80. end;
  81. { add objectfiles, start with prt0 always }
  82. LinkRes.AddFileName(FindObjectFile('prt0'));
  83. while not ObjectFiles.Empty do
  84. begin
  85. s:=ObjectFiles.Get;
  86. if s<>'' then
  87. LinkRes.AddFileName(s);
  88. end;
  89. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  90. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  91. linklibc:=false;
  92. While not SharedLibFiles.Empty do
  93. begin
  94. S:=SharedLibFiles.Get;
  95. if s<>'c' then
  96. begin
  97. i:=Pos(target_os.sharedlibext,S);
  98. if i>0 then
  99. Delete(S,i,255);
  100. LinkRes.Add('-l'+s);
  101. end
  102. else
  103. begin
  104. LinkRes.Add('-l'+s);
  105. linklibc:=true;
  106. end;
  107. end;
  108. { be sure that libc&libgcc is the last lib }
  109. if linklibc then
  110. begin
  111. LinkRes.Add('-lc');
  112. LinkRes.Add('-lgcc');
  113. end;
  114. { Write staticlibraries }
  115. if not StaticLibFiles.Empty then
  116. begin
  117. LinkRes.Add('-(');
  118. While not StaticLibFiles.Empty do
  119. begin
  120. S:=StaticLibFiles.Get;
  121. LinkRes.AddFileName(s)
  122. end;
  123. LinkRes.Add('-)');
  124. end;
  125. { Write and Close response }
  126. linkres.writetodisk;
  127. linkres.done;
  128. WriteResponseFile:=True;
  129. end;
  130. function TLinkergo32v1.MakeExecutable:boolean;
  131. var
  132. binstr,
  133. cmdstr : string;
  134. success : boolean;
  135. StripStr : string[40];
  136. begin
  137. if not(cs_link_extern in aktglobalswitches) then
  138. Message1(exec_i_linking,current_module^.exefilename^);
  139. { Create some replacements }
  140. StripStr:='';
  141. if (cs_link_strip in aktglobalswitches) then
  142. StripStr:='-s';
  143. { Write used files and libraries }
  144. WriteResponseFile(false);
  145. { Call linker }
  146. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  147. Replace(cmdstr,'$EXE',current_module^.exefilename^);
  148. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  149. Replace(cmdstr,'$RES',current_module^.outpath^+Info.ResName);
  150. Replace(cmdstr,'$STRIP',StripStr);
  151. success:=DoExec(FindUtil(BinStr),cmdstr,true,false);
  152. { Remove ReponseFile }
  153. if (success) and not(cs_link_extern in aktglobalswitches) then
  154. RemoveFile(current_module^.outpath^+Info.ResName);
  155. MakeExecutable:=success; { otherwise a recursive call to link method }
  156. end;
  157. end.
  158. {
  159. $Log$
  160. Revision 1.3 1999-11-04 10:55:31 peter
  161. * TSearchPathString for the string type of the searchpaths, which is
  162. ansistring under FPC/Delphi
  163. Revision 1.2 1999/10/22 14:42:40 peter
  164. * reset linklibc
  165. Revision 1.1 1999/10/21 14:29:38 peter
  166. * redesigned linker object
  167. + library support for linux (only procedures can be exported)
  168. }