fpc.pp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. processorstr : shortstring;
  74. ppccommandline : ansistring;
  75. i : longint;
  76. begin
  77. ppccommandline:='';
  78. {$ifdef i386}
  79. ppcbin:='ppc386';
  80. processorname:='i386';
  81. {$endif i386}
  82. {$ifdef m68k}
  83. ppcbin:='ppc68k';
  84. processorname:='m68k';
  85. {$endif m68k}
  86. {$ifdef alpha}
  87. ppcbin:='ppcapx';
  88. processorname:='alpha';
  89. {$endif alpha}
  90. {$ifdef powerpc}
  91. ppcbin:='ppcppc';
  92. processorname:='powerpc';
  93. {$endif powerpc}
  94. for i:=1 to paramcount do
  95. begin
  96. s:=paramstr(i);
  97. if pos('-P',s)=1 then
  98. begin
  99. processorstr:=copy(s,3,length(s)-2);
  100. { -PB is a special code that will show the
  101. default compiler and exit immediatly. It's
  102. main usage is for Makefile }
  103. if processorstr='B' then
  104. begin
  105. { report the full name of the ppcbin }
  106. findexe(ppcbin);
  107. writeln(ppcbin);
  108. halt(0);
  109. end
  110. { -PP is a special code that will show the
  111. processor and exit immediatly. It's
  112. main usage is for Makefile }
  113. else if processorstr='P' then
  114. begin
  115. { report the processor }
  116. writeln(processorname);
  117. halt(0);
  118. end
  119. else if processorstr='i386' then
  120. ppcbin:='ppc386'
  121. else if processorstr='m68k' then
  122. ppcbin:='ppc68k'
  123. else if processorstr='alpha' then
  124. ppcbin:='ppcapx'
  125. else if processorstr='powerpc' then
  126. ppcbin:='ppcppc'
  127. else error('Illegal processor type "'+processorstr+'"');
  128. end
  129. else
  130. ppccommandline:=ppccommandline+s+' ';
  131. end;
  132. { find the full path to the specified exe }
  133. findexe(ppcbin);
  134. { call ppcXXX }
  135. swapvectors;
  136. exec(ppcbin,ppccommandline);
  137. swapvectors;
  138. if doserror<>0 then
  139. error(ppcbin+' can''t be executed');
  140. halt(dosexitcode);
  141. end.
  142. {
  143. $Log$
  144. Revision 1.5 2003-04-08 16:01:40 peter
  145. * amiga has also no .exe
  146. Revision 1.4 2002/05/18 13:34:27 peter
  147. * readded missing revisions
  148. }