在目标内部设置Makefile变量 [英] Set Makefile variable inside target

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

问题描述

我在makefile中有一个目标:

I have a target inside a makefile:

all: $(TARGETS)

我想要一个与all不同的变量,仅因为它设置了环境变量.像这样:

I want a variant that differs from all only by the fact that it sets an environment variable. Something like:

all-abc: $(TARGETS)
    ABC=123

但这不起作用,因为在设置变量之前先处理了依赖项.我曾经考虑过在真正的依赖项之前设置另一个依赖项,该依赖项只是设置环境变量,但我认为环境不会在目标之间持久存在.就是说

but that doesn't work because the dependencies are processed before the variable is set. I've thought about having another dependency before the real ones that just sets the environment variable but I don't think the environment persists across targets. That is to say that

abc:
    ABC=123
all-abc: abc $(TARGETS)

不起作用.我最终想要做的是

doesn't work. What I ultimately want to be able to do is

$ make all-abc

代替

$ ABC=123 make

是否可以像这样设置环境变量?

Is it possible to set an environment variable like this ?

(GNU Make 3.82)

(GNU Make 3.82)

推荐答案

尝试一下:

all:
    @#usual rule, if you call `make all-abc`, this will print "123"
    @echo $(ABC)

all-abc: ABC=123
all-abc: all
    @#what you put here it's going to be executed after the rule `all`

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

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