t_palmos.pas 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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,cfileutils,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 : TCmdStrListItem;
  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:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
  68. while assigned(HPath) do
  69. begin
  70. LinkRes.Add('-L'+HPath.Str);
  71. HPath:=TCmdStrListItem(HPath.Next);
  72. end;
  73. HPath:=TCmdStrListItem(LibrarySearchPath.First);
  74. while assigned(HPath) do
  75. begin
  76. LinkRes.Add('-L'+HPath.Str);
  77. HPath:=TCmdStrListItem(HPath.Next);
  78. end;
  79. { add objectfiles, start with crt0 always }
  80. { using crt0, we should stick C compatible }
  81. LinkRes.AddFileName(FindObjectFile('crt0','',false));
  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 : TPathStr;
  132. cmdstr : TCmdStr;
  133. success : boolean;
  134. StripStr : string[40];
  135. i : longint;
  136. begin
  137. if not(cs_link_nolink in current_settings.globalswitches) then
  138. Message1(exec_i_linking,current_module.exefilename^);
  139. { Create some replacements }
  140. StripStr:='';
  141. if (cs_link_strip in current_settings.globalswitches) 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',MaybeQuoted(current_module.exefilename^));
  153. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  154. Replace(cmdstr,'$RES',MaybeQuoted(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_nolink in current_settings.globalswitches) then
  166. DeleteFile(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(system_m68k_palmos_info);
  175. RegisterRes(res_m68k_palmos_info);
  176. {$endif m68k}
  177. {$ifdef arm}
  178. RegisterTarget(system_arm_palmos_info);
  179. RegisterRes(res_arm_palmos_info);
  180. {$endif arm}
  181. end.