t_watcom.pas 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. {
  2. $Id$
  3. Copyright (c) 2003 by Wiktor Sywula
  4. This unit implements support import, export, link routines
  5. for the (i386) Watcom 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_watcom;
  20. {$i fpcdefs.inc}
  21. interface
  22. implementation
  23. uses
  24. link,
  25. cclasses,cutils,strings,globtype,globals,
  26. systems,verbose,script,fmodule,i_watcom;
  27. type
  28. tlinkerwatcom=class(texternallinker)
  29. private
  30. Function WriteResponseFile(isdll:boolean) : Boolean;
  31. public
  32. constructor Create;override;
  33. procedure SetDefaultInfo;override;
  34. function MakeExecutable:boolean;override;
  35. { function MakeSharedLibrary:boolean;override;}
  36. end;
  37. {****************************************************************************
  38. TLinkerWatcom
  39. ****************************************************************************}
  40. Constructor TLinkerWatcom.Create;
  41. begin
  42. Inherited Create;
  43. SharedLibFiles.doubles:=true;
  44. StaticLibFiles.doubles:=true;
  45. end;
  46. procedure TLinkerWatcom.SetDefaultInfo;
  47. begin
  48. with Info do
  49. ExeCmd[1]:='wlink system causeway option quiet option nocaseexact $OPT $STRIP name $EXE @$RES';
  50. end;
  51. Function TLinkerWatcom.WriteResponseFile(isdll:boolean) : Boolean;
  52. Var
  53. linkres : TLinkRes;
  54. i : longint;
  55. s : string;
  56. linklibc : boolean;
  57. begin
  58. WriteResponseFile:=False;
  59. { Open link.res file }
  60. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName);
  61. { Write object files, start with prt0 }
  62. LinkRes.Add('file '+GetShortName(FindObjectFile('prt0','',false)));
  63. if not ObjectFiles.Empty then
  64. While not ObjectFiles.Empty do
  65. begin
  66. S:=ObjectFiles.GetFirst;
  67. LinkRes.AddFileName('file '+GetShortName(s));
  68. end;
  69. { Write staticlibraries }
  70. if not StaticLibFiles.Empty then
  71. While not StaticLibFiles.Empty do
  72. begin
  73. S:=StaticLibFiles.GetFirst;
  74. LinkRes.AddFileName('file '+GetShortName(s));
  75. end;
  76. (*
  77. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  78. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  79. linklibc:=false;
  80. While not SharedLibFiles.Empty do
  81. begin
  82. S:=SharedLibFiles.Get;
  83. if s<>'c' then
  84. begin
  85. i:=Pos(target_os.sharedlibext,S);
  86. if i>0 then
  87. Delete(S,i,255);
  88. LinkRes.Add('-l'+s);
  89. end
  90. else
  91. begin
  92. LinkRes.Add('-l'+s);
  93. linklibc:=true;
  94. end;
  95. end;
  96. { be sure that libc&libgcc is the last lib }
  97. if linklibc then
  98. begin
  99. LinkRes.Add('-lc');
  100. LinkRes.Add('-lgcc');
  101. end;
  102. *)
  103. { Write and Close response }
  104. linkres.writetodisk;
  105. linkres.free;
  106. WriteResponseFile:=True;
  107. end;
  108. function TLinkerWatcom.MakeExecutable:boolean;
  109. var
  110. binstr,
  111. cmdstr : string;
  112. success : boolean;
  113. StripStr : string[40];
  114. begin
  115. if not(cs_link_extern in aktglobalswitches) then
  116. Message1(exec_i_linking,current_module.exefilename^);
  117. { Create some replacements }
  118. StripStr:='debug dwarf all';
  119. if (cs_link_strip in aktglobalswitches) then
  120. StripStr:='';
  121. { Write used files and libraries }
  122. WriteResponseFile(false);
  123. { Call linker }
  124. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  125. Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename^));
  126. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  127. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  128. Replace(cmdstr,'$STRIP',StripStr);
  129. success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);
  130. { Remove ReponseFile }
  131. if (success) and not(cs_link_extern in aktglobalswitches) then
  132. RemoveFile(outputexedir+Info.ResName);
  133. MakeExecutable:=success; { otherwise a recursive call to link method }
  134. end;
  135. {function TLinkerWatcom.MakeSharedLibrary:boolean;
  136. begin
  137. MakeSharedLibrary:=false;
  138. end;}
  139. {*****************************************************************************
  140. Initialize
  141. *****************************************************************************}
  142. initialization
  143. RegisterExternalLinker(system_i386_watcom_info,TLinkerWatcom);
  144. RegisterTarget(system_i386_watcom_info);
  145. end.
  146. {
  147. $Log$
  148. Revision 1.3 2003-10-03 14:16:48 marco
  149. * -XP<prefix> support
  150. Revision 1.2 2003/09/30 08:39:50 michael
  151. + Patch from Wiktor Sywula for watcom support
  152. Revision 1.1 2003/09/06 10:01:11 florian
  153. + added *_watcom units
  154. }