规则的命令部分中使用的定义中使用的条件的 Makefile 问题
我的 makefile 中有一个具有这种结构的部分:
bob:
ifdef DEBUG
@echo running
endif
@echo chug chug chug
ifdef DEBUG
@echo done
endif
bobit:
@echo "before"
@make bob
@echo "after"
我在这里大大简化了,所有的 echo 实际上都是不平凡的命令块,并且还有更多条件性的东西,但这抓住了我的问题的本质。
出于技术原因,我现在不想进入,我需要摆脱那个子制作,但是因为 echo 代表了不平凡的代码量,我不想只是复制并过去 bob 的主体来代替子品牌。
理想情况下,我想做的是这样的
define BOB_BODY
ifdef DEBUG
@echo running
endif
@echo chug chug chug
ifdef DEBUG
@echo done
endif
endef
bob:
$(BOB_BODY)
bobit:
@echo "before"
$(BOB_BODY)
@echo "after"
不幸的是,条件似乎在欺骗我,它们产生“ifdef:命令未找到”错误,我尝试使用 eval 和 call 的各种组合来解决这个问题,但似乎无法找出让它发挥作用的方法。
我该如何进行这项工作? 这是否是解决问题的正确方法?
I have a section of makefile that has this sort of structure:
bob:
ifdef DEBUG
@echo running
endif
@echo chug chug chug
ifdef DEBUG
@echo done
endif
bobit:
@echo "before"
@make bob
@echo "after"
I'm simplifying greatly here, all the echo's are actually non trivial blocks of commands and there is more conditional stuff, but this captures the essence of my problem.
For technical reasons I don't want to get into right now, I need to get rid of that submake, but because the echo's represent nontrivial amounts of code I don't want to just copy and past the body of bob in place of the submake.
Ideally what I'd like to do is something like this
define BOB_BODY
ifdef DEBUG
@echo running
endif
@echo chug chug chug
ifdef DEBUG
@echo done
endif
endef
bob:
$(BOB_BODY)
bobit:
@echo "before"
$(BOB_BODY)
@echo "after"
Unfortunately the conditionals seem to be shafting me, they produce "ifdef: Command not found" errors, I tried getting around this with various combinations of eval and call, but can't seem to figure out a way to get it to work.
How do I make this work? and is it even the right way to approach the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我解决这个问题的方法是使用 bash 条件语句,这实际上具有一定的意义,因为我们正在使用命令而不是制定规则。
所以我上面的理想解决方案变成了这样
The way I have fixed this is to use bash conditionals instead, which actually makes a certain amount of sense since we are playing with commands and not make rules.
So my ideal solution from above becomes something like
您只需更改 ifdef/define 的顺序即可:
更新
You can simply change the order of ifdef/define:
UPDATE