[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Possible out of order execution of pre-requisite targets in 3.82
From: |
Brown, Ruben |
Subject: |
Possible out of order execution of pre-requisite targets in 3.82 |
Date: |
Mon, 2 Apr 2012 23:13:01 -0400 |
I have a question about a behavior I'm seeing in gnu make 3.82. The behavior
seems undesirable, but has persisted from at least as far back as 3.79. The
behavior can be demonstrated with a very simple make file with two targets, A
and B and a single variable VAR. I have included an example below, along with
the observed, naively expected behavior, and a short argument for a change in
this behavior. Is this behavior by design or an unfortunately long lived bug?
If it is by design, what purpose does maintaining this behavior serve?
***Makefile***
.PHONY: all A B
all: A
VAR := 0
A: B
A: VAR:= 1
B:
@echo VAR=$(VAR) @ B
A:
@echo VAR=$(VAR) @ A
***Observed Behavior***
It appears that the dependent target B is always executed after the evaluation
of VAR:=1, when target A is the entry point. This cannot be altered by
reordering the target definitions, or by specifying all dependencies of A in a
single ordered list (A: B VAR:=1). However, entry via the B target causes VAR
to evaluate to 0.
$ make-3.82/make -f Makefile B
VAR=0 @ B
$ make-3.82/make -f Makefile A
VAR=1 @ B
VAR=1 @ A
***Expected Behavior***
The naively expected behavior is that the value of VAR upon evaluation of B
would always be 0, because neither B nor any of its dependencies modify VAR.
$ make-3.82.1/make -f Makefile B
VAR=0 @ B
$ make-3.82.1/make -f Makefile A
VAR=0 @ B
VAR=1 @ A
***Potential argument for a change of behavior***
The current behavior violates the apparent scope of the target B, which can be
construed to be the state of the global variables (and system environment)
after the evaluation of the dependencies of B. Using this definition of scope
implies that the evaluation of the peer dependency VAR:=1 should be out of
scope with regard to B, and only impact VAR's value in scope of A, which should
include all changes made to the state of global variables made by all of its
own dependencies. This would also cause the behavior of B to be invariant, no
matter the entry point.
- Possible out of order execution of pre-requisite targets in 3.82,
Brown, Ruben <=