t_go32v1.pas 4.8 KB

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