t_palmos.pas 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. {
  2. Copyright (c) 2001-2002 by Peter Vreman
  3. This unit implements support import,export,link routines
  4. for the (i386) Amiga 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_palmos;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. link;
  23. type
  24. tlinkerPalmOS=class(texternallinker)
  25. private
  26. Function WriteResponseFile : Boolean;
  27. public
  28. constructor Create;override;
  29. procedure SetDefaultInfo;override;
  30. function MakeExecutable:boolean;override;
  31. end;
  32. implementation
  33. uses
  34. cutils,cclasses,
  35. globtype,globals,systems,verbose,script,fmodule,i_palmos;
  36. {****************************************************************************
  37. TLinkerPalmOS
  38. ****************************************************************************}
  39. Constructor TLinkerPalmOS.Create;
  40. begin
  41. Inherited Create;
  42. { allow duplicated libs (PM) }
  43. SharedLibFiles.doubles:=true;
  44. StaticLibFiles.doubles:=true;
  45. end;
  46. procedure TLinkerPalmOS.SetDefaultInfo;
  47. begin
  48. with Info do
  49. begin
  50. ExeCmd[1]:='ldpalm $OPT $STRIP -N -dy -T $SCRIPT -o $EXE @$RES';
  51. ExeCmd[2]:='build-prc $EXE.prc "$APPNAME" $APPID $EXE *.bin';
  52. end;
  53. end;
  54. Function TLinkerPalmOS.WriteResponseFile : Boolean;
  55. Var
  56. linkres : TLinkRes;
  57. i : longint;
  58. HPath : TStringListItem;
  59. s : string;
  60. linklibc : boolean;
  61. begin
  62. WriteResponseFile:=False;
  63. { Open link.res file }
  64. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName);
  65. { Write path to search libraries }
  66. HPath:=TStringListItem(current_module.locallibrarysearchpath.First);
  67. while assigned(HPath) do
  68. begin
  69. LinkRes.Add('-L'+HPath.Str);
  70. HPath:=TStringListItem(HPath.Next);
  71. end;
  72. HPath:=TStringListItem(LibrarySearchPath.First);
  73. while assigned(HPath) do
  74. begin
  75. LinkRes.Add('-L'+HPath.Str);
  76. HPath:=TStringListItem(HPath.Next);
  77. end;
  78. { add objectfiles, start with crt0 always }
  79. { using crt0, we should stick C compatible }
  80. LinkRes.AddFileName(FindObjectFile('crt0','',false));
  81. { main objectfiles }
  82. while not ObjectFiles.Empty do
  83. begin
  84. s:=ObjectFiles.GetFirst;
  85. if s<>'' then
  86. LinkRes.AddFileName(s);
  87. end;
  88. { Write staticlibraries }
  89. if not StaticLibFiles.Empty then
  90. begin
  91. LinkRes.Add('-(');
  92. While not StaticLibFiles.Empty do
  93. begin
  94. S:=StaticLibFiles.GetFirst;
  95. LinkRes.AddFileName(s)
  96. end;
  97. LinkRes.Add('-)');
  98. end;
  99. { currently the PalmOS target must be linked always against the C lib }
  100. LinkRes.Add('-lcrt');
  101. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  102. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  103. linklibc:=false;
  104. While not SharedLibFiles.Empty do
  105. begin
  106. S:=SharedLibFiles.GetFirst;
  107. if s<>'c' then
  108. begin
  109. i:=Pos(target_info.sharedlibext,S);
  110. if i>0 then
  111. Delete(S,i,255);
  112. LinkRes.Add('-l'+s);
  113. end
  114. else
  115. linklibc:=true;
  116. end;
  117. { be sure that libc is the last lib }
  118. if linklibc then
  119. begin
  120. LinkRes.Add('-lc');
  121. LinkRes.Add('-lgcc');
  122. end;
  123. { Write and Close response }
  124. linkres.writetodisk;
  125. linkres.Free;
  126. WriteResponseFile:=True;
  127. end;
  128. function TLinkerPalmOS.MakeExecutable:boolean;
  129. var
  130. binstr,
  131. cmdstr : string;
  132. success : boolean;
  133. StripStr : string[40];
  134. i : longint;
  135. begin
  136. if not(cs_link_extern in aktglobalswitches) then
  137. Message1(exec_i_linking,current_module.exefilename^);
  138. { Create some replacements }
  139. StripStr:='';
  140. if (cs_link_strip in aktglobalswitches) then
  141. StripStr:='-s';
  142. { Write used files and libraries }
  143. WriteResponseFile;
  144. { Call linker }
  145. success:=false;
  146. for i:=1 to 2 do
  147. begin
  148. SplitBinCmd(Info.ExeCmd[i],binstr,cmdstr);
  149. if binstr<>'' then
  150. begin
  151. Replace(cmdstr,'$EXE',MaybeQuoted(current_module.exefilename^));
  152. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  153. Replace(cmdstr,'$RES',MaybeQuoted(outputexedir+Info.ResName));
  154. Replace(cmdstr,'$STRIP',StripStr);
  155. Replace(cmdstr,'$SCRIPT',FindUtil('palm.ld'));
  156. Replace(cmdstr,'$APPNAME',palmos_applicationname);
  157. Replace(cmdstr,'$APPID',palmos_applicationid);
  158. success:=DoExec(FindUtil(binstr),cmdstr,(i=1),false);
  159. if not success then
  160. break;
  161. end;
  162. end;
  163. { Remove ReponseFile }
  164. if (success) and not(cs_link_extern in aktglobalswitches) then
  165. RemoveFile(outputexedir+Info.ResName);
  166. MakeExecutable:=success; { otherwise a recursive call to link method }
  167. end;
  168. {*****************************************************************************
  169. Initialize
  170. *****************************************************************************}
  171. initialization
  172. {$ifdef m68k}
  173. RegisterTarget(system_m68k_palmos_info);
  174. RegisterRes(res_m68k_palmos_info);
  175. {$endif m68k}
  176. {$ifdef arm}
  177. RegisterTarget(system_arm_palmos_info);
  178. RegisterRes(res_arm_palmos_info);
  179. {$endif arm}
  180. end.