t_macos.pas 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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:tvarsym;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. { do nothing with the procedure, only set the mangledname }
  54. if name<>'' then
  55. begin
  56. aprocdef.setmangledname(name);
  57. end
  58. else
  59. message(parser_e_empty_import_name);
  60. end;
  61. procedure timportlibmacos.importvariable(vs:tvarsym;const name,module:string);
  62. begin
  63. { insert sharedlibrary }
  64. current_module.linkothersharedlibs.add(SplitName(module),link_allways);
  65. { reset the mangledname and turn off the dll_var option }
  66. vs.set_mangledname(name);
  67. exclude(vs.varoptions,vo_is_dll_var);
  68. end;
  69. procedure timportlibmacos.generatelib;
  70. begin
  71. end;
  72. {*****************************************************************************
  73. TLINKERMPW
  74. *****************************************************************************}
  75. Constructor TLinkerMPW.Create;
  76. begin
  77. Inherited Create;
  78. //LibrarySearchPath.AddPath('/lib;/usr/lib;/usr/X11R6/lib',true);
  79. end;
  80. procedure TLinkerMPW.SetDefaultInfo;
  81. begin
  82. with Info do
  83. begin
  84. ExeCmd[1]:='PPCLink $OPT $DYNLINK $STATIC $STRIP -tocdataref off -dead on -o $EXE -@filelist $RES';
  85. DllCmd[1]:='PPCLink $OPT $INIT $FINI $SONAME -shared -o $EXE -@filelist $RES';
  86. end;
  87. end;
  88. Function TLinkerMPW.WriteResponseFile(isdll:boolean) : Boolean;
  89. begin
  90. WriteResponseFile:=False;
  91. end;
  92. function TLinkerMPW.MakeExecutable:boolean;
  93. var
  94. binstr,
  95. cmdstr : string;
  96. success : boolean;
  97. DynLinkStr : string[60];
  98. StaticStr,
  99. StripStr : string[40];
  100. s: string;
  101. begin
  102. //TODO Only external link in MPW is possible, otherwise yell.
  103. if not(cs_link_extern in aktglobalswitches) then
  104. Message1(exec_i_linking,current_module.exefilename^);
  105. { Create some replacements }
  106. (*
  107. StaticStr:='';
  108. StripStr:='';
  109. DynLinkStr:='';
  110. if (cs_link_staticflag in aktglobalswitches) then
  111. StaticStr:='-static';
  112. if (cs_link_strip in aktglobalswitches) then
  113. StripStr:='-s';
  114. If (cs_profile in aktmoduleswitches) or
  115. ((Info.DynamicLinker<>'') and (not SharedLibFiles.Empty)) then
  116. DynLinkStr:='-dynamic-linker='+Info.DynamicLinker;
  117. *)
  118. { Call linker }
  119. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  120. Replace(cmdstr,'$EXE',current_module.exefilename^);
  121. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  122. Replace(cmdstr,'$RES',outputexedir+Info.ResName);
  123. Replace(cmdstr,'$STATIC',StaticStr);
  124. Replace(cmdstr,'$STRIP',StripStr);
  125. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  126. with AsmRes do
  127. begin
  128. {#182 is escape char in MPW (analog to backslash in unix). The space}
  129. {ensures there is whitespace separating items.}
  130. Add('PPCLink '#182);
  131. { Add MPW standard libraries}
  132. if true then // if not MPWTool
  133. begin
  134. Add('"{PPCLibraries}PPCSIOW.o" '#182);
  135. Add('"{PPCLibraries}PPCToolLibs.o" '#182);
  136. end;
  137. Add('"{SharedLibraries}InterfaceLib" '#182);
  138. Add('"{SharedLibraries}StdCLib" '#182);
  139. Add('"{SharedLibraries}MathLib" '#182);
  140. Add('"{PPCLibraries}StdCRuntime.o" '#182);
  141. Add('"{PPCLibraries}PPCCRuntime.o" '#182);
  142. {Add main objectfiles}
  143. while not ObjectFiles.Empty do
  144. begin
  145. s:=ObjectFiles.GetFirst;
  146. if s<>'' then
  147. Add(s+' '#182);
  148. end;
  149. {Add last lines of the link command}
  150. if true then //If SIOW, to avoid some warnings.
  151. Add('-ignoredups __start -ignoredups .__start -ignoredups main -ignoredups .main '#182);
  152. Add('-tocdataref off -sym on -dead on -o '+ current_module.exefilename^);
  153. {Add mac resources}
  154. if true then //If SIOW
  155. Add('Rez -append "{RIncludes}"SIOW.r -o ' + current_module.exefilename^);
  156. success:= true;
  157. end;
  158. MakeExecutable:=success; { otherwise a recursive call to link method }
  159. end;
  160. {*****************************************************************************
  161. Initialize
  162. *****************************************************************************}
  163. initialization
  164. {$ifdef m68k}
  165. RegisterTarget(system_m68k_macos_info);
  166. RegisterImport(system_m68k_macos,timportlibmacos);
  167. {$endif m68k}
  168. {$ifdef powerpc}
  169. RegisterExternalLinker(system_powerpc_macos_info,TLinkerMPW);
  170. RegisterTarget(system_powerpc_macos_info);
  171. RegisterImport(system_powerpc_macos,timportlibmacos);
  172. {$endif powerpc}
  173. end.
  174. {
  175. $Log$
  176. Revision 1.7 2004-02-19 20:40:20 olle
  177. + Support for Link on target especially for MacOS
  178. + TLinkerMPW
  179. + TAsmScriptMPW
  180. Revision 1.6 2003/04/27 08:52:00 florian
  181. * another compile fix
  182. Revision 1.5 2003/04/27 08:50:45 peter
  183. * compile fix
  184. Revision 1.4 2002/11/17 16:32:04 carl
  185. * memory optimization (3-4%) : cleanup of tai fields,
  186. cleanup of tdef and tsym fields.
  187. * make it work for m68k
  188. Revision 1.3 2002/10/16 20:18:33 olle
  189. * header comment updated
  190. Revision 1.2 2002/10/02 21:50:19 florian
  191. * importing via external is now possible for macos
  192. Revision 1.1 2002/09/06 15:03:50 carl
  193. * moved files to systems directory
  194. Revision 1.13 2002/08/20 21:40:44 florian
  195. + target macos for ppc added
  196. + frame work for mpw assembler output
  197. Revision 1.12 2002/07/26 21:15:46 florian
  198. * rewrote the system handling
  199. }