fpc.pp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. {
  2. $Id$
  3. Copyright (c) 2000-2002 by Florian Klaempfl
  4. This file is the "loader" for the Free Pascal compiler
  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. program fpc;
  18. {$mode objfpc}{$H+}
  19. uses
  20. Sysutils,dos;
  21. const
  22. {$ifdef UNIX}
  23. exeext='';
  24. {$else UNIX}
  25. {$ifdef AMIGA}
  26. exeext='';
  27. {$else}
  28. {$ifdef MORPHOS}
  29. exeext='';
  30. {$else}
  31. exeext='.exe';
  32. {$endif}
  33. {$endif}
  34. {$endif UNIX}
  35. procedure error(const s : string);
  36. begin
  37. writeln('Error: ',s);
  38. halt(1);
  39. end;
  40. function SplitPath(Const HStr:String):String;
  41. var
  42. i : longint;
  43. begin
  44. i:=Length(Hstr);
  45. while (i>0) and not(Hstr[i] in ['\','/']) do
  46. dec(i);
  47. SplitPath:=Copy(Hstr,1,i);
  48. end;
  49. function FileExists ( Const F : String) : Boolean;
  50. var
  51. Info : SearchRec;
  52. begin
  53. findfirst(F,readonly+archive+hidden,info);
  54. FileExists:=(doserror=0);
  55. findclose(Info);
  56. end;
  57. procedure findexe(var ppcbin:string);
  58. var
  59. path : string;
  60. begin
  61. { add .exe extension }
  62. ppcbin:=ppcbin+exeext;
  63. { get path of fpc.exe }
  64. path:=splitpath(paramstr(0));
  65. if FileExists(path+ppcbin) then
  66. ppcbin:=path+ppcbin
  67. else
  68. begin
  69. path:=FSearch(ppcbin,getenv('PATH'));
  70. if path<>'' then
  71. ppcbin:=path;
  72. end;
  73. end;
  74. var
  75. s : ansistring;
  76. processorname,
  77. ppcbin,
  78. versionStr,
  79. processorstr : string;
  80. ppccommandline : ansistring;
  81. i : longint;
  82. errorvalue : Longint;
  83. begin
  84. ppccommandline:='';
  85. {$ifdef i386}
  86. ppcbin:='ppc386';
  87. processorname:='i386';
  88. {$endif i386}
  89. {$ifdef m68k}
  90. ppcbin:='ppc68k';
  91. processorname:='m68k';
  92. {$endif m68k}
  93. {$ifdef alpha}
  94. ppcbin:='ppcapx';
  95. processorname:='alpha';
  96. {$endif alpha}
  97. {$ifdef powerpc}
  98. ppcbin:='ppcppc';
  99. processorname:='powerpc';
  100. {$endif powerpc}
  101. {$ifdef arm}
  102. ppcbin:='ppcarm';
  103. processorname:='arm';
  104. {$endif arm}
  105. {$ifdef sparc}
  106. ppcbin:='ppcsparc';
  107. processorname:='sparc';
  108. {$endif sparc}
  109. {$ifdef x86_64}
  110. ppcbin:='ppcx86_64';
  111. processorname:='x86_64';
  112. {$endif x86_64}
  113. {$ifdef ia64}
  114. ppcbin:='ppcia64';
  115. processorname:='ia64';
  116. {$endif ia64}
  117. versionstr:=''; { Default is just the name }
  118. for i:=1 to paramcount do
  119. begin
  120. s:=paramstr(i);
  121. if pos('-V',s)=1 then
  122. versionstr:=copy(s,3,length(s)-2)
  123. else
  124. begin
  125. if pos('-P',s)=1 then
  126. begin
  127. processorstr:=copy(s,3,length(s)-2);
  128. { -PB is a special code that will show the
  129. default compiler and exit immediatly. It's
  130. main usage is for Makefile }
  131. if processorstr='B' then
  132. begin
  133. { report the full name of the ppcbin }
  134. findexe(ppcbin);
  135. writeln(ppcbin);
  136. halt(0);
  137. end
  138. { -PP is a special code that will show the
  139. processor and exit immediatly. It's
  140. main usage is for Makefile }
  141. else if processorstr='P' then
  142. begin
  143. { report the processor }
  144. writeln(processorname);
  145. halt(0);
  146. end
  147. else if processorstr='i386' then
  148. ppcbin:='ppc386'
  149. else if processorstr='m68k' then
  150. ppcbin:='ppc68k'
  151. else if processorstr='alpha' then
  152. ppcbin:='ppcapx'
  153. else if processorstr='powerpc' then
  154. ppcbin:='ppcppc'
  155. else if processorstr='arm' then
  156. ppcbin:='ppcarm'
  157. else if processorstr='sparc' then
  158. ppcbin:='ppcsparc'
  159. else if processorstr='ia64' then
  160. ppcbin:='ppcia64'
  161. else if processorstr='x86_64' then
  162. ppcbin:='ppcx64_64'
  163. else error('Illegal processor type "'+processorstr+'"');
  164. end
  165. else
  166. ppccommandline:=ppccommandline+s+' ';
  167. end;
  168. end;
  169. if versionstr<>'' then
  170. ppcbin:=ppcbin+'-'+versionstr;
  171. { find the full path to the specified exe }
  172. findexe(ppcbin);
  173. { call ppcXXX }
  174. try
  175. errorvalue:=ExecuteProcess(ppcbin,ppccommandline);
  176. except
  177. on e : exception do
  178. error(ppcbin+' can''t be executed, error message: '+e.message);
  179. end;
  180. if errorvalue<>0 then
  181. error(ppcbin+' can''t be executed');
  182. halt(errorvalue);
  183. end.
  184. {
  185. $Log$
  186. Revision 1.15 2004-06-06 01:18:47 karoly
  187. * morphos has no .exe just like amiga
  188. Revision 1.14 2004/06/05 10:14:42 marco
  189. * fix for bug 3127
  190. Revision 1.13 2004/03/20 22:29:37 florian
  191. + arm, ia64, x86_64 and sparc supported added
  192. Revision 1.12 2004/01/26 20:34:24 florian
  193. * improved error message
  194. Revision 1.11 2004/01/05 22:41:20 florian
  195. * changed sysutils.exec to ExecuteProcess
  196. Revision 1.10 2004/01/03 09:20:45 marco
  197. * errorhandling fixed
  198. Revision 1.9 2004/01/03 09:12:23 marco
  199. * unix does ansistring exec
  200. Revision 1.8 2003/10/08 19:16:50 peter
  201. * -Q back to -P, -L back to -V
  202. Revision 1.7 2003/09/30 17:25:01 marco
  203. * -Q=-P and -L=-V
  204. Revision 1.6 2003/09/30 11:24:59 marco
  205. * -V support
  206. Revision 1.5 2003/04/08 16:01:40 peter
  207. * amiga has also no .exe
  208. Revision 1.4 2002/05/18 13:34:27 peter
  209. * readded missing revisions
  210. }