[pm-h] can a makefile invoke a perl script?

G. Wade Johnson gwadej at anomaly.org
Wed Sep 5 05:13:24 PDT 2007


On Wed, 5 Sep 2007 06:38:38 -0500
"Russell L. Harris" <rlharris at oplink.net> wrote:

> For a week now I've been trying without success to solve this problem
> using gnu make and bash.  Here is what I have been trying to do:
> 
> The context is my web site, which is automatically regenerated by a
> single makefile.  In the course of modifying the web site, I now need
> to change the make file so that it transfers a mixed group of files
> from a main directory, sorting them into several subdirectories.  The
> source files are:
> 
>     main/red-17
>     main/red-23
>     main/red-28
>     main/...
> 
>     main/green-20
>     main/green-33
>     main/...
> 
>     main/yellow-5
>     main/yellow-22
>     main/...

Understood.

> The destination files are:
> 
>     main/sub-red/red-17
>     main/sub-red/red-23
>     main/sub-red/red-28
>     main/sub-red/...
> 
>     main/sub-green/green-20
>     main/sub-green/green-33
>     main/sub-green/...
> 
>     main/sub-yellow/yellow-5
>     main/sub-yellow/yellow-22
>     main/sub-yellow/...
> 
> I have been searching for a way to apply 'make' functions such as
> $(dir ...), $(suffix ...), $(basename ...), $(filter ...), etc., to
> the index of a bash for-loop, to enable operations such as:

Remember that any make functions are only available at the time the
command is built, not when it is executed.

>     directories := red green yellow
>         
>         (for d in $(directories:/=);    
>             do    
>                 (for f in *;    
>                     do    
>                         cp $(nodir $$f) $$d;    
>                     done;)    
>             done;)
>     
> But expressions such as $(nodir $$f) appear not to return a value.

The way I would normally handle this through bash is

  (cd main; # now I don't have to remove directories
   for d in red green yellow; do
       cp $d* sub-$d/   # no need for the loop, cp can do them all.
   done)

Of course, this only works if the file names and directory names are
related as simply as you gave above. Otherwise, I would probably resort
to Perl

> It occurs to me that Perl might offer a better approach, if only a
> makefile can invoke a Perl script.  I have not yet found an answer in
> the GNU make manual.

The "command" portion of the make can be anything you could execute at
a shell prompt. So, calling a separate Perl program is no problem.

G. Wade
-- 
Don't kill him!! If you kill him, he won't learn nothin'!
                                    -- The Riddler, "Batman Forever"


More information about the Houston mailing list