fpc.pp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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,dos;
  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 : SearchRec;
  55. begin
  56. findfirst(F,readonly+archive+hidden,info);
  57. FileExists:=(doserror=0);
  58. findclose(Info);
  59. end;
  60. procedure findexe(var ppcbin:string);
  61. var
  62. path : string;
  63. begin
  64. { add .exe extension }
  65. ppcbin:=ppcbin+exeext;
  66. { get path of fpc.exe }
  67. path:=splitpath(paramstr(0));
  68. if FileExists(path+ppcbin) then
  69. ppcbin:=path+ppcbin
  70. else
  71. begin
  72. path:=FSearch(ppcbin,getenv('PATH'));
  73. if path<>'' then
  74. ppcbin:=path;
  75. end;
  76. end;
  77. var
  78. s : ansistring;
  79. processorname,
  80. ppcbin,
  81. versionStr,
  82. processorstr : string;
  83. ppccommandline : ansistring;
  84. i : longint;
  85. errorvalue : Longint;
  86. begin
  87. ppccommandline:='';
  88. {$ifdef i386}
  89. ppcbin:='ppc386';
  90. processorname:='i386';
  91. {$endif i386}
  92. {$ifdef m68k}
  93. ppcbin:='ppc68k';
  94. processorname:='m68k';
  95. {$endif m68k}
  96. {$ifdef alpha}
  97. ppcbin:='ppcapx';
  98. processorname:='alpha';
  99. {$endif alpha}
  100. {$ifdef powerpc}
  101. ppcbin:='ppcppc';
  102. processorname:='powerpc';
  103. {$endif powerpc}
  104. {$ifdef arm}
  105. ppcbin:='ppcarm';
  106. processorname:='arm';
  107. {$endif arm}
  108. {$ifdef sparc}
  109. ppcbin:='ppcsparc';
  110. processorname:='sparc';
  111. {$endif sparc}
  112. {$ifdef x86_64}
  113. ppcbin:='ppcx64';
  114. processorname:='x86_64';
  115. {$endif x86_64}
  116. {$ifdef ia64}
  117. ppcbin:='ppcia64';
  118. processorname:='ia64';
  119. {$endif ia64}
  120. versionstr:=''; { Default is just the name }
  121. for i:=1 to paramcount do
  122. begin
  123. s:=paramstr(i);
  124. if pos('-V',s)=1 then
  125. versionstr:=copy(s,3,length(s)-2)
  126. else
  127. begin
  128. if pos('-P',s)=1 then
  129. begin
  130. processorstr:=copy(s,3,length(s)-2);
  131. { -PB is a special code that will show the
  132. default compiler and exit immediatly. It's
  133. main usage is for Makefile }
  134. if processorstr='B' then
  135. begin
  136. { report the full name of the ppcbin }
  137. findexe(ppcbin);
  138. writeln(ppcbin);
  139. halt(0);
  140. end
  141. { -PP is a special code that will show the
  142. processor and exit immediatly. It's
  143. main usage is for Makefile }
  144. else if processorstr='P' then
  145. begin
  146. { report the processor }
  147. writeln(processorname);
  148. halt(0);
  149. end
  150. else if processorstr='i386' then
  151. ppcbin:='ppc386'
  152. else if processorstr='m68k' then
  153. ppcbin:='ppc68k'
  154. else if processorstr='alpha' then
  155. ppcbin:='ppcapx'
  156. else if processorstr='powerpc' then
  157. ppcbin:='ppcppc'
  158. else if processorstr='arm' then
  159. ppcbin:='ppcarm'
  160. else if processorstr='sparc' then
  161. ppcbin:='ppcsparc'
  162. else if processorstr='ia64' then
  163. ppcbin:='ppcia64'
  164. else if processorstr='x86_64' then
  165. ppcbin:='ppcx64'
  166. else error('Illegal processor type "'+processorstr+'"');
  167. end
  168. else
  169. ppccommandline:=ppccommandline+s+' ';
  170. end;
  171. end;
  172. if versionstr<>'' then
  173. ppcbin:=ppcbin+'-'+versionstr;
  174. { find the full path to the specified exe }
  175. findexe(ppcbin);
  176. { call ppcXXX }
  177. try
  178. errorvalue:=ExecuteProcess(ppcbin,ppccommandline);
  179. except
  180. on e : exception do
  181. error(ppcbin+' can''t be executed, error message: '+e.message);
  182. end;
  183. if errorvalue<>0 then
  184. error(ppcbin+' returned an error exitcode (normal if you did not specify a source file to be compiled)');
  185. halt(errorvalue);
  186. end.