help-make
[Top][All Lists]
Advanced

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

Re: Crossing directories for target and source


From: David Boyce
Subject: Re: Crossing directories for target and source
Date: Thu, 7 Oct 2010 17:10:14 -0400

On Thu, Oct 7, 2010 at 4:44 PM, David Boyce <address@hidden> wrote:
> I like to use full paths everywhere, using a
> BASE_DIR variable which can be inherited from an env var or derived
> from $(MAKEFILES), but that's just me.

Sorry, I meant MAKEFILE_LIST. Something like:

ifndef BASE_DIR
export BASE_DIR := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
endif

.PHONY: all
all:
        @echo BASE_DIR=$(BASE_DIR)

Though fully-qualified paths are most useful in a non-recursive model,
the above should work fine in a recursive setup too. Also, I use
conditionals instead of ?= so BASE_DIR will be a simply-expanded
variable. This is more efficient because $(realpath) usually requires
a system call and BASE_DIR does tend to be heavily used.

Interestingly (I just noticed), the above produces a BASE_DIR with a
trailing slash but if you use

    $(realpath $(dir $(firstword $(MAKEFILE_LIST))))

instead there's no trailing slash. Depending on personal style you may
prefer one or the other.

This requires GNU make 3.81 BTW.

David Boyce



reply via email to

[Prev in Thread] Current Thread [Next in Thread]