在目标体内更改Makefile变量值 [英] Change Makefile variable value inside the target body

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

问题描述

是否可以在目标正文中重新分配Makefile变量值?

Is there a way to reassign Makefile variable value inside of the target body?

我想做的是为调试编译添加一些额外的标志:

What I am trying to do is to add some extra flags for debug compilation:

%.erl: %.beam
    $(ERLC) $(ERLFLAGS) -o ebin $<

test: clean debug_compile_flag compile compile_test

debug_compile:
    $(ERLCFLAGS) += -DTEST

因此,如果我调用 test 目标,我想清理我的环境,则添加一些新的标志(如 -DTEST 到现有的标志),并编译整个代码再次(先提供资料,然后再测试模块).

So if I invoke test target I would like to clean up my environment, add some new flags (like -DTEST to the existing ones), compile the whole code once again (first sources, then test modules).

我不想复制/粘贴用于设置新标志的编译代码,因为到处都是逻辑.

I do not want to copy/paste the code for compiling with some new flags set since there is a lot of logic put here and there.

是否存在一些简单的方法来重新定义变量值,以便我可以重用现有代码?

Is there some easy way to redefine the variable value so I can reuse the existing code?

推荐答案

编辑:如Beta在不.在Makefile中无法执行此操作.但是,您可以在make命令行上更改变量的值.如果您按照以下方式重写Makefile:

No. There is no way to do this in the Makefile. You can however change the value of a variable on the make command line. If you rewrite your Makefile as follows:

ERLCFLAGS += $(ERLCFLAGSADDED)

%.erl: %.beam
    $(ERLC) $(ERLCFLAGS) -o ebin $<

test: clean compile compile_test

然后,您可以使用以下命令调用make来执行测试:

Then, you can invoke make to perform your tests using:

make ERLCFLAGSADDED=-DTEST test

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

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