t_palmos.pas 5.7 KB

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