fpcmpkg.pp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. {
  2. $Id$
  3. Copyright (c) 2001 by Peter Vreman
  4. FPCMake - Package.Fpc writer
  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. unit fpcmpkg;
  14. interface
  15. uses
  16. sysutils,classes,
  17. fpcmmain;
  18. type
  19. TPackageFpcWriter=class
  20. private
  21. FFileName : string;
  22. FInput : TFPCMake;
  23. FOutput : TStringList;
  24. public
  25. constructor Create(AFPCMake:TFPCMake;const AFileName:string);
  26. destructor Destroy;override;
  27. procedure WritePackageFpc;
  28. procedure AddSection(const s:string);
  29. end;
  30. implementation
  31. {*****************************************************************************
  32. Helpers
  33. *****************************************************************************}
  34. function FixVariable(s:string):string;
  35. var
  36. i : integer;
  37. begin
  38. Result:=UpperCase(s);
  39. i:=pos('.',Result);
  40. if i>0 then
  41. Result[i]:='_';
  42. end;
  43. {*****************************************************************************
  44. TPackageFpcWriter
  45. *****************************************************************************}
  46. constructor TPackageFpcWriter.Create(AFPCMake:TFPCMake;const AFileName:string);
  47. begin
  48. FInput:=AFPCMake;
  49. FFileName:=AFileName;
  50. FOutput:=TStringList.Create;
  51. end;
  52. destructor TPackageFpcWriter.Destroy;
  53. begin
  54. FOutput.Free;
  55. end;
  56. procedure TPackageFpcWriter.AddSection(const s:string);
  57. var
  58. Sec : TFPCMakeSection;
  59. begin
  60. Sec:=TFPCMakeSection(FInput[s]);
  61. if assigned(Sec) then
  62. begin
  63. Sec.BuildIni;
  64. FOutput.Add('['+s+']');
  65. FOutput.AddStrings(Sec.List);
  66. end;
  67. end;
  68. procedure TPackageFpcWriter.WritePackageFpc;
  69. begin
  70. { Only write the Package.fpc if the package is
  71. section available }
  72. if not assigned(FInput['package']) then
  73. begin
  74. FInput.Verbose(FPCMakeInfo,'Not writing Package.fpc, no package section');
  75. exit;
  76. end;
  77. { Generate Output }
  78. with FOutput do
  79. begin
  80. AddSection('package');
  81. AddSection('require');
  82. end;
  83. { write to disk }
  84. FInput.Verbose(FPCMakeInfo,'Writing Package.fpc');
  85. FOutput.SaveToFile(FFileName);
  86. end;
  87. end.
  88. {
  89. $Log$
  90. Revision 1.3 2002-09-07 15:40:32 peter
  91. * old logs removed and tabs fixed
  92. }