Subversion Repositories DevTools

Rev

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

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