t_msdos.pas 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. {
  2. Copyright (c) 1998-2002 by Peter Vreman
  3. This unit implements support import,export,link routines
  4. for the (i8086) MS-DOS 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_msdos;
  19. {$i fpcdefs.inc}
  20. interface
  21. implementation
  22. uses
  23. SysUtils,
  24. cutils,cfileutl,cclasses,
  25. globtype,globals,systems,verbose,script,
  26. fmodule,i_msdos,
  27. link,aasmbase;
  28. type
  29. TExternalLinkerMsDosTLink=class(texternallinker)
  30. private
  31. Function WriteResponseFile(isdll:boolean) : Boolean;
  32. public
  33. constructor Create;override;
  34. procedure SetDefaultInfo;override;
  35. function MakeExecutable:boolean;override;
  36. end;
  37. {****************************************************************************
  38. TExternalLinkerMsDosTLink
  39. ****************************************************************************}
  40. Constructor TExternalLinkerMsDosTLink.Create;
  41. begin
  42. Inherited Create;
  43. { allow duplicated libs (PM) }
  44. SharedLibFiles.doubles:=true;
  45. StaticLibFiles.doubles:=true;
  46. end;
  47. procedure TExternalLinkerMsDosTLink.SetDefaultInfo;
  48. begin
  49. with Info do
  50. begin
  51. ExeCmd[1]:='tlink $RES';
  52. end;
  53. end;
  54. Function TExternalLinkerMsDosTLink.WriteResponseFile(isdll:boolean) : Boolean;
  55. Var
  56. linkres : TLinkRes;
  57. i : longint;
  58. s : string;
  59. linklibc : boolean;
  60. begin
  61. WriteResponseFile:=False;
  62. { Open link.res file }
  63. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName,true);
  64. { Add all options to link.res instead of passing them via command line:
  65. DOS command line is limited to 126 characters! }
  66. { add objectfiles, start with prt0 always }
  67. LinkRes.Add(GetShortName(FindObjectFile('prt0','',false)) + ' +');
  68. while not ObjectFiles.Empty do
  69. begin
  70. s:=ObjectFiles.GetFirst;
  71. if s<>'' then
  72. LinkRes.Add(GetShortName(s) + ' +');
  73. end;
  74. LinkRes.Add(', ' + maybequoted(current_module.exefilename));
  75. { Write and Close response }
  76. linkres.writetodisk;
  77. LinkRes.Free;
  78. WriteResponseFile:=True;
  79. end;
  80. function TExternalLinkerMsDosTLink.MakeExecutable:boolean;
  81. var
  82. binstr,
  83. cmdstr : TCmdStr;
  84. success : boolean;
  85. begin
  86. if not(cs_link_nolink in current_settings.globalswitches) then
  87. Message1(exec_i_linking,current_module.exefilename);
  88. { Write used files and libraries and our own tlink script }
  89. WriteResponsefile(false);
  90. { Call linker }
  91. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  92. Replace(cmdstr,'$RES','@'+maybequoted(outputexedir+Info.ResName));
  93. success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);
  94. { Remove ReponseFile }
  95. if (success) and not(cs_link_nolink in current_settings.globalswitches) then
  96. DeleteFile(outputexedir+Info.ResName);
  97. MakeExecutable:=success; { otherwise a recursive call to link method }
  98. end;
  99. {*****************************************************************************
  100. Initialize
  101. *****************************************************************************}
  102. initialization
  103. RegisterExternalLinker(system_i8086_msdos_info,TExternalLinkerMsDosTLink);
  104. RegisterTarget(system_i8086_msdos_info);
  105. end.