bug-make
[Top][All Lists]
Advanced

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

Condtional target-specific variable assignment does not work as expected


From: Ed Hutchins
Subject: Condtional target-specific variable assignment does not work as expected
Date: Fri, 9 Aug 2013 12:59:52 -0700

The following Makefile:

condset: COND ?= one
condset: condset2
@echo $@ COND [$(COND)]

condset2: COND ?= two
condset2: condset3
@echo $@ COND [$(COND)]

condset3: COND ?= three
condset3:
@echo $@ COND [$(COND)]

outputs:

condset3 COND [three]
condset2 COND [two]
condset COND [one]

I would have expected "one" in all cases. Note that:

addset: COND += one
addset: addset2
@echo $@ COND [$(COND)]

addset2: COND += two
addset2: addset3
@echo $@ COND [$(COND)]

addset3: COND += three
addset3:
@echo $@ COND [$(COND)]

produces:

addset3 COND [one two three]
addset2 COND [one two]
addset COND [one]

The reason I need such a construct falls out of another shortcoming I've run into while
trying to use make to manage the configuration of a set of servers (basically a state machine):
there's no way to specify a true ordering-only constraint in gmake's syntax. If there were a way
to specify a weak dependency (e.g. if "A" and "B" are both targets under consideration, always
complete "B" before "A" without any other side-effects) I wouldn't need the above. Unfortunately
the order-only dependency cannot be used for this in a reusable way.

In my case I'd like to have "init", "start" and "start_clean" end-user targets which reuse common
targets which in turn depend on targets specified by the above semantic intent. If there were a
true order-only operator (say ||), I could do:

.PHONY: <all of the below>

init_server: <some initialization for a running server>

start_server: <start a server and load existing database info>

start_clean_server: <start a server and create a clean database>

common: || init_server start_server start_clean_server

init: init_server common

start: start_server common

start_clean: start_server common

If I try the above with the current order-only | operator all three dependencies are
invoked by common. Is there a way to get the effect of the above that anyone can
think of?


reply via email to

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