fpc.pp 5.4 KB

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