tech-toolchain archive

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

Re: make: modifier to run realpath() on variable?

On Wed, Apr 21, 2010 at 06:37:47PM -0700, Simon J. Gerraty wrote:
 > Sorry, I missed this.

Responding less than a week later hardly counts as "missing" it :-/

 >> I generally recommend writing makefiles to never use absolute paths,
 >> but that's not always possible.
 > I agree, and I've done evil[TM] things in the past to force .CURDIR to
 > be a relative path ;-) However absolute paths can be very handy when
 > trying to trim or otherwise canonicalize.


 > Eg if you have
 > and you have a at the top of your src tree it can do
 > neat things like:
 > of course there are other ways of skinning that cat...

This is what I did the last nontrivial build system I set up:


.if "$(MYDIR)" == ""
# avoid stray slash

where this logic appears in a file included using the standard form
.include "$(TOP)/mk/"

and BUILDTOP defaults to $(TOP)/build.

But an explicit absolutize is clearly preferable, and wouldn't fall
over on directories with * in their names.

 > >Did I ever propose ${.PARSEDIR:<<} and ${.PARSEDIR:>>} for helping to
 > >navigate with relative paths?
 > I haven't seen a proposal - what would be the idea?

The << and >> modifiers would have no effect on absolute paths but
would move relative paths up and down one level respectively; thus
if DIR is ../../foo

   $(DIR:<<)    =>      ../foo
   $(DIR:>>)    =>      ../../../foo

If << runs out of ..'s to cancel it should use the last component of

This way you can do stuff like

        cd subdir && $(MYTOOL:>>) somefile

which is otherwise a pain if MYTOOL sometimes points at e.g. /usr/local.

David A. Holland

Home | Main Index | Thread Index | Old Index