有条件地附加到Makefile目标内部的变量 [英] Conditionally appending to a variable inside a Makefile target

查看:81
本文介绍了有条件地附加到Makefile目标内部的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的GNU Makefile:

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
    echo $(LIST)

targetA: preA targetMain
targetB: preB targetMain

preA:
LIST += itemA

preB:
LIST += itemB

这个想法是我要么运行make targetA要么make targetB.他们两个都做非常相似的事情,但是有不同的项目列表.问题在于该变量没有条件附加,而是始终附加,这意味着我的输出始终是"item1 itemA 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

这篇关于有条件地附加到Makefile目标内部的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