t_palmos.pas 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. {
  2. $Id$
  3. Copyright (c) 2001-2002 by Peter Vreman
  4. This unit implements support import,export,link routines
  5. for the (i386) Amiga 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_palmos;
  20. {$i fpcdefs.inc}
  21. interface
  22. uses
  23. link;
  24. type
  25. tlinkerPalmOS=class(texternallinker)
  26. private
  27. Function WriteResponseFile : Boolean;
  28. public
  29. constructor Create;override;
  30. procedure SetDefaultInfo;override;
  31. function MakeExecutable:boolean;override;
  32. end;
  33. implementation
  34. uses
  35. cutils,cclasses,
  36. globtype,globals,systems,verbose,script,fmodule,i_palmos;
  37. {****************************************************************************
  38. TLinkerPalmOS
  39. ****************************************************************************}
  40. Constructor TLinkerPalmOS.Create;
  41. begin
  42. Inherited Create;
  43. { allow duplicated libs (PM) }
  44. SharedLibFiles.doubles:=true;
  45. StaticLibFiles.doubles:=true;
  46. end;
  47. procedure TLinkerPalmOS.SetDefaultInfo;
  48. begin
  49. with Info do
  50. begin
  51. ExeCmd[1]:='ldpalm $OPT $STRIP -N -dy -T $SCRIPT -o $EXE @$RES';
  52. ExeCmd[2]:='build-prc $EXE.prc "$APPNAME" $APPID $EXE *.bin';
  53. end;
  54. end;
  55. Function TLinkerPalmOS.WriteResponseFile : Boolean;
  56. Var
  57. linkres : TLinkRes;
  58. i : longint;
  59. HPath : PStringQueueItem;
  60. s : string;
  61. linklibc : boolean;
  62. begin
  63. WriteResponseFile:=False;
  64. { Open link.res file }
  65. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName);
  66. { Write path to search libraries }
  67. HPath:=TStringListItem(current_module.locallibrarysearchpath.First);
  68. while assigned(HPath) do
  69. begin
  70. LinkRes.Add('-L'+HPath.Str);
  71. HPath:=TStringListItem(HPath.Next);
  72. end;
  73. HPath:=TStringListItem(LibrarySearchPath.First);
  74. while assigned(HPath) do
  75. begin
  76. LinkRes.Add('-L'+HPath.Str);
  77. HPath:=TStringListItem(HPath.Next);
  78. end;
  79. { add objectfiles, start with crt0 always }
  80. { using crt0, we should stick C compatible }
  81. LinkRes.AddFileName(FindObjectFile('crt0',''));
  82. { main objectfiles }
  83. while not ObjectFiles.Empty do
  84. begin
  85. s:=ObjectFiles.GetFirst;
  86. if s<>'' then
  87. LinkRes.AddFileName(s);
  88. end;
  89. { Write staticlibraries }
  90. if not StaticLibFiles.Empty then
  91. begin
  92. LinkRes.Add('-(');
  93. While not StaticLibFiles.Empty do
  94. begin
  95. S:=StaticLibFiles.GetFirst;
  96. LinkRes.AddFileName(s)
  97. end;
  98. LinkRes.Add('-)');
  99. end;
  100. { currently the PalmOS target must be linked always against the C lib }
  101. LinkRes.Add('-lcrt');
  102. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  103. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  104. linklibc:=false;
  105. While not SharedLibFiles.Empty do
  106. begin
  107. S:=SharedLibFiles.GetFirst;
  108. if s<>'c' then
  109. begin
  110. i:=Pos(target_info.sharedlibext,S);
  111. if i>0 then
  112. Delete(S,i,255);
  113. LinkRes.Add('-l'+s);
  114. end
  115. else
  116. linklibc:=true;
  117. end;
  118. { be sure that libc is the last lib }
  119. if linklibc then
  120. begin
  121. LinkRes.Add('-lc');
  122. LinkRes.Add('-lgcc');
  123. end;
  124. { Write and Close response }
  125. linkres.writetodisk;
  126. linkres.Free;
  127. WriteResponseFile:=True;
  128. end;
  129. function TLinkerPalmOS.MakeExecutable:boolean;
  130. var
  131. binstr,
  132. cmdstr : string;
  133. success : boolean;
  134. StripStr : string[40];
  135. i : longint;
  136. begin
  137. if not(cs_link_extern in aktglobalswitches) then
  138. Message1(exec_i_linking,current_module^.exefilename^);
  139. { Create some replacements }
  140. StripStr:='';
  141. if (cs_link_strip in aktglobalswitches) then
  142. StripStr:='-s';
  143. { Write used files and libraries }
  144. WriteResponseFile;
  145. { Call linker }
  146. success:=false;
  147. for i:=1 to 2 do
  148. begin
  149. SplitBinCmd(Info.ExeCmd[i],binstr,cmdstr);
  150. if binstr<>'' then
  151. begin
  152. Replace(cmdstr,'$EXE',MaybeQuote(current_module.exefilename^));
  153. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  154. Replace(cmdstr,'$RES',outputexedir+Info.ResName);
  155. Replace(cmdstr,'$STRIP',StripStr);
  156. Replace(cmdstr,'$SCRIPT',FindUtil('palm.ld'));
  157. Replace(cmdstr,'$APPNAME',palmos_applicationname);
  158. Replace(cmdstr,'$APPID',palmos_applicationid);
  159. success:=DoExec(FindUtil(binstr),cmdstr,(i=1),false);
  160. if not success then
  161. break;
  162. end;
  163. end;
  164. { Remove ReponseFile }
  165. if (success) and not(cs_link_extern in aktglobalswitches) then
  166. RemoveFile(outputexedir+Info.ResName);
  167. MakeExecutable:=success; { otherwise a recursive call to link method }
  168. end;
  169. {*****************************************************************************
  170. Initialize
  171. *****************************************************************************}
  172. initialization
  173. {$ifdef m68k}
  174. RegisterTarget(target_m68k_palmos_info);
  175. RegisterRes(res_m68k_palmos_info);
  176. {$endif m68k}
  177. end.
  178. {
  179. $Log$
  180. Revision 1.2 2003-01-12 15:42:23 peter
  181. * m68k pathexist update from 1.0.x
  182. * palmos res update from 1.0.x
  183. Revision 1.1 2002/09/06 15:03:50 carl
  184. * moved files to systems directory
  185. Revision 1.14 2002/07/26 21:15:46 florian
  186. * rewrote the system handling
  187. Revision 1.13 2002/07/01 18:46:35 peter
  188. * internal linker
  189. * reorganized aasm layer
  190. Revision 1.12 2002/05/18 13:34:27 peter
  191. * readded missing revisions
  192. Revision 1.11 2002/05/16 19:46:53 carl
  193. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  194. + try to fix temp allocation (still in ifdef)
  195. + generic constructor calls
  196. + start of tassembler / tmodulebase class cleanup
  197. Revision 1.9 2002/04/22 18:19:22 carl
  198. - remove use_bound_instruction field
  199. Revision 1.8 2002/04/20 21:43:18 carl
  200. * fix stack size for some targets
  201. + add offset to parameters from frame pointer info.
  202. - remove some unused stuff
  203. Revision 1.7 2002/04/15 19:16:57 carl
  204. - remove size_of_pointer field
  205. }