On Wed, May 26, 2004 at 12:15:57PM +0530, N. Raghavendra wrote:
> At 2004-05-25T15:44:51+01:00, Matthew Seaman wrote:
> 
> > > Is there an analogue in BSD `make' of the `call' function in `gmake':
> > > $(call VARIABLE,PARAM,PARAM,...)?
> > 
> > Not as such.  You can however use the '!=' operator to assign a value
> > to a variable based on the output of some external command:
> > 
> >     RATIO  != sh -c 'echo $$(( $a / $b ))'
> 
> Hi Matthew,
> 
> Thanks for your reply.  After writing to the list yesterday, I read
> make(1) carefully, and found what I wanted, namely the shell command
> for creating `dir1' in this example `Makefile':
> 
>   ### Makefile
>   
>   ## Create directory FOO if it does not exist.
>   create_dir = if test ! -d foo ; then  rm -f foo ; mkdir foo ; fi
>   
>   dir1: src1
>       $(create_dir:S/foo/$@/g)
>   
>   dir2: src2
>       $(create_dir:foo=$@)
>   
>   ### Makefile ends here
> 
> However, I don't understand something.  The command for `dir1' works
> perfectly well:
> 
>     % make dir1
>     if test ! -d dir1 ; then rm -f dir1 ; mkdir dir1 ; fi
> (`dir1' created)
> 
> OTOH, the command for `dir2' does not work --- `make' is not expanding
> the local variable `@':
> 
>     % make dir2
>     if test ! -d $@ ; then rm -f $@ ; mkdir $@ ; fi
> (`dir2' not created)
> 
> Can someone tell me why this is happening?

Err... because in the second form the result of the substitution is
not run through another round of variable expansion, and in the first
for it is?  You'ld have to ask the original authors of make(1) why
they did it that way.  Is there something wrong with the first form of
the rule that means you can't use it?

You have got a line:

    .PHONY: dir1 dir2

to force those rules to be applied even if dir1 or dir2 are newer than
their sources?

        Cheers,

        Matthew

-- 
Dr Matthew J Seaman MA, D.Phil.                       26 The Paddocks
                                                      Savill Way
PGP: http://www.infracaninophile.co.uk/pgpkey         Marlow
Tel: +44 1628 476614                                  Bucks., SL7 1TH UK

Attachment: pgpm30kbde89O.pgp
Description: PGP signature

Reply via email to