Subversion Repositories DevTools

Rev

Rev 261 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
# -*- mode: perl; indent-width: 4; show-tabs: yes; -*-
2
#
3
# Module name   : COMMON
4
# Module type   : Makefile system
5
#
6
# Description:
7
#    Common toolset utils
8
#
9
# Version   Who     Date        Description
10
#           APY     06/05/04    Created
11
#                   02/09/04    packaged functionality into ToolsetPrinter()
12
#
13
# $Source: /cvsroot/etm/devl/CFG/TOOLSET/COMMON,v $
14
# $Revision: 1.4 $ $Date: 2004/09/06 07:37:44 $ $State: Exp $
15
# $Author: ayoung $ $Locker:  $
16
#............................................................................#
17
 
18
use strict;
19
use warnings;
20
 
21
###############################################################################
22
#   Toolset I/O stream
23
#
24
#       New         Create a new stream
25
#
26
#       Prt         Print a raw line
27
#
28
#       PrtLn       Print a raw line and a new line
29
#
30
#       Newline     Print a single new line
31
#
32
#       Tag         Tagged line print.
33
#
34
#       Cmd         Command line print, tagged with meta quoted and terminates.
35
#
36
#       SetTag      Set the "tag", default none.
37
#
38
#       SetTerm     Set the command line "terminator", default "\\n\n".
39
#
40
#       Label       Print generalised label
41
#
42
#       ObjList     Generate a object list, using the specified recipe.
43
#
44
#       LibList     Generate a library list, using the specified recipe.
45
#
46
#       DepRules    Generate library dependency rules
47
#
48
###############################################################################
49
 
50
package ToolsetPrinter;
51
 
52
sub New
53
{
54
    my ($tag, $cmdterm) = @_;
55
 
56
    $tag = "" if ( !defined($tag) );            # default tag
57
    $cmdterm = "\\n\n"                          # and terminator
58
        if ( !defined($cmdterm) );
59
 
60
    my ($self) = {
61
            TAG         => $tag,
62
            CMDTERM     => $cmdterm
63
        };
64
    return bless $self, __PACKAGE__;
65
}
66
 
67
 
68
sub Prt
69
{
70
    my ($self) = shift;
71
    ::MakePrint "@_";
72
}
73
 
74
sub PrtLn
75
{
76
    my ($self) = shift;
77
    ::MakePrint "@_\n";
78
}
79
 
80
sub Entry
81
{
82
    my ($self) = shift;
83
    ::MakeEntry( @_ );
84
}
85
 
86
 
87
sub Newline
88
{
89
    my ($self) = shift;
90
    ::MakePrint "\n";
91
}
92
 
93
 
94
sub SetTag
95
{
96
    my ($self) = shift;
97
    my ($tag) = @_;
98
 
99
    $tag = "" if ( !defined($tag) );
100
    $self->{TAG} = $tag;
101
}
102
 
103
 
104
sub SetTerm
105
{
106
    my ($self) = shift;
107
    my ($cmdterm) = @_;
108
 
109
    $cmdterm = "\\n\n"                          # default terminator
110
        if ( !defined($cmdterm) );
111
    $self->{CMDTERM} = $cmdterm;
112
}
113
 
114
 
115
sub Cmd
116
{
117
    my ($self) = shift;
118
    ::MakeQuote "$self->{TAG}\t+=@_$self->{CMDTERM}";
119
}
120
 
121
 
122
sub Tag
123
{
124
    my ($self) = shift;
125
    ::MakePrint "$self->{TAG}\t+=@_\n";
126
}
127
 
128
 
129
sub Label
130
{
131
    my ($self) = shift;
132
    my ($desc, $target) = @_;
133
 
134
    $self->Prt( "#.. $desc ($target)\n\n" );
135
}
136
 
137
 
138
sub ObjList
139
{
140
    my ($self) = shift;
141
    my ($target, $objs, $genrecipe, @uargs) = @_;
142
 
143
    foreach (@$objs)
144
    {
145
        &$genrecipe( $self, $target, $_, @uargs );
146
    }
147
}
148
 
149
 
150
#private
151
sub CondParse
152
{
153
    my ($target, $cond) = @_;
154
 
155
    if ($cond =~ /^--ifdef=(.*)/) {             # .. ifdef XXX
156
        $cond = "ifdef $1";
157
 
158
    } elsif ($cond =~ /^--ifndef=(.*)/) {       # .. ifndef XXX
159
        $cond = "ifndef $1";
160
 
161
    } elsif ($cond =~ /^--ifdebug$/) {          # .. if DEBUG
162
        $cond = "ifeq \"\$(DEBUG)\" \"1\"";
163
 
164
    } elsif ($cond =~ /^--ifprod$/) {           # .. if PRODUCTION
165
        $cond = "ifeq \"\$(DEBUG)\" \"0\"";
166
 
167
    } elsif ($cond =~ /^--ifeq=(.*):(.*)$/) {   # .. ifeq XXXX:YYYY
168
        $cond = "ifeq \"\$($1)\" \"$2\"";
169
 
170
    } elsif ($cond =~ /^--ifneq=(.*):(.*)$/) {  # .. ifneq XXXX:YYYY
171
        $cond = "ifneq \"\$($1)\" \"$2\"";
172
 
173
    } else {                                    # .. unknown
174
        ::Error( "$target: unknown conditional construct '$cond'" );
175
        $cond = "";
176
    }
177
    return $cond;
178
}
179
 
