2
0

fpc.pp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. {
  2. $Id$
  3. Copyright (c) 2000 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. ppcbin,
  68. processorstr : shortstring;
  69. ppccommandline : ansistring;
  70. i : longint;
  71. begin
  72. ppccommandline:='';
  73. {$ifdef i386}
  74. ppcbin:='ppc386';
  75. {$endif i386}
  76. {$ifdef m68k}
  77. ppcbin:='ppc68k';
  78. {$endif m68k}
  79. {$ifdef alpha}
  80. ppcbin:='ppcapx';
  81. {$endif alpha}
  82. {$ifdef powerpc}
  83. ppcbin:='ppcppc';
  84. {$endif powerpc}
  85. for i:=1 to paramcount do
  86. begin
  87. s:=paramstr(i);
  88. if pos('-P',s)=1 then
  89. begin
  90. processorstr:=copy(s,3,length(s)-2);
  91. { -P? is a special code that will show the
  92. default compiler and exit immediatly. It's
  93. main usage is for Makefile }
  94. if processorstr='?' then
  95. begin
  96. { report the full name of the ppcbin }
  97. findexe(ppcbin);
  98. writeln(ppcbin);
  99. halt(0);
  100. end
  101. else if processorstr='i386' then
  102. ppcbin:='ppc386'
  103. else if processorstr='m68k' then
  104. ppcbin:='ppc68k'
  105. else if processorstr='alpha' then
  106. ppcbin:='ppcapx'
  107. else if processorstr='powerpc' then
  108. ppcbin:='ppcppc'
  109. else error('Illegal processor type "'+processorstr+'"');
  110. end
  111. else
  112. ppccommandline:=ppccommandline+s+' ';
  113. end;
  114. { find the full path to the specified exe }
  115. findexe(ppcbin);
  116. { call ppcXXX }
  117. swapvectors;
  118. exec(ppcbin,ppccommandline);
  119. swapvectors;
  120. if doserror<>0 then
  121. error(ppcbin+' can''t be executed');
  122. halt(dosexitcode);
  123. end.
  124. {
  125. $Log$
  126. Revision 1.2 2001-09-22 11:11:43 peter
  127. * "fpc -P?" command to query for used ppcXXX compiler
  128. Revision 1.1.2.1 2001/04/25 22:43:24 peter
  129. * compiler dependent utils in utils/ subdir
  130. Revision 1.1.2.2 2000/12/12 19:47:40 peter
  131. * fixed for go32v2 and win32
  132. Revision 1.1.2.1 2000/11/18 14:16:12 peter
  133. * really working now
  134. Revision 1.1 2000/07/13 06:29:50 michael
  135. + Initial import
  136. Revision 1.1 2000/07/07 17:07:20 florian
  137. + initial revision
  138. }