fpc.pas 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. procedure error(const s : string);
  21. begin
  22. writeln('Error: ',s);
  23. halt(1);
  24. end;
  25. function SplitPath(Const HStr:ShortString):ShortString;
  26. var
  27. i : longint;
  28. begin
  29. i:=Length(Hstr);
  30. while (i>0) and not(Hstr[i] in ['\','/']) do
  31. dec(i);
  32. SplitPath:=Copy(Hstr,1,i);
  33. end;
  34. function FileExists ( Const F : ShortString) : Boolean;
  35. var
  36. Info : SearchRec;
  37. begin
  38. findfirst(F,readonly+archive+hidden,info);
  39. FileExists:=(doserror=0);
  40. findclose(Info);
  41. end;
  42. var
  43. s,path,
  44. ppcbin,
  45. processorstr : shortstring;
  46. ppccommandline : ansistring;
  47. i : longint;
  48. begin
  49. ppccommandline:='';
  50. {$ifdef i386}
  51. ppcbin:='ppc386';
  52. {$endif i386}
  53. {$ifdef m68k}
  54. ppcbin:='ppc68k';
  55. {$endif m68k}
  56. {$ifdef alpha}
  57. ppcbin:='ppcapx';
  58. {$endif alpha}
  59. {$ifdef powerpc}
  60. ppcbin:='ppcppc';
  61. {$endif powerpc}
  62. for i:=1 to paramcount do
  63. begin
  64. s:=paramstr(i);
  65. if pos('-P',s)=1 then
  66. begin
  67. processorstr:=copy(s,3,length(s)-2);
  68. if processorstr='i386' then
  69. ppcbin:='ppc386'
  70. else if processorstr='m68k' then
  71. ppcbin:='ppc68k'
  72. else if processorstr='alpha' then
  73. ppcbin:='ppcapx'
  74. else if processorstr='powerpc' then
  75. ppcbin:='ppcppc'
  76. else error('Illegal processor type "'+processorstr+'"');
  77. end
  78. else
  79. ppccommandline:=ppccommandline+s+' ';
  80. end;
  81. { get path of fpc.exe }
  82. path:=splitpath(paramstr(0));
  83. if FileExists(path+ppcbin) then
  84. ppcbin:=path+ppcbin
  85. else
  86. begin
  87. path:=FSearch(ppcbin,getenv('PATH'));
  88. if path<>'' then
  89. ppcbin:=path;
  90. end;
  91. { call ppcXXX }
  92. swapvectors;
  93. exec(ppcbin,ppccommandline);
  94. swapvectors;
  95. if doserror<>0 then
  96. error(ppcbin+' can''t be executed');
  97. halt(dosexitcode);
  98. end.
  99. {
  100. }