Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 26 May 2004 12:41:57 +0100
From:      Matthew Seaman <m.seaman@infracaninophile.co.uk>
To:        "N. Raghavendra" <raghu@mri.ernet.in>
Cc:        FreeBSD Questions <freebsd-questions@freebsd.org>
Subject:   Re: `call' function in `make'
Message-ID:  <20040526114157.GE26430@happy-idiot-talk.infracaninophile.co.uk>
In-Reply-To: <16564.15653.674179.246862@riemann.mri.ernet.in>
References:  <16563.20591.846129.789297@riemann.mri.ernet.in> <20040525144451.GA49822@happy-idiot-talk.infracaninophile.co.uk> <16564.15653.674179.246862@riemann.mri.ernet.in>

next in thread | previous in thread | raw e-mail | index | archive | help

--uCPdOCrL+PnN2Vxy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, May 26, 2004 at 12:15:57PM +0530, N. Raghavendra wrote:
> At 2004-05-25T15:44:51+01:00, Matthew Seaman wrote:
>=20
> > > Is there an analogue in BSD `make' of the `call' function in `gmake':
> > > $(call VARIABLE,PARAM,PARAM,...)?
> >=20
> > Not as such.  You can however use the '!=3D' operator to assign a value
> > to a variable based on the output of some external command:
> >=20
> >     RATIO  !=3D sh -c 'echo $$(( $a / $b ))'
>=20
> Hi Matthew,
>=20
> 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':
>=20
>   ### Makefile
>  =20
>   ## Create directory FOO if it does not exist.
>   create_dir =3D if test ! -d foo ; then  rm -f foo ; mkdir foo ; fi
>  =20
>   dir1: src1
>   	$(create_dir:S/foo/$@/g)
>  =20
>   dir2: src2
>   	$(create_dir:foo=3D$@)
>  =20
>   ### Makefile ends here
>=20
> However, I don't understand something.  The command for `dir1' works
> perfectly well:
>=20
>     % make dir1
>     if test ! -d dir1 ; then rm -f dir1 ; mkdir dir1 ; fi
> (`dir1' created)
>=20
> OTOH, the command for `dir2' does not work --- `make' is not expanding
> the local variable `@':
>=20
>     % make dir2
>     if test ! -d $@ ; then rm -f $@ ; mkdir $@ ; fi
> (`dir2' not created)
>=20
> 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

--=20
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

--uCPdOCrL+PnN2Vxy
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (FreeBSD)

iD8DBQFAtIKFiD657aJF7eIRAoPtAJ4nMkOx9eSAaY0AAnBy8dCDqRlDzwCfXMV8
3yhHJCawJtVPNqjDem41JcM=
=x2py
-----END PGP SIGNATURE-----

--uCPdOCrL+PnN2Vxy--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040526114157.GE26430>