t_watcom.pas 4.5 KB

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