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: Luke Shumaker
Subject: Re: Crossing directories for target and source
Date: Thu, 07 Oct 2010 17:26:28 -0400

On Thu, 2010-10-07 at 17:10 -0400, David Boyce wrote:
> 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

I too like to use absolute paths, although I generally base mine off of
$(CURDIR). Also, I provide a method to include makefiles in a way that
all files are identified relative to the makefile containing the rule;
this makes moving directories around significantly easier, as well has
converting to/from recursive make.

ifndef THISFILE
THISFILE=$(CURDIR)/Makefile
endif
THISDIR=$(patsubst %/,%,$(dir $(THISFILE)))
include=$(foreach THISFILE,$(abspath $1),\
$(eval include $(THISFILE)))

I then use ``$(eval include, ... )'' instead of ``include ...''.

~ LukeShu





reply via email to

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