| Panotools-Script documentation | Contained in the Panotools-Script distribution. |
Panotools::Makefile::Variable - Assemble Makefile Variable definitions
Simple interface for generating Makefile syntax
Writing Makefiles directly from perl scripts with print and "\t" etc... is prone to error, this library provides a simple perl interface for assembling Makefiles.
$var = new Panotools::Makefile::Variable;
..or define the 'variable name' at the same time:
$var = new Panotools::Makefile::Variable ('USERS');
..or define the name and values at the same time:
$var = new Panotools::Makefile::Variable ('USERS', 'Andy Pandy');
Set or query the name:
$var->Name ('USERS');
$text = $var->Name;
$var->Values ('James Brine', 'George Loveless');
$var->Values ('Thomas Standfield');
Construct a text fragment that defines this variable suitable for use in a Makefile like so:
$text = $var->Assemble;
| Panotools-Script documentation | Contained in the Panotools-Script distribution. |
package Panotools::Makefile::Variable;
use strict; use warnings; use Panotools::Makefile::Utils qw/quotetarget quoteprerequisite quoteshell/;
sub new { my $class = shift; $class = ref $class || $class; my $self = bless {name => shift, value => [@_]}, $class; return $self; }
sub Name { my $self = shift; $self->{name} = shift if @_; return $self->{name}; } sub NameRef { my $self = shift; return '$('. $self->Name .')'; } sub NameRefShell { my $self = shift; return '$('. $self->Name .'_SHELL)'; }
sub Values { my $self = shift; push @{$self->{value}}, @_; return $self->{value}; }
sub Assemble { my $self = shift; return '' unless defined $self->{name}; my $text; $text .= quotetarget ($self->{name}); $text .= ' = '; $text .= join ' ', (map { quotetarget ($_)} grep /./, @{$self->{value}}); $text .= "\n"; $text .= quotetarget ($self->{name} .'_SHELL'); $text .= ' = '; my @items = map { quoteshell ($_)} grep /./, @{$self->{value}}; @items = map {s/\$\(([^)]+)\)/\$($1_SHELL)/g; $_} @items; $text .= join ' ', @items; $text .= "\n"; return $text; } 1;