Subject: Re: bug in handling of != in make?
To: None <>
From: Alan Barrett <>
List: tech-userlevel
Date: 06/09/2006 14:28:42
On Fri, 09 Jun 2006, Roland Illig wrote:
> VERSION_cmd=    echo '$$NetBSD$$'
> VERSION=        ${VERSION_cmd:sh}
> all:
>         echo ${VERSION:Q}
> This is the BSD Make equivalent to using $(shell echo '$$NetBSD$$') in 
> GNU Make. They both do not further expand '$' characters from the output.

But the above will execute the shell command every time ${VERSION} is
expanded.  To avoid that, try this:

VERSION_cmd=	echo '$$NetBSD$$'
# The above sets VERSION=\$NetBSD\$
		echo ${VERSION}

> The question whether someone might rely on the current behaviour of the 
> != operator to mangle the output remains valid though.

!= is not mangling the output; "VERSION != cat file" will set
VERSION=$NetBSD$ as expected.  However, != is also not protecting the
result from being mangled later.

Subsequent expansion of ${VERSION} will recursively try to expand
$N at the beginning and $<nothing> at the end.  AFAIK, there's no
way to suppress this recursive expansion.  Using ${VERSION:Q} after
VERSION!=... doesn't help because the recursive expansion happens before
the :Q modifier is applied.

The only way around it, AFAIK, is to apply a :Q modifier after the
shell expansion but before saving the result into a variable, as in

--apb (Alan Barrett)