Makefile:将变量传播到从属目标 [英] Makefile: Propagating variables to dependent targets

查看:60
本文介绍了Makefile:将变量传播到从属目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是

从本质上讲,build调用所有image目标(base是第一个目标),并为每个目标运行docker build--no-cache=true.

Essentially, build calls all image targets (base being the first one), and runs docker build with --no-cache=true for each one.

我希望有一个rebuild目标,该目标可以使用--no-cache=false而不是--no-cache=true运行所有image目标,而无需复制代码.我猜想正确的方法是在rebuildbuild中设置一个变量,其范围将覆盖诸如images中任何一个的依赖目标.

I would like to have a rebuild target which runs all image targets with --no-cache=false rather than --no-cache=true, without duplicating the code. I guess that the right way is to set a variable in rebuild and build whose scope would cover dependent targets like any of the images.

如何在目标范围内涵盖所有相关目标的变量中定义变量?

How do I define a variable in a target whose scope covers all dependent targets?

推荐答案

非常相似,例如提到的问题:

Quite similar, like in mentioned question:

images := base web proxy lb users api

$(images):
    @echo $@ docker --no-cache=$(NO_CACHE)

build: NO_CACHE=true
rebuild: NO_CACHE=false

rebuild build: $(images)

例如,如果您想调用make base,则可能要为NO_CACHE设置默认值.

You may want to set a default value for NO_CACHE in case you would like to call make base for example.

这篇关于Makefile:将变量传播到从属目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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