Conditionally appending to a variable inside a Makefile target
I have a GNU Makefile that looks a bit like this:
LIST = item1
.PHONY: targetMain targetA targetB preA preB
targetMain:
# DO all the work in here
ech开发者_StackOverflow中文版o $(LIST)
targetA: preA targetMain
targetB: preB targetMain
preA:
LIST += itemA
preB:
LIST += itemB
The idea is that I either run make targetA or make targetB. Both of them do a very similar thing, but with a different list of items. The problem is that the variable isn't conditionally appended to, it is always appended to, meaning my output is always "item1 itemA itemB".
How can I conditionally append to a variable?
LIST = item1
.PHONY: targetMain targetA targetB
targetMain:
# DO all the work in here
echo $(LIST)
targetA: LIST+=itemA
targetB: LIST+=itemB
targetA targetB: targetMain
精彩评论