fpcmpkg.pp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. {
  2. Copyright (c) 2001 by Peter Vreman
  3. FPCMake - Package.Fpc writer
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. **********************************************************************}
  10. {$ifdef fpc}{$mode objfpc}{$endif}
  11. {$H+}
  12. unit fpcmpkg;
  13. interface
  14. uses
  15. sysutils,classes,
  16. fpcmmain;
  17. type
  18. TPackageFpcWriter=class
  19. private
  20. FFileName : string;
  21. FInput : TFPCMake;
  22. FOutput : TStringList;
  23. public
  24. constructor Create(AFPCMake:TFPCMake;const AFileName:string);
  25. destructor Destroy;override;
  26. procedure WritePackageFpc;
  27. procedure AddSection(const s:string);
  28. end;
  29. implementation
  30. {*****************************************************************************
  31. Helpers
  32. *****************************************************************************}
  33. function FixVariable(s:string):string;
  34. var
  35. i : integer;
  36. begin
  37. Result:=UpperCase(s);
  38. i:=pos('.',Result);
  39. if i>0 then
  40. Result[i]:='_';
  41. end;
  42. {*****************************************************************************
  43. TPackageFpcWriter
  44. *****************************************************************************}
  45. constructor TPackageFpcWriter.Create(AFPCMake:TFPCMake;const AFileName:string);
  46. begin
  47. FInput:=AFPCMake;
  48. FFileName:=AFileName;
  49. FOutput:=TStringList.Create;
  50. end;
  51. destructor TPackageFpcWriter.Destroy;
  52. begin
  53. FOutput.Free;
  54. end;
  55. procedure TPackageFpcWriter.AddSection(const s:string);
  56. var
  57. Sec : TFPCMakeSection;
  58. begin
  59. Sec:=TFPCMakeSection(FInput[s]);
  60. if assigned(Sec) then
  61. begin
  62. Sec.BuildIni;
  63. FOutput.Add('['+s+']');
  64. FOutput.AddStrings(Sec.List);
  65. end;
  66. end;
  67. procedure TPackageFpcWriter.WritePackageFpc;
  68. begin
  69. { Only write the Package.fpc if the package is
  70. section available }
  71. if not assigned(FInput['package']) then
  72. begin
  73. FInput.Verbose(FPCMakeInfo,'Not writing Package.fpc, no package section');
  74. exit;
  75. end;
  76. { Generate Output }
  77. with FOutput do
  78. begin
  79. AddSection('package');
  80. AddSection('require');
  81. end;
  82. { write to disk }
  83. FInput.Verbose(FPCMakeInfo,'Writing '+FFileName);
  84. FOutput.SaveToFile(FFileName);
  85. end;
  86. end.