GNU Make:sed在$(shell)内部管道时不起作用

时间:2013-05-14 23:29:07

标签: shell makefile pipe gnu

这是我的实验性Makefile。

.SECONDEXPANSION:

~/hello.txt:  $(shell echo '$$(@D)/')$(shell echo '$$(@F)' | sed -e 's/hello/bye/')
    echo "$^"

不知何故,sed命令不起作用,并且抱怨循环依赖

gmake: Circular /users/sim/hello.txt <- /users/me/hello.txt dependency dropped.
gmake: *** No rule to make target `echo', needed by `/users/me/hello.txt'.  Stop.

我的预期行为是GNU Make寻找〜/ bye.txt而不是。我做错了什么?

虽然我可以指定&#34; bye.txt&#34;明确地在这个小例子中,我仍然想知道为什么sed命令不适用。谢谢你的帮助。

1 个答案:

答案 0 :(得分:1)

我不明白为什么你有$(shell echo '$$(@D)/');为什么不直接写$$(@D)/

至于第二个,它不起作用,因为$(shell ...)函数是立即评估的,而不是在第二次扩展期间。您还需要通过编写$$(shell ...)来推迟shell函数。

但是,我不确定这是否有效。我不明白为什么你这样做呢;我假设有一些更大的上下文使它有用。因为,您可以通过使用静态模式规则更直接地完成您想要在 MUCH 上面做的事情:

~/hello.txt : %/hello.txt : %/bye.txt
        echo "$^"