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.
Yes.
> Eg if you have
>
> _PARSEDIR = ${.PARSEDIR:tA}
>
> and you have a makefile.inc at the top of your src tree it can do
> neat things like:
>
> SRCTOP := ${_PARSEDIR}
> RELDIR = ${.CURDIR:S,${SRCTOP}/,,}
>
> of course there are other ways of skinning that cat...
This is what I did the last nontrivial build system I set up:
ABSTOP_PATTERN=$(TOP:S/./\\./g:S/\\.\\./[^\/]*/g)
ABSTOP=$(.CURDIR:C/$(ABSTOP_PATTERN)\$//)
MYDIR=$(.CURDIR:S/^$(ABSTOP)//)
.if "$(MYDIR)" == ""
# avoid stray slash
MYBUILDDIR=$(BUILDTOP)
.else
MYBUILDDIR=$(BUILDTOP)/$(MYDIR)
.endif
where this logic appears in a file included using the standard form
TOP=../..[../../.....]
.include "$(TOP)/mk/setup.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
$(.CURDIR).
This way you can do stuff like
MYTOOL=../mytool/mytool
:
all:
cd subdir && $(MYTOOL:>>) somefile
which is otherwise a pain if MYTOOL sometimes points at e.g. /usr/local.
--
David A. Holland
dholland%netbsd.org@localhost
Home |
Main Index |
Thread Index |
Old Index