Subversion Repositories DevTools

Rev

Rev 271 | Rev 4778 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 271 Rev 4344
Line 19... Line 19...
19
#
19
#
20
#                 The order that information is added is not important
20
#                 The order that information is added is not important
21
#                 Recipes and prerequisites may be mixed to simplify
21
#                 Recipes and prerequisites may be mixed to simplify
22
#                 programming.
22
#                 programming.
23
#
23
#
-
 
24
#                 The --Define option creates
-
 
25
#                 define <name>
-
 
26
#                   Recipe
-
 
27
#                 endef
-
 
28
#
-
 
29
#                The --Raw option creates
-
 
30
#                   Recipe
-
 
31
#
-
 
32
#
24
#......................................................................#
33
#......................................................................#
25
 
34
 
26
use 5.006_001;
35
use 5.006_001;
27
use strict;
36
use strict;
28
use warnings;
37
use warnings;
Line 51... Line 60...
51
#                           --Target=name,name,name
60
#                           --Target=name,name,name
52
#                           --Comment=text
61
#                           --Comment=text
53
#                           --Prereq=name,name,name
62
#                           --Prereq=name,name,name
54
#                           --Recipe=text
63
#                           --Recipe=text
55
#                           --Phony
64
#                           --Phony
-
 
65
#                           --Define
-
 
66
#                           --Raw
56
#                           --Print
67
#                           --Print
57
#
68
#
58
# Returns         : Ref to a an object that can be manipulated
69
# Returns         : Ref to a an object that can be manipulated
59
#
70
#
60
sub New
71
sub New
Line 67... Line 78...
67
    $self->{SHELL}          = [];
78
    $self->{SHELL}          = [];
68
    $self->{PRINTED}        = 0;
79
    $self->{PRINTED}        = 0;
69
    $self->{COMMENT}        = [];
80
    $self->{COMMENT}        = [];
70
    $self->{DEFN}           = {};
81
    $self->{DEFN}           = {};
71
    $self->{PHONY}          = 0;
82
    $self->{PHONY}          = 0;
-
 
83
    $self->{DEFINE}         = 0;
-
 
84
    $self->{RAW}            = 0;
72
    $self->{FH}             = $handle;
85
    $self->{FH}             = $handle;
73
    $self->{FH_inmemory}    = 0;
86
    $self->{FH_inmemory}    = 0;
74
    $self->{RECIPE_PREFIX}  = '';
87
    $self->{RECIPE_PREFIX}  = '';
75
    $self->{RECIPE_COMMENT} = '';
88
    $self->{RECIPE_COMMENT} = '';
76
 
89
 
Line 94... Line 107...
94
            $self->AddDependancy(split(/,/,$1));
107
            $self->AddDependancy(split(/,/,$1));
95
 
108
 
96
        } elsif ( m/^--Phony/ ) {
109
        } elsif ( m/^--Phony/ ) {
97
            $self->Phony();
110
            $self->Phony();
98
 
111
 
-
 
112
        } elsif ( m/^--Define/ ) {
-
 
113
            $self->Define();
-
 
114
 
-
 
115
        } elsif ( m/^--Raw/ ) {
-
 
116
            $self->Raw();
-
 
117
 
99
        } elsif ( m/^--Recipe=(.*)/ ) {
118
        } elsif ( m/^--Recipe=(.*)/ ) {
100
            $self->AddRecipe($1);
119
            $self->AddRecipe($1);
101
 
120
 
102
        } elsif ( m/^--Print/ ) {
121
        } elsif ( m/^--Print/ ) {
103
            $print = 1;
122
            $print = 1;
Line 164... Line 183...
164
{
183
{
165
    my $self = shift;
184
    my $self = shift;
166
    $self->{PHONY} = 1;
185
    $self->{PHONY} = 1;
167
}
186
}
168
 
187
 
-
 
188
#-------------------------------------------------------------------------------
-
 
189
# Function        : Define
-
 
190
#
-
 
191
# Description     : Flag the entry as a define, rather than a normal target
-
 
192
#                   Many of the other commands are not supported
-
 
193
#                   Only AddComment and AddRecipe
-
 
194
#
-
 
195
# Inputs          :
-
 
196
#
-
 
197
# Returns         :
-
 
198
#
-
 
199
sub Define
-
 
200
{
-
 
201
    my $self = shift;
-
 
202
    $self->{DEFINE} = 1;
-
 
203
}
-
 
204
 
-
 
205
#-------------------------------------------------------------------------------
-
 
206
# Function        : Raw
-
 
207
#
-
 
208
# Description     : Flag the entry as raw text
-
 
209
#                   Many of the other commands are not supported
-
 
210
#                   Only AddComment and AddRecipe
-
 
211
#
-
 
212
# Inputs          :
-
 
213
#
-
 
214
# Returns         :
-
 
215
#
-
 
216
sub Raw
-
 
217
{
-
 
218
    my $self = shift;
-
 
219
    $self->{RAW} = 1;
-
 
220
}
169
 
221
 
170
#-------------------------------------------------------------------------------
222
#-------------------------------------------------------------------------------
171
# Function        : AddComment
223
# Function        : AddComment
172
#
224
#
173
# Description     : Add a comment to the entry
225
# Description     : Add a comment to the entry
Line 261... Line 313...
261
# Inputs          : One or more recipe lines
313
# Inputs          : One or more recipe lines
262
#                   Each line of the recipe will be prefixed with the current
314
#                   Each line of the recipe will be prefixed with the current
263
#                   recipe prefix.
315
#                   recipe prefix.
264
#
316
#
265
#                   An array will be treated as a recipe with implicit line
317
#                   An array will be treated as a recipe with implicit line
266
#                   breakes for formatting purposes.
318
#                   breaks for formatting purposes.
267
#
319
#
268
# Returns         :
320
# Returns         :
269
#
321
#
270
sub AddRecipe
322
sub AddRecipe
271
{
323
{
Line 363... Line 415...
363
            my $value = $self->{DEFN} {$_};
415
            my $value = $self->{DEFN} {$_};
364
            print( "$tstring: $_ = $value\n" );
416
            print( "$tstring: $_ = $value\n" );
365
        }
417
        }
366
    }
