t_macos.pas 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. {
  2. $Id$
  3. Copyright (c) 2001-2002 by Peter Vreman
  4. This unit implements support import,export,link routines for MacOS.
  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_macos;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. import,symsym,symdef,link;
  23. type
  24. timportlibmacos=class(timportlib)
  25. procedure preparelib(const s:string);override;
  26. procedure importprocedure(aprocdef:tprocdef;const module:string;index:longint;const name:string);override;
  27. procedure importvariable(vs:tglobalvarsym;const name,module:string);override;
  28. procedure generatelib;override;
  29. end;
  30. tlinkermpw=class(texternallinker)
  31. private
  32. Function WriteResponseFile(isdll:boolean) : Boolean;
  33. public
  34. constructor Create;override;
  35. procedure SetDefaultInfo;override;
  36. function MakeExecutable:boolean;override;
  37. end;
  38. implementation
  39. uses
  40. cutils,cclasses,
  41. globtype,globals,systems,verbose,script,fmodule,i_macos,
  42. symconst;
  43. {*****************************************************************************
  44. TIMPORTLIBMACOS
  45. *****************************************************************************}
  46. procedure timportlibmacos.preparelib(const s : string);
  47. begin
  48. end;
  49. procedure timportlibmacos.importprocedure(aprocdef:tprocdef;const module:string;index:longint;const name:string);
  50. begin
  51. { insert sharedlibrary }
  52. current_module.linkothersharedlibs.add(SplitName(module),link_allways);
  53. end;
  54. procedure timportlibmacos.importvariable(vs:tglobalvarsym;const name,module:string);
  55. begin
  56. { insert sharedlibrary }
  57. current_module.linkothersharedlibs.add(SplitName(module),link_allways);
  58. { reset the mangledname and turn off the dll_var option }
  59. vs.set_mangledname(name);
  60. exclude(vs.varoptions,vo_is_dll_var);
  61. end;
  62. procedure timportlibmacos.generatelib;
  63. begin
  64. end;
  65. {*****************************************************************************
  66. TLINKERMPW
  67. *****************************************************************************}
  68. Constructor TLinkerMPW.Create;
  69. begin
  70. Inherited Create;
  71. //LibrarySearchPath.AddPath('/lib;/usr/lib;/usr/X11R6/lib',true);
  72. end;
  73. procedure TLinkerMPW.SetDefaultInfo;
  74. begin
  75. with Info do
  76. begin
  77. ExeCmd[1]:='Execute $RES'; {The link.res file contains the whole link command.}
  78. //ExeCmd[1]:='PPCLink $OPT $DYNLINK $STATIC $STRIP -tocdataref off -dead on -o $EXE -@filelist $RES';
  79. //DllCmd[1]:='PPCLink $OPT $INIT $FINI $SONAME -shared -o $EXE -@filelist $RES';
  80. end;
  81. end;
  82. Function TLinkerMPW.WriteResponseFile(isdll:boolean) : Boolean;
  83. Var
  84. linkres : TLinkRes;
  85. s: string;
  86. begin
  87. WriteResponseFile:=False;
  88. { Open link.res file }
  89. linkRes:=TLinkRes.Create(outputexedir+Info.ResName);
  90. with linkRes do
  91. begin
  92. {#182 is escape char in MPW (analog to backslash in unix). The space}
  93. {ensures there is whitespace separating items.}
  94. Add('PPCLink '#182);
  95. { Add MPW standard libraries}
  96. if apptype = app_cui then
  97. Add('"{PPCLibraries}PPCSIOW.o" '#182);
  98. if (apptype = app_tool) or (apptype = app_cui) then
  99. Add('"{PPCLibraries}PPCToolLibs.o" '#182);
  100. Add('"{SharedLibraries}InterfaceLib" '#182);
  101. Add('"{SharedLibraries}StdCLib" '#182);
  102. Add('"{SharedLibraries}MathLib" '#182);
  103. Add('"{PPCLibraries}StdCRuntime.o" '#182);
  104. Add('"{PPCLibraries}PPCCRuntime.o" '#182);
  105. {Add main objectfiles}
  106. while not ObjectFiles.Empty do
  107. begin
  108. s:=ObjectFiles.GetFirst;
  109. if s<>'' then
  110. Add(s+' '#182);
  111. end;
  112. {Add last lines of the link command}
  113. if apptype = app_tool then
  114. Add('-t "MPST" -c "MPS " '#182);
  115. if apptype = app_cui then {If SIOW, to avoid some warnings.}
  116. Add('-ignoredups __start -ignoredups .__start -ignoredups main -ignoredups .main '#182);
  117. Add('-tocdataref off -sym on -dead on -o '+ ScriptFixFileName(current_module.exefilename^));
  118. Add('Exit If "{Status}" != 0');
  119. {Add mac resources}
  120. if apptype = app_cui then
  121. begin
  122. Add('Rez -append "{RIncludes}"SIOW.r -o ' + ScriptFixFileName(current_module.exefilename^));
  123. Add('Exit If "{Status}" != 0');
  124. end;
  125. end;
  126. { Write and Close response }
  127. linkres.writetodisk;
  128. linkres.Free;
  129. WriteResponseFile:=True;
  130. end;
  131. function TLinkerMPW.MakeExecutable:boolean;
  132. var
  133. binstr,
  134. cmdstr : string;
  135. success : boolean;
  136. DynLinkStr : string[60];
  137. StaticStr,
  138. StripStr : string[40];
  139. s: string;
  140. begin
  141. //TODO Only external link in MPW is possible, otherwise yell.
  142. if not(cs_link_extern in aktglobalswitches) then
  143. Message1(exec_i_linking,current_module.exefilename^);
  144. { Create some replacements }
  145. (*
  146. StaticStr:='';
  147. StripStr:='';
  148. DynLinkStr:='';
  149. if (cs_link_staticflag in aktglobalswitches) then
  150. StaticStr:='-static';
  151. if (cs_link_strip in aktglobalswitches) then
  152. StripStr:='-s';
  153. If (cs_profile in aktmoduleswitches) or
  154. ((Info.DynamicLinker<>'') and (not SharedLibFiles.Empty)) then
  155. DynLinkStr:='-dynamic-linker='+Info.DynamicLinker;
  156. *)
  157. { Call linker }
  158. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  159. Replace(cmdstr,'$EXE',maybequoted(ScriptFixFileName(current_module.exefilename^)));
  160. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  161. Replace(cmdstr,'$RES',maybequoted(ScriptFixFileName(outputexedir+Info.ResName)));
  162. Replace(cmdstr,'$STATIC',StaticStr);
  163. Replace(cmdstr,'$STRIP',StripStr);
  164. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  165. with AsmRes do
  166. begin
  167. WriteResponseFile(false);
  168. success:= true;
  169. if cs_link_on_target in aktglobalswitches then
  170. success:=DoExec('SetFile', ' -c ''MPS '' -t ''TEXT'' ' +
  171. ScriptFixFileName(outputexedir+Info.ResName),true,false);
  172. if success then
  173. success:=DoExec('Execute',CmdStr,true,false);
  174. end;
  175. MakeExecutable:=success; { otherwise a recursive call to link method }
  176. end;
  177. {*****************************************************************************
  178. Initialize
  179. *****************************************************************************}
  180. initialization
  181. {$ifdef m68k}
  182. RegisterTarget(system_m68k_macos_info);
  183. RegisterImport(system_m68k_macos,timportlibmacos);
  184. {$endif m68k}
  185. {$ifdef powerpc}
  186. RegisterExternalLinker(system_powerpc_macos_info,TLinkerMPW);
  187. RegisterTarget(system_powerpc_macos_info);
  188. RegisterImport(system_powerpc_macos,timportlibmacos);
  189. {$endif powerpc}
  190. end.
  191. {
  192. $Log$
  193. Revision 1.16 2004-12-22 16:32:46 peter
  194. * maybequoted() added
  195. Revision 1.15 2004/11/19 16:30:24 peter
  196. * fixed setting of mangledname when importing
  197. Revision 1.14 2004/11/11 19:31:33 peter
  198. * fixed compile of powerpc,sparc,arm
  199. Revision 1.13 2004/10/25 15:38:41 peter
  200. * heap and heapsize removed
  201. * checkpointer fixes
  202. Revision 1.12 2004/09/13 16:13:04 olle
  203. + When link on target, the script sets file type on link.res
  204. Revision 1.11 2004/08/20 10:30:00 olle
  205. + made fpc work as an MPW tool, by itself calling asm and link.
  206. Revision 1.10 2004/06/20 08:55:32 florian
  207. * logs truncated
  208. Revision 1.9 2004/05/11 18:24:39 olle
  209. + added GUI apptype to MacOS
  210. Revision 1.8 2004/04/06 22:44:22 olle
  211. + Status checks in scripts
  212. + Scripts support apptype tool
  213. + Added some ScriptFixFileName
  214. Revision 1.7 2004/02/19 20:40:20 olle
  215. + Support for Link on target especially for MacOS
  216. + TLinkerMPW
  217. + TAsmScriptMPW
  218. }