t_watcom.pas 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. SysUtils,
  25. cclasses,cutils,cfileutl,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 : TCmdStr;
  112. success : boolean;
  113. StripStr : string[40];
  114. begin
  115. if not(cs_link_nolink in current_settings.globalswitches) then
  116. Message1(exec_i_linking,current_module.exefilename^);
  117. { Create some replacements }
  118. StripStr:='debug dwarf all';
  119. if (cs_link_strip in current_settings.globalswitches) 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_nolink in current_settings.globalswitches) then
  132. DeleteFile(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.