fpcmake.pp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. {
  2. $Id$
  3. Copyright (c) 2001 by Peter Vreman
  4. Convert Makefile.fpc to Makefile
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$ifdef fpc}{$mode objfpc}{$endif}
  12. {$H+}
  13. program fpcmake;
  14. uses
  15. sysutils,
  16. fpcmmain,fpcmwr;
  17. procedure Verbose(s:string);
  18. begin
  19. writeln(s);
  20. end;
  21. procedure Error(s:string);
  22. begin
  23. Writeln('Error: ',s);
  24. Halt(1);
  25. end;
  26. procedure ProcessFile(const fn:string);
  27. var
  28. CurrFPCMake : TFPCMake;
  29. CurrMakefile : TMakefileWriter;
  30. {$ifdef SUBDIRS}
  31. s,Subdirs : string;
  32. t : ttarget;
  33. {$endif SUBDIRS}
  34. begin
  35. CurrFPCMake:=nil;
  36. // try
  37. writeln('Processing ',fn);
  38. { Load Makefile.fpc }
  39. CurrFPCMake:=TFPCMake.Create(fn);
  40. CurrFPCMake.LoadMakefileFPC;
  41. // CurrFPCMake.Print;
  42. {$ifdef SUBDIRS}
  43. subdirs:=CurrFPCMake.GetVariable('target_dirs',true);
  44. for t:=low(ttarget) to high(ttarget) do
  45. subdirs:=subdirs+' '+CurrFPCMake.GetVariable('target_dirs'+targetsuffix[t],true);
  46. {$endif SUBDIRS}
  47. { Write Makefile }
  48. CurrMakefile:=TMakefileWriter.Create(CurrFPCMake,ExtractFilePath(fn)+'Makefile');
  49. CurrMakefile.WriteGenericMakefile;
  50. { Free }
  51. CurrMakefile.Free;
  52. // except
  53. // on e : exception do
  54. // begin
  55. // Error(e.message);
  56. // Subdirs:='';
  57. // end;
  58. // end;
  59. CurrFPCMake.Free;
  60. {$ifdef SUBDIRS}
  61. { Process subdirs }
  62. writeln('Subdirs found: ',subdirs);
  63. repeat
  64. s:=GetToken(subdirs);
  65. if s='' then
  66. break;
  67. ProcessFile(ExtractFilePath(fn)+s+'/Makefile.fpc');
  68. until false;
  69. {$endif SUBDIRS}
  70. end;
  71. procedure UseMakefilefpc;
  72. var
  73. fn : string;
  74. begin
  75. if FileExists('Makefile.fpc') then
  76. fn:='Makefile.fpc'
  77. else
  78. fn:='makefile.fpc';
  79. ProcessFile(fn);
  80. end;
  81. procedure UseParameters;
  82. var
  83. i : integer;
  84. begin
  85. for i:=1 to ParamCount do
  86. ProcessFile(ParamStr(i));
  87. end;
  88. begin
  89. if ParamCount=0 then
  90. UseMakefilefpc
  91. else
  92. UseParameters;
  93. end.
  94. {
  95. $Log$
  96. Revision 1.3 2001-02-22 21:11:24 peter
  97. * fpcdir detection added
  98. * fixed loading of variables in fpcmake itself
  99. Revision 1.2 2001/01/29 21:49:10 peter
  100. * lot of updates
  101. Revision 1.1 2001/01/24 21:59:36 peter
  102. * first commit of new fpcmake
  103. }