[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: patterns
From: |
Johan Holmberg |
Subject: |
Re: patterns |
Date: |
Sat, 19 Oct 2002 15:03:22 +0200 (MEST) |
On Tue, 15 Oct 2002 address@hidden wrote:
>
> After reading the cons manual, I still can't figure out how to write a
> simple pattern rule in Cons. For instance, if I want to create a "ps"
> file from a "dvi" file using dvips, in GNU Make I can write the
> following rule:
>
> %.ps: %.dvi
> dvips $< -o $@
>
Cons has no "implicit rules" ala make (pattern matching rules/suffix rules).
I think this is very *good*. Even if the implicit choosing of rules
in make is tempting in the simple case, I've seen too many cases
where *the wrong* rule is choosen by "accident" and the poor
ordinary make user has no clue what is happening.
A Construct instead explicitly tells Cons what there is to build.
But since you have a real programming language at your disposal
the difference isn't so big. Just create a "dvips" method ...
> Is there a way to do this easily in cons?
>
You could do something like:
#--------------------------------------------------
sub cons::dvi2ps
{
my ($e, $dvi) = @_;
# replace suffix: .dvi ---> .ps
my $ps = $dvi;
$ps =~ s/\.dvi$//;
$ps .= ".ps";
$e->Command( $ps, $dvi, "dvips %< -o %>");
}
$e = cons->new();
# use the new method ...
$e->dvi2ps( "foo.dvi" );
#--------------------------------------------------
And if you intent do use this more than once, you can move the
"cons::dvi2ps" method into a Perl-module and just add a "use" line
like below to your Construct file:
use YourConsStuff;
$e = cons->new();
$e->dvi2ps( "foo.dvi" );
Or maybe even make a sub-class of "cons" and add the method there.
In either case you get a rather short Construct file.
/Johan Holmberg
- patterns, frederik, 2002/10/15
- Re: patterns,
Johan Holmberg <=