fpc.pp 5.7 KB

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