fpc.pp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. {$ifdef NETWARE}
  32. exeext='.nlm';
  33. {$else}
  34. exeext='.exe';
  35. {$endif NETWARE}
  36. {$endif MORPHOS}
  37. {$endif AMIGA}
  38. {$endif UNIX}
  39. procedure error(const s : string);
  40. begin
  41. writeln('Error: ',s);
  42. halt(1);
  43. end;
  44. function SplitPath(Const HStr:String):String;
  45. var
  46. i : longint;
  47. begin
  48. i:=Length(Hstr);
  49. while (i>0) and not(Hstr[i] in ['\','/']) do
  50. dec(i);
  51. SplitPath:=Copy(Hstr,1,i);
  52. end;
  53. function FileExists ( Const F : String) : Boolean;
  54. var
  55. Info : SearchRec;
  56. begin
  57. findfirst(F,readonly+archive+hidden,info);
  58. FileExists:=(doserror=0);
  59. findclose(Info);
  60. end;
  61. procedure findexe(var ppcbin:string);
  62. var
  63. path : string;
  64. begin
  65. { add .exe extension }
  66. ppcbin:=ppcbin+exeext;
  67. { get path of fpc.exe }
  68. path:=splitpath(paramstr(0));
  69. if FileExists(path+ppcbin) then
  70. ppcbin:=path+ppcbin
  71. else
  72. begin
  73. path:=FSearch(ppcbin,getenv('PATH'));
  74. if path<>'' then
  75. ppcbin:=path;
  76. end;
  77. end;
  78. var
  79. s : ansistring;
  80. processorname,
  81. ppcbin,
  82. versionStr,
  83. processorstr : string;
  84. ppccommandline : ansistring;
  85. i : longint;
  86. errorvalue : Longint;
  87. begin
  88. ppccommandline:='';
  89. {$ifdef i386}
  90. ppcbin:='ppc386';
  91. processorname:='i386';
  92. {$endif i386}
  93. {$ifdef m68k}
  94. ppcbin:='ppc68k';
  95. processorname:='m68k';
  96. {$endif m68k}
  97. {$ifdef alpha}
  98. ppcbin:='ppcapx';
  99. processorname:='alpha';
  100. {$endif alpha}
  101. {$ifdef powerpc}
  102. ppcbin:='ppcppc';
  103. processorname:='powerpc';
  104. {$endif powerpc}
  105. {$ifdef arm}
  106. ppcbin:='ppcarm';
  107. processorname:='arm';
  108. {$endif arm}
  109. {$ifdef sparc}
  110. ppcbin:='ppcsparc';
  111. processorname:='sparc';
  112. {$endif sparc}
  113. {$ifdef x86_64}
  114. ppcbin:='ppcx64';
  115. processorname:='x86_64';
  116. {$endif x86_64}
  117. {$ifdef ia64}
  118. ppcbin:='ppcia64';
  119. processorname:='ia64';
  120. {$endif ia64}
  121. versionstr:=''; { Default is just the name }
  122. for i:=1 to paramcount do
  123. begin
  124. s:=paramstr(i);
  125. if pos('-V',s)=1 then
  126. versionstr:=copy(s,3,length(s)-2)
  127. else
  128. begin
  129. if pos('-P',s)=1 then
  130. begin
  131. processorstr:=copy(s,3,length(s)-2);
  132. { -PB is a special code that will show the
  133. default compiler and exit immediatly. It's
  134. main usage is for Makefile }
  135. if processorstr='B' then
  136. begin
  137. { report the full name of the ppcbin }
  138. findexe(ppcbin);
  139. writeln(ppcbin);
  140. halt(0);
  141. end
  142. { -PP is a special code that will show the
  143. processor and exit immediatly. It's
  144. main usage is for Makefile }
  145. else if processorstr='P' then
  146. begin
  147. { report the processor }
  148. writeln(processorname);
  149. halt(0);
  150. end
  151. else if processorstr='i386' then
  152. ppcbin:='ppc386'
  153. else if processorstr='m68k' then
  154. ppcbin:='ppc68k'
  155. else if processorstr='alpha' then
  156. ppcbin:='ppcapx'
  157. else if processorstr='powerpc' then
  158. ppcbin:='ppcppc'
  159. else if processorstr='arm' then
  160. ppcbin:='ppcarm'
  161. else if processorstr='sparc' then
  162. ppcbin:='ppcsparc'
  163. else if processorstr='ia64' then
  164. ppcbin:='ppcia64'
  165. else if processorstr='x86_64' then
  166. ppcbin:='ppcx64'
  167. else error('Illegal processor type "'+processorstr+'"');
  168. end
  169. else
  170. ppccommandline:=ppccommandline+s+' ';
  171. end;
  172. end;
  173. if versionstr<>'' then
  174. ppcbin:=ppcbin+'-'+versionstr;
  175. { find the full path to the specified exe }
  176. findexe(ppcbin);
  177. { call ppcXXX }
  178. try
  179. errorvalue:=ExecuteProcess(ppcbin,ppccommandline);
  180. except
  181. on e : exception do
  182. error(ppcbin+' can''t be executed, error message: '+e.message);
  183. end;
  184. if errorvalue<>0 then
  185. error(ppcbin+' returned an error exitcode (normal if you did not specify a source file to be compiled)');
  186. halt(errorvalue);
  187. end.
  188. {
  189. $Log$
  190. Revision 1.20 2005-05-08 19:56:59 marco
  191. * typo fixed
  192. Revision 1.19 2005/02/14 17:13:10 peter
  193. * truncate log
  194. Revision 1.18 2005/01/14 21:04:44 armin
  195. * added .nlm extension for netware
  196. }