创建 gnu makefile“函数”时出现问题
我的 makefile 中有很大一部分(约 50 行),需要针对不同情况(使用的不同库)复制粘贴 5 次。是否可以在 makefile 中创建一个函数并只调用该函数而不是复制粘贴?
这是我尝试过的一个例子。基本上,这会尝试为已安装的库找到正确的路径。
define Flags_template
$(1)_include_home := $(HOME)/usr/include
$(1)_include_home_name := $(HOME)/usr/include/$(1)
ifneq ($$(wildcard $($(1)_include_home)/$(2)),)
$(1)_Include := $$($(1)_include_home)
else
ifneq ($$(wildcard $($(1)_include_home_name)/$(2)),)
$(1)_Include := $$($(1)_include_home_name)
endif
endif
CFLAGS += -I$$($(1)_Include)
endef
$(eval $(call Flags_template,stdcout,StdCout.hpp))
.PHONY: test
test:
# stdcout_include_home_name = $(stdcout_include_home_name)
# stdcout_Include = $(stdcout_Include)
# CFLAGS: $(CFLAGS)
输入“make”,我得到这个输出:
# stdcout_include_home_name = /home/nicolas/usr/include/stdcout
# stdcout_Include =
# CFLAGS: -I
它是如此接近。但请注意最后一个“-I”,我总是得到重复项,一个完全耗尽,一个空...
我不明白需要评估什么,用两个 $ 转义等等。
我怎样才能实现这一点?
非常感谢。
I have a big chunk of my makefile (~50 lines) that needs to be copy-pasted 5 times for different case (the different libraries used). Is it possible to create a function in a makefile and just call that function instead of copy-pasting?
This is an example of what I've tried. Basically this tries to find the right path for an installed library.
define Flags_template
$(1)_include_home := $(HOME)/usr/include
$(1)_include_home_name := $(HOME)/usr/include/$(1)
ifneq ($(wildcard $($(1)_include_home)/$(2)),)
$(1)_Include := $($(1)_include_home)
else
ifneq ($(wildcard $($(1)_include_home_name)/$(2)),)
$(1)_Include := $($(1)_include_home_name)
endif
endif
CFLAGS += -I$($(1)_Include)
endef
$(eval $(call Flags_template,stdcout,StdCout.hpp))
.PHONY: test
test:
# stdcout_include_home_name = $(stdcout_include_home_name)
# stdcout_Include = $(stdcout_Include)
# CFLAGS: $(CFLAGS)
Typing "make", I get this output:
# stdcout_include_home_name = /home/nicolas/usr/include/stdcout
# stdcout_Include =
# CFLAGS: -I
It's so close. But note the last "-I", I always get dupplicates, one fully expended, one empty...
I don't understant what needs to be eval'ed, escaped with two $, etc.
How can I achieve this?
Thank you very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
GNU Make (3.82) 手册的第 8.8 节有帮助吗?
这有效(对我来说)
这是下面 GNU makefile 的输出:
GNU Makefile
区别在于通配符调用:
我对何时需要双美元和何时需要单美元有一半的直觉;不过,我不确定我能清楚地表达出这个决定。
Does §8.8 of the GNU Make (3.82) manual help?
This Works (For Me)
This is the output from the GNU makefile just below:
GNU Makefile
The difference is in the wildcard invocations:
I have half an intuition about when double-dollars and when single-dollars are needed; I am not sure I can articulate the decision, though.