Subject: Re: bug#35886: Built-in variable dependency issue with bindir/exec_prefix/prefix

From: Eric Blake <[email-masked]>
Date: Fri, 24 May 2019 13:04:58 -0500

tag 35886 notabug
thanks

On 5/24/19 12:33 PM, Sternberg, Jay E wrote:
> Built-in variables are stored in the generated Makefile in ascending sort order.  This results in dependency issues specifically for bindir and exec_prefix. after running './configure --prefix /usr'; the resulting Makefile variables are as follows:
> 
> ...
> bindir = ${exec_prefix}/bin
> build_alias =
> builddir = .
> ...
> dvidir = ${docdir}
> exec_prefix = ${prefix}
> host_alias =
> ...
> pdfdir = ${docdir}
> prefix = /usr
> program_transform_name = s,x,x,
> ...
> 
> The result is that when make install uses bindir, the value is "/bin", not "/usr/bin"

You are misunderstanding how makefile macros are handled, and forgetting
that it is a two-phase process.  Make macros are not like shell
variables processed in textual order (where 'bindir =
${exec_prefix}/bin' would assign '/bin/' to the variable bindir if the
variable exec_prefix were currently empty) but rather the first pass
stores all macro definitions, and the second pass then refers to those
stored definitions when determining rules to run. When a macro is
encountered, the literal text stored in the first pass is then expanded
recursively, regardless of the order the macros were defined (so
expanding ${bindir} substitutes the text '${exec_prefix}/bin' then
rescans that output to notice that more substitution is needed, which in
turn expands exec_prefix, then in turn prefix).

Proof:

$ make -f - <<\EOF
> a=${b}
> c=${d}
> d=hi
> all:
>       echo ${a}
> b=${c}
> EOF
echo hi
hi

I see no bug here, so I'm closing this, but feel free to add more
details if there is something else we're missing from your report and we
can reopen as needed.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org