fpc.pp 4.2 KB

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