fpc.pp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. {
  2. Copyright (c) 2000-2002 by Florian Klaempfl
  3. This file is the "loader" for the Free Pascal compiler
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************}
  16. program fpc;
  17. {$mode objfpc}{$H+}
  18. uses
  19. Sysutils;
  20. const
  21. {$ifdef UNIX}
  22. exeext='';
  23. {$else UNIX}
  24. {$ifdef AMIGA}
  25. exeext='';
  26. {$else}
  27. {$ifdef MORPHOS}
  28. exeext='';
  29. {$else}
  30. {$ifdef NETWARE}
  31. exeext='.nlm';
  32. {$else}
  33. exeext='.exe';
  34. {$endif NETWARE}
  35. {$endif MORPHOS}
  36. {$endif AMIGA}
  37. {$endif UNIX}
  38. procedure error(const s : string);
  39. begin
  40. writeln('Error: ',s);
  41. halt(1);
  42. end;
  43. function SplitPath(Const HStr:String):String;
  44. var
  45. i : longint;
  46. begin
  47. i:=Length(Hstr);
  48. while (i>0) and not(Hstr[i] in ['\','/']) do
  49. dec(i);
  50. SplitPath:=Copy(Hstr,1,i);
  51. end;
  52. function FileExists ( Const F : String) : Boolean;
  53. var
  54. Info : TSearchRec;
  55. begin
  56. FileExists:= findfirst(F,fareadonly+faarchive+fahidden,info)=0;
  57. findclose(Info);
  58. end;
  59. procedure findexe(var ppcbin:string);
  60. var
  61. path : string;
  62. begin
  63. { add .exe extension }
  64. ppcbin:=ppcbin+exeext;
  65. { get path of fpc.exe }
  66. path:=splitpath(paramstr(0));
  67. if FileExists(path+ppcbin) then
  68. ppcbin:=path+ppcbin
  69. else
  70. begin
  71. path:=FileSearch(ppcbin,getenvironmentvariable('PATH'));
  72. if path<>'' then
  73. ppcbin:=path;
  74. end;
  75. end;
  76. var
  77. s : ansistring;
  78. processorname,
  79. ppcbin,
  80. versionStr,
  81. processorstr : string;
  82. ppccommandline : ansistring;
  83. i : longint;
  84. errorvalue : Longint;
  85. begin
  86. ppccommandline:='';
  87. {$ifdef i386}
  88. ppcbin:='ppc386';
  89. processorname:='i386';
  90. {$endif i386}
  91. {$ifdef m68k}
  92. ppcbin:='ppc68k';
  93. processorname:='m68k';
  94. {$endif m68k}
  95. {$ifdef alpha}
  96. ppcbin:='ppcapx';
  97. processorname:='alpha';
  98. {$endif alpha}
  99. {$ifdef powerpc}
  100. ppcbin:='ppcppc';
  101. processorname:='powerpc';
  102. {$endif powerpc}
  103. {$ifdef powerpc64}
  104. ppcbin:='ppcppc64';
  105. processorname:='powerpc64';
  106. {$endif powerpc64}
  107. {$ifdef arm}
  108. ppcbin:='ppcarm';
  109. processorname:='arm';
  110. {$endif arm}
  111. {$ifdef sparc}
  112. ppcbin:='ppcsparc';
  113. processorname:='sparc';
  114. {$endif sparc}
  115. {$ifdef x86_64}
  116. ppcbin:='ppcx64';
  117. processorname:='x86_64';
  118. {$endif x86_64}
  119. {$ifdef ia64}
  120. ppcbin:='ppcia64';
  121. processorname:='ia64';
  122. {$endif ia64}
  123. versionstr:=''; { Default is just the name }
  124. for i:=1 to paramcount do
  125. begin
  126. s:=paramstr(i);
  127. if pos('-V',s)=1 then
  128. versionstr:=copy(s,3,length(s)-2)
  129. else
  130. begin
  131. if pos('-P',s)=1 then
  132. begin
  133. processorstr:=copy(s,3,length(s)-2);
  134. { -PB is a special code that will show the
  135. default compiler and exit immediatly. It's
  136. main usage is for Makefile }
  137. if processorstr='B' then
  138. begin
  139. { report the full name of the ppcbin }
  140. findexe(ppcbin);
  141. writeln(ppcbin);
  142. halt(0);
  143. end
  144. { -PP is a special code that will show the
  145. processor and exit immediatly. It's
  146. main usage is for Makefile }
  147. else if processorstr='P' then
  148. begin
  149. { report the processor }
  150. writeln(processorname);
  151. halt(0);
  152. end
  153. else if processorstr='i386' then
  154. ppcbin:='ppc386'
  155. else if processorstr='m68k' then
  156. ppcbin:='ppc68k'
  157. else if processorstr='alpha' then
  158. ppcbin:='ppcapx'
  159. else if processorstr='powerpc' then
  160. ppcbin:='ppcppc'
  161. else if processorstr='powerpc64' then
  162. ppcbin:='ppcppc64'
  163. else if processorstr='arm' then
  164. ppcbin:='ppcarm'
  165. else if processorstr='sparc' then
  166. ppcbin:='ppcsparc'
  167. else if processorstr='ia64' then
  168. ppcbin:='ppcia64'
  169. else if processorstr='x86_64' then
  170. ppcbin:='ppcx64'
  171. else error('Illegal processor type "'+processorstr+'"');
  172. end
  173. else
  174. ppccommandline:=ppccommandline+s+' ';
  175. end;
  176. end;
  177. if versionstr<>'' then
  178. ppcbin:=ppcbin+'-'+versionstr;
  179. { find the full path to the specified exe }
  180. findexe(ppcbin);
  181. { call ppcXXX }
  182. try
  183. errorvalue:=ExecuteProcess(ppcbin,ppccommandline);
  184. except
  185. on e : exception do
  186. error(ppcbin+' can''t be executed, error message: '+e.message);
  187. end;
  188. if errorvalue<>0 then
  189. error(ppcbin+' returned an error exitcode (normal if you did not specify a source file to be compiled)');
  190. halt(errorvalue);
  191. end.