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

Re: Makefile parametrisation



On Tue, Apr 25, 2006 at 06:56:27PM +0200, Dennis Stosberg wrote:
> hendrik@topoi.pooq.com wrote:
> 
> > I'd like to define a symbol ARCH in my Makefile to be the output
> > of
> >       uname -m
> >
> > The obvious thing, just starting with
> >
> > ARCH = `uname -m`
> >
> > didn't seem to work.  It defined ARCH to be `uname -m' instead of
> > i686 or x86_64.  Not unreasonable, but What *is* the way to do
> > this?
> 
> With GNU make you can use "ARCH = $(shell uname -m)".

...or even "ARCH := $(shell uname -m)", the difference being that when
you use ":=", the value will be expanded only once upon definition,
while with "=", it is evaluated anew every time you use it -- resulting
in lots of unnecessary fork()s when you have many occurrences of
$(ARCH) in your makefile.[1]

Since the result of "uname -m" is unlikely to change while running
make, this performance optimisation can safely be made.

Cheers,
Almut


[1] sceptical minds can verify this themselves: ;)

With the following little makefile

ARCH := $(shell uname -m)
target:
	# $(ARCH) $(ARCH) $(ARCH) $(ARCH)

the command

$ strace -eprocess make 3>&2 2>&1 1>&3 | grep fork | wc -l

should count only 2 forks, while when using "ARCH = $(shell uname -m)"
you'd get 5 ...



Reply to: