Subversion Repositories DevTools

Rev

Rev 5709 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
289 dpurdie 1
########################################################################
5709 dpurdie 2
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
289 dpurdie 3
#
4
# Module name   : MakeObject.pm
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : A class to describe an buildable object
10
#                 Used to contain information about
11
#                 Static libs, Merged Libs, Shared Libs
12
#
13
# Usage:
14
#               Create a new Factory for a given Type
15
#               Create new instances of that type
16
#       Per Type
17
#               NewType             - Create a New Type factory
18
#               New                 - Create new instance
19
#               NewAdd              - Create New Instance and add to lists
20
#               Get                 - Get an existing instance
21
#               AllTargets          - Return array of all items getPath's
22
#       Per Object
23
#               getBaseDir          - Base Dir of Built Object
24
#               getFullName         - Full Name of Built Object
25
#               getPath             - BaseDir and Full Name
26
#
27
#               addItem             - Push an item onto named list (ie: OBJS)
28
#               getItems            - get Ref to named list
29
#
30
#......................................................................#
31
 
32
use strict;
33
use warnings;
34
 
35
package MakeObject;
36
 
37
use JatsError;
38
 
39
#-------------------------------------------------------------------------------
40
# Function        : NewType
41
#
42
# Description     : Creates a new Type of Object
43
#                   A factory for creating classes that will contain
44
#                   a set of common types
45
#
46
# Inputs          : $name       - Text name
47
#                   \@ARRAY     - Ref to an array that will be maintained
48
#                   $base       - Base directory
49
#                   $code       - Function to create names of new objects
50
#
51
# Returns         : A Reference to a class that this can be used
52
#
53
sub NewType
54
{
55
    my ($name, $pArray, $base, $code) = @_;
56
    my $self  = {};
57
 
58
    $base .= '/';
59
    $base =~ s~//~/~;
60
 
61
    $self->{NAME} = $name;
62
    $self->{ARRAY} = $pArray;
63
    $self->{BASEDIR} = $base;
64
    $self->{NFUNCT} = $code;
65
    $self->{LIST} = {};
66
 
67
    bless ($self, __PACKAGE__ );
68
    return $self;
69
}
70
 
71
#-------------------------------------------------------------------------------
72
# Function        : New
73
#
74
# Description     : Create a new object of this type
75
#                   Do not add to internal lists
76
#                   Can be used to create a temp template
77
#
78
# Inputs          : $name   - Name of the object
79
#
80
# Returns         : 
81
#
82
sub New
83
{
84
    my ($self, $name) = @_;
85
 
86
    Error ("Bad method to create a New MakeObject" .  ref($self))
87
        unless ( $self && ref($self) eq __PACKAGE__ );
88
 
89
    return  MakeObjectBody::NewBody(@_);
90
}
91
 
92
#-------------------------------------------------------------------------------
93
# Function        : NewAdd
94
#
95
# Description     : Create a new object of this type
96
#                   Add it to the list of known objects
97
#
98
# Inputs          : $name   - Name of the object
99
#
100
# Returns         : 
101
#
102
sub NewAdd
103
{
104
    my $self = shift;
105
    my $obj = New( $self, @_ );
106
 
107
    #
108
    #   Maintain data items
109
    #       Hash of objects entries for ready access
110
    #       Array list - used by user makefiles
111
    #           ie: @LIBS
112
    #
113
    my $name = $obj->{NAME};
114
    $self->{LIST}{$name} = $obj;
115
    push( @{$self->{ARRAY}}, $name );
116
 
117
    return $obj
118
}
119
 
120
#-------------------------------------------------------------------------------
121
# Function        : Get
122
#
123
# Description     : Retrieve an item
124
#                   Also used to test existance
125
#
126
# Inputs          : $self
127
#                   $name       - Name of item
128
#
129
# Returns         : Ref or undef if not known
130
#
131
sub Get
132
{
133
    my $parent = shift;
134
    my ($name) = @_;
135
 
136
    #
137
    #   Return Item
138
    #   Will not create hash entry if it doesn't exist
139
    #
140
    return $parent->{LIST}{$name};
141
}
142
 
