cons-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: patterns


From: frederik
Subject: Re: patterns
Date: 25 Oct 2002 09:47:19 -0700
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

> 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 ...
>
> 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 intend 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.

Thanks for the example... So from what you're saying, the only
disadvantage _here_ with cons' approach versus make's approach is that
I have to specify each source file and how it is built, right?

If there are multiple steps to the process, do I have to describe each
one individually for each file? For instance, suppose I have a general
macro preprocessor which I want to invoke on all my source files
before building them. The unprocessed files end with ".in". In make, I
would write

% :: %.in
        my_macro_processor <$< >$@

With this Makefile and a file "foo.c.in", I could run "make foo" to
build an executable; with a dvips rule as mentioned above, and latex
rule, and a file "doc.tex.in", I could also run "make doc.ps" to
generate a postscript file. Make would combine my macro rules with
each other and with its own implicit rules, and apply them
automatically to generate the desired target file. How would you write
the corresponding cons script?

Frederik





reply via email to

[Prev in Thread] Current Thread [Next in Thread]