t_watcom.pas 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. {
  2. Copyright (c) 2003 by Wiktor Sywula
  3. This unit implements support import, export, link routines
  4. for the (i386) Watcom target
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit t_watcom;
  19. {$i fpcdefs.inc}
  20. interface
  21. implementation
  22. uses
  23. link,
  24. cclasses,cutils,strings,globtype,globals,
  25. systems,verbose,script,fmodule,i_watcom;
  26. type
  27. tlinkerwatcom=class(texternallinker)
  28. private
  29. Function WriteResponseFile(isdll:boolean) : Boolean;
  30. public
  31. constructor Create;override;
  32. procedure SetDefaultInfo;override;
  33. function MakeExecutable:boolean;override;
  34. { function MakeSharedLibrary:boolean;override;}
  35. end;
  36. {****************************************************************************
  37. TLinkerWatcom
  38. ****************************************************************************}
  39. Constructor TLinkerWatcom.Create;
  40. begin
  41. Inherited Create;
  42. SharedLibFiles.doubles:=true;
  43. StaticLibFiles.doubles:=true;
  44. end;
  45. procedure TLinkerWatcom.SetDefaultInfo;
  46. begin
  47. with Info do
  48. ExeCmd[1]:='wlink system causeway option quiet option nocaseexact $OPT $STRIP name $EXE @$RES';
  49. end;
  50. Function TLinkerWatcom.WriteResponseFile(isdll:boolean) : Boolean;
  51. Var
  52. linkres : TLinkRes;
  53. i : longint;
  54. s : string;
  55. linklibc : boolean;
  56. begin
  57. WriteResponseFile:=False;
  58. { Open link.res file }
  59. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName);
  60. { Write object files, start with prt0 }
  61. LinkRes.Add('file '+GetShortName(FindObjectFile('prt0','',false)));
  62. if not ObjectFiles.Empty then
  63. While not ObjectFiles.Empty do
  64. begin
  65. S:=ObjectFiles.GetFirst;
  66. LinkRes.AddFileName('file '+GetShortName(s));
  67. end;
  68. { Write staticlibraries }
  69. if not StaticLibFiles.Empty then
  70. While not StaticLibFiles.Empty do
  71. begin
  72. S:=StaticLibFiles.GetFirst;
  73. LinkRes.AddFileName('file '+GetShortName(s));
  74. end;
  75. (*
  76. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  77. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  78. linklibc:=false;
  79. While not SharedLibFiles.Empty do
  80. begin
  81. S:=SharedLibFiles.Get;
  82. if s<>'c' then
  83. begin
  84. i:=Pos(target_os.sharedlibext,S);
  85. if i>0 then
  86. Delete(S,i,255);
  87. LinkRes.Add('-l'+s);
  88. end
  89. else
  90. begin
  91. LinkRes.Add('-l'+s);
  92. linklibc:=true;
  93. end;
  94. end;
  95. { be sure that libc&libgcc is the last lib }
  96. if linklibc then
  97. begin
  98. LinkRes.Add('-lc');
  99. LinkRes.Add('-lgcc');
  100. end;
  101. *)
  102. { Write and Close response }
  103. linkres.writetodisk;
  104. linkres.free;
  105. WriteResponseFile:=True;
  106. end;
  107. function TLinkerWatcom.MakeExecutable:boolean;
  108. var
  109. binstr : String;
  110. cmdstr : TCmdStr;
  111. success : boolean;
  112. StripStr : string[40];
  113. begin
  114. if not(cs_link_extern in aktglobalswitches) then
  115. Message1(exec_i_linking,current_module.exefilename^);
  116. { Create some replacements }
  117. StripStr:='debug dwarf all';
  118. if (cs_link_strip in aktglobalswitches) then
  119. StripStr:='';
  120. { Write used files and libraries }
  121. WriteResponseFile(false);
  122. { Call linker }
  123. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  124. Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename^));
  125. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  126. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  127. Replace(cmdstr,'$STRIP',StripStr);
  128. success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);
  129. { Remove ReponseFile }
  130. if (success) and not(cs_link_extern in aktglobalswitches) then
  131. RemoveFile(outputexedir+Info.ResName);
  132. MakeExecutable:=success; { otherwise a recursive call to link method }
  133. end;
  134. {function TLinkerWatcom.MakeSharedLibrary:boolean;
  135. begin
  136. MakeSharedLibrary:=false;
  137. end;}
  138. {*****************************************************************************
  139. Initialize
  140. *****************************************************************************}
  141. initialization
  142. RegisterExternalLinker(system_i386_watcom_info,TLinkerWatcom);
  143. RegisterTarget(system_i386_watcom_info);
  144. end.