summaryrefslogtreecommitdiff
path: root/utils/fpcm/fpcmpkg.pp
blob: a73d6ec729a2a953ca6429ddf994f36d05d5c4ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
{
    Copyright (c) 2001 by Peter Vreman

    FPCMake - Package.Fpc writer

    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 **********************************************************************}
{$ifdef fpc}{$mode objfpc}{$endif}
{$H+}
unit fpcmpkg;
interface

    uses
      sysutils,classes,
      fpcmmain;

    type
      TPackageFpcWriter=class
      private
        FFileName : string;
        FInput  : TFPCMake;
        FOutput : TStringList;
      public
        constructor Create(AFPCMake:TFPCMake;const AFileName:string);
        destructor  Destroy;override;
        procedure WritePackageFpc;
        procedure AddSection(const s:string);
      end;


implementation

{*****************************************************************************
                               Helpers
*****************************************************************************}

    function FixVariable(s:string):string;
      var
        i : integer;
      begin
        Result:=UpperCase(s);
        i:=pos('.',Result);
        if i>0 then
         Result[i]:='_';
      end;


{*****************************************************************************
                          TPackageFpcWriter
*****************************************************************************}

    constructor TPackageFpcWriter.Create(AFPCMake:TFPCMake;const AFileName:string);
      begin
        FInput:=AFPCMake;
        FFileName:=AFileName;
        FOutput:=TStringList.Create;
      end;


    destructor TPackageFpcWriter.Destroy;
      begin
        FOutput.Free;
      end;


    procedure TPackageFpcWriter.AddSection(const s:string);
      var
        Sec : TFPCMakeSection;
      begin
        Sec:=TFPCMakeSection(FInput[s]);
        if assigned(Sec) then
         begin
           Sec.BuildIni;
           FOutput.Add('['+s+']');
           FOutput.AddStrings(Sec.List);
         end;
      end;


    procedure TPackageFpcWriter.WritePackageFpc;
      begin
        { Only write the Package.fpc if the package is
          section available }
        if not assigned(FInput['package']) then
         begin
           FInput.Verbose(FPCMakeInfo,'Not writing Package.fpc, no package section');
           exit;
         end;

        { Generate Output }
        with FOutput do
         begin
           AddSection('package');
           AddSection('require');
         end;

        { write to disk }
        FInput.Verbose(FPCMakeInfo,'Writing Package.fpc');
        FOutput.SaveToFile(FFileName);
      end;

end.