143
#-------------------------------------------------------------------------------
144
# Function        : AllTargets
145
#
146
# Description     : Return an array of all targets
147
#
148
# Inputs          : $self
149
#
150
# Returns         : A Ref to an array
151
#                   that contains the 'makefile' path to the generated items
152
#
153
sub AllTargets
154
{
155
    my $self = shift;
156
    my @result;
157
 
158
    #
159
    #   Use the Array element as the source of the list:
160
    #       1) Retains the order in which the user specified the artifacts
161
    #       2) Allows user to manipulate the list
162
    #
163
 
164
    foreach my $lib ( @{$self->{ARRAY}} )
165
    {
293 dpurdie 166
        #
167
        #   Some toolsets add names directly into the lists
168
        #   Thus not all entries in the ARRAY have entries in
169
        #   the LIST. We need to handle this
170
        #
171
        #   If we have the object, then use it
172
        #   Else use a default name construction
173
        #
174
        #   Note: Is UGLY
175
        #         Feature used by toolsets that create Shared and Static
176
        #         library pairs. They tend to do push @::LIBS, $name
177
        #         Perhaps this should be done better
178
        #
179
        unless ( exists ($self->{LIST}{$lib}) )
180
        {
181
            push @result, $self->{BASEDIR} . $self->{NFUNCT}($lib);
182
        }
183
        else
184
        {
185
            push @result, $self->{LIST}{$lib}->getPath();
186
        }
289 dpurdie 187
    }
188
    \@result;
189
}
190
 
191
#sub DESTROY
192
#{
193
#    DebugDumpData("DESTROY", \@_ );
194
#}
195
 
196
 
197
################################################################################
198
#   Internal Package
199
#
200
package MakeObjectBody;
201
use JatsError;
202
 
203
#-------------------------------------------------------------------------------
204
# Function        : NewBody
205
#
206
# Description     : Create a new 'empty' entry
207
#
208
# Inputs          : $parent         - Ref to Base Type
209
#                   $name           - Name
210
#
211
# Returns         : Ref to a an object that can be manipulated
212
#
213
sub NewBody
214
{
215
    my $parent = shift;
216
    my ($name) = @_;
217
    my $self  = {};
218
 
219
    Error ("No Name provided creating a new " . $parent->{NAME})
220
        unless ( $name );
221
 
222
    Error ("Creating duplicate name: $name of type: " . $parent->{NAME} )
223
        if ( exists $parent->{LIST}{$name} );
224
 
225
    Error ("Bad object name : \"$name\"",
226
            "Contains invalid characters" )
227
        if ( $name =~ m~[^-.\$a-zA-Z0-9_]~ );
228
 
229
    $self->{NAME}     = $name;
230
    $self->{BASEDIR}  = $parent->{BASEDIR};
231
    $self->{FULLNAME} = $parent->{NFUNCT}($name);
232
 
233
    bless ($self, __PACKAGE__);
234
    return $self;
235
}
236
 
237
#-------------------------------------------------------------------------------
238
# Function        : getPath
239
#                   getBaseDir
240
#                   getFullName
241
#
242
# Description     : Accessor functions
243
#
244
# Inputs          : $self
245
#
246
# Returns         : 
247
#
248
 
249
sub getPath
250
{
251
    my $self = shift;
252
    return $self->{BASEDIR} . $self->{FULLNAME};
253
}
254
 
255
sub getBaseDir
256
{
257
    my $self = shift;
258
    return $self->{BASEDIR};
259
}
260
 
261
sub getFullName
262
{
263
    my $self = shift;
264
    return $self->{FULLNAME};
265
}
266
 
267
#-------------------------------------------------------------------------------
268
# Function        : getItems
269
#                   addItem
270
#
271
# Description     : Accessor functions for lists of things
272
#                   The list will spring into existance if it doesn't exist
273
#                   Will return a ref to the list or a ref to an empty list
274
#
275
# Inputs          : $self
276
#                   $name               - Name of item list
277
#                   $value              - Value to add
278
#
279
# Returns         : 
280
#
281
 
282
sub getItems
283
{
284
    my ( $self, $name ) = @_;
285
    return $self->{$name} || [];
286
}
287
 
288
sub addItem
289
{
290
    my ($self, $name, $value) = @_;
291
    push @{$self->{$name}}, $value;
292
}
293
 
294
 
295
1;
296