180
 
181
#private
182
sub CondOpen
183
{
184
    my ($self) = shift;
185
 
186
    @{$self->{CONDSTACK}} = ();
187
}
188
 
189
 
190
#private
191
sub CondModify
192
{
193
    my ($self) = shift;
194
    my ($newstack) = @_;
195
    my ($oldstack) = \@{$self->{CONDSTACK}};
196
    my ($idx, $cond);
197
 
198
#   Diff the two stacks
199
#
200
    $idx = 0;
201
    while ( $idx <= $#$newstack &&
202
            $idx <= $#$oldstack &&
203
            $$newstack[$idx] eq $$oldstack[$idx] ) {
204
        $idx++;
205
    }
206
 
207
#   Pop diff
208
#
209
    while ($idx <= $#$oldstack) {
210
        $cond = pop @$oldstack;
211
        $self->Prt( "  " x ($#$oldstack+1) . "endif\n" );
212
    }
213
 
214
#   Push diff
215
#
216
    while ($idx <= $#$newstack) {
217
        $self->Prt( "  " x $idx . "$$newstack[$idx]\n" );
218
        $idx++;
219
    }
220
 
221
    @{$self->{CONDSTACK}} = @$newstack;
222
}
223
 
224
 
225
#private
226
sub CondClose
227
{
228
    my ($self) = shift;
229
    my (@newstack) = ();
230
 
231
    $self->CondModify( \@newstack );            # pop any stacked conditionals
232
}
233
 
234
 
235
sub LibList
236
{
237
    my ($self) = shift;
238
    my ($target, $libs, $genrecipe, @uargs) = @_;
239
    my (@cond, $t_cond) = ();
240
 
241
    $self->CondOpen();                          # open a conditional session
242
 
243
    foreach (@$libs)
244
    {
245
        if (/^--if/)                            # inlined conditionals
246
        {
247
            push @cond, $t_cond
248
                if (($t_cond = CondParse( $target, $_ )) ne "");
249
        }
250
        elsif (/^--/)                           # arguments
251
        {
252
            &$genrecipe( $self, $target, $_, @uargs );
253
        }
254
        else                                    # library
255
        {
256
            my (@args) = split( "\n\t\t", $_ ); # see makeif.pl
257
            my ($lib) = shift @args;
258
 
259
            #   Associated conditionals (if any)
260
            #
261
            foreach (@args) {
262
                push @cond, $t_cond
263
                    if (($t_cond = CondParse( $target, $_ )) ne "");
264
            }
265
            $self->CondModify( \@cond );        # modify
266
            @cond = ();
267
 
268
            #   Generate recipe
269
            #
270
            &$genrecipe( $self, $target, $lib, @uargs );
271
        }
272
    }
273
    $self->CondClose();                         # close session
274
}
275
 
276
 
277
 
278
sub SHLDDEPEND
279
{
280
    my ($self) = shift;
281
    my ($target, $base, $name, $dir) = @_;
282
 
283
    $dir = "LIBDIR" unless ( defined $dir );
284
 
285
    $self->Prt( "
286
\$($dir)/${target}.dep:\tSHBASE=${base}
287
\$($dir)/${target}.dep:\tSHNAME=${name}
288
\$($dir)/${target}.dep:\t\$(GBE_$dir)
289
\$($dir)/${target}.dep:\t\$(GBE_PLATFORM).mk
290
	\$(SHLDDEPEND)
291
 
292
ifneq \"\$(findstring \$(IFLAG),23)\" \"\"
293
-include\t\$($dir)/${target}.dep
294
endif
295
 
296
" );
297
}
298
 
299
 
300
sub LDDEPEND
301
{
302
    my ($self) = shift;
303
    my ($target, $dir) = @_;
304
 
305
    $dir = "BINDIR" unless ( defined $dir );
306
 
307
    $self->Prt( "
308
\$($dir)/${target}.dep:\t\$(GBE_$dir)
309
\$($dir)/${target}.dep:\t\$(GBE_PLATFORM).mk
310
	\$(LDDEPEND)
311
 
312
ifeq \"\$(IFLAG)\" \"3\"
313
-include\t\$($dir)/${target}.dep
314
endif
315
 
316
" );
317
}
318
 
319
 
320
sub DepRules
321
{
322
    my ($self) = shift;
323
    my ($target, $libs, $librecipe, @uargs) = @_;
324
 
325
    unless ( $self->{DepRulesHeaderDone}{$target} )
326
    {
327
        $self->{DepRulesHeaderDone}{$target} = 1;
328
                                                # label
329
        $self->Prt( "#.. Dependencies ($target)\n\n" );
330
 
331
                                                # library depends
332
        $self->Tag( "\\# DO NOT REMOVE - dependencies\\\\n\\\\n" );
333
    }
334
    $self->LibList( $target, $libs, $librecipe, @uargs );
335
}
336
 
337
1;
338