418
    }
367
 
419
 
368
    #
-
 
369
    #   Print the main target name
-
 
370
    #   Print on multiple lines if multiple targets are very long
-
 
371
    #
-
 
372
    my $tstring = join $;, @{$self->{NAME}};
-
 
373
    my $join = length ($tstring) < $llength ? ' ' : " \\\n";
-
 
374
    $tstring =~ s~$;~$join~g;
-
 
375
    my $nlength = length $tstring;
-
 
376
    print "$tstring:";
-
 
377
    
-
 
378
    #
-
 
379
    #   Print the prerequisites
-
 
380
    #   Print on multiple lines if long
-
 
381
    #
-
 
382
    $tstring = join $;, @{$self->{DEPENDANCY}};
-
 
383
    $join = $nlength + length ($tstring) < $llength ? ' ' : " \\\n\t";
-
 
384
    $tstring =~ s~$;~$join~g;
-
 
385
    print $join . $tstring;
-
 
386
 
-
 
387
 
-
 
388
    #
-
 
389
    #   Print the Recipe runtime comment
-
 
390
    #
-
 
391
    if ( $self->{RECIPE_COMMENT} )
420
    if ( $self->{RAW}  )
392
    {
421
    {
393
        print "\n\t\@echo \"$self->{RECIPE_COMMENT}\"";
422
        my $tstring = join ("\n", @{$self->{RECIPE}});
-
 
423
        print $tstring;
394
    }
424
    }
-
 
425
    elsif ( $self->{DEFINE}  )
-
 
426
    {
395
 
427
 
-
 
428
        my $tstring = $self->{NAME}[0];
-
 
429
        print "define $tstring";
-
 
430
        print_list ( '', '', $self->{RECIPE}, '');
-
 
431
        print "\nendef";
396
    #
432
    }
-
 
433
    else
-
 
434
    {
-
 
435
        #
-
 
436
        #   Print the main target name
-
 
437
        #   Print on multiple lines if multiple targets are very long
-
 
438
        #
-
 
439
        my $tstring = join $;, @{$self->{NAME}};
-
 
440
        my $join = length ($tstring) < $llength ? ' ' : " \\\n";
-
 
441
        $tstring =~ s~$;~$join~g;
-
 
442
        my $nlength = length $tstring;
-
 
443
        print "$tstring:";
-
 
444
        
-
 
445
        #
397
    #   Print the recipe
446
        #   Print the prerequisites
-
 
447
        #   Print on multiple lines if long
398
    #
448
        #
399
    print_list ( '', '', $self->{RECIPE}, '');
449
        $tstring = join $;, @{$self->{DEPENDANCY}};
-
 
450
        $join = $nlength + length ($tstring) < $llength ? ' ' : " \\\n\t";
-
 
451
        $tstring =~ s~$;~$join~g;
-
 
452
        print $join . $tstring;
400
 
453
 
-
 
454
        #
-
 
455
        #   Print the Recipe runtime comment
401
    #
456
        #
-
 
457
        if ( $self->{RECIPE_COMMENT} )
-
 
458
        {
-
 
459
            print "\n\t\@echo \"$self->{RECIPE_COMMENT}\"";
-
 
460
        }
-
 
461
 
-
 
462
        #
-
 
463
        #   Print the recipe
-
 
464
        #
-
 
465
        print_list ( '', '', $self->{RECIPE}, '');
-
 
466
 
-
 
467
        #
402
    #   Print the recipe as a shell command
468
        #   Print the recipe as a shell command
403
    #   Bracket the recipes with ( .. ) and place semi colons between lines
469
        #   Bracket the recipes with ( .. ) and place semi colons between lines
404
    #   Use the current recipe prefix
470
        #   Use the current recipe prefix
405
    #
471
        #
406
    print_list ( $self->{RECIPE_PREFIX} . '(', ';\\', $self->{SHELL}, ')');
472
        print_list ( $self->{RECIPE_PREFIX} . '(', ';\\', $self->{SHELL}, ')');
-
 
473
    }
407
 
474
 
408
    print "\n\n";
475
    print "\n\n";
409
 
476
 
410
    #
477
    #
411
    #   Flag the entry as having been printed
478
    #   Flag the entry as having been printed