为什么GNU Make罐装食谱不起作用? [英] Why GNU Make canned recipe doesn't work?

查看:53
本文介绍了为什么GNU Make罐装食谱不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望看到下面的makefile创建的文件 foo1 foo3 .但是,仅创建文件 foo3 .在我看来,罐头食谱 make-foo 只是被make忽略了.目标 foo1 foo2 (空配方)的调试结果是相同的.

I'm expecting to see files foo1 and foo3 created by the makefile below. However only a file foo3 is created. To me it seems that the canned recipe make-foo is simply ignored by make. The debug outcome of targets foo1 and foo2 (empty recipe) is identical.

# why canned recipe doesn't work ?
# http://www.gnu.org/software/make/manual/make.html#Canned-Recipes
define make-foo =
echo making $@
touch $@
endef

.PHONY: all
all: foo1 foo2 foo3

# foo1 is not created, but why ?
.PHONY: foo1
foo1:
    $(make-foo)

# debug output similar to foo1
.PHONY: foo2
foo2:

# this works
.PHONY: foo3
foo3:
    echo making $@
    touch $@

运行品牌:

xxxx@xxxx:/dev/shm$ make -dRr
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i686-pc-linux-gnu
Reading makefiles...
Reading makefile `makefile'...
Updating makefiles....
 Considering target file `makefile'.
  Looking for an implicit rule for `makefile'.
  No implicit rule found for `makefile'.
  Finished prerequisites of target file `makefile'.
 No need to remake target `makefile'.
Updating goal targets....
Considering target file `all'.
 File `all' does not exist.
  Considering target file `foo1'.
   File `foo1' does not exist.
   Finished prerequisites of target file `foo1'.
  Must remake target `foo1'.
  Successfully remade target file `foo1'.
  Considering target file `foo2'.
   File `foo2' does not exist.
   Finished prerequisites of target file `foo2'.
  Must remake target `foo2'.
  Successfully remade target file `foo2'.
  Considering target file `foo3'.
   File `foo3' does not exist.
   Finished prerequisites of target file `foo3'.
  Must remake target `foo3'.
echo making foo3
Putting child 0x0914c5f0 (foo3) PID 3132 on the chain.
Live child 0x0914c5f0 (foo3) PID 3132 
making foo3
Reaping winning child 0x0914c5f0 PID 3132 
touch foo3
Live child 0x0914c5f0 (foo3) PID 3133 
Reaping winning child 0x0914c5f0 PID 3133 
Removing child 0x0914c5f0 PID 3133 from chain.
  Successfully remade target file `foo3'.
 Finished prerequisites of target file `all'.
Must remake target `all'.
Successfully remade target file `all'.

缺少 foo1 :

xxxx@xxxx:/dev/shm$ ll foo*
-rw-r--r-- 1 xxxx xxxx 0 2011-02-17 20:04 foo3

推荐答案

我认为您不希望=define行的末尾.这个makefile在这里对我有用:

I think you don't want the = at the end of the define line. This makefile works here for me:

define make-foo
echo making $@
touch $@
endef

.PHONY: foo1
foo1:
    $(make-foo)

示例:

$ make
echo making foo1
making foo1
touch foo1
$ ls
Makefile  foo1

GNU制作手册似乎表明=应该没问题,但是像您一样,如果在那里,我会得到不同的行为.

The GNU make manual seems to indicate that the = should be just fine, but like you, I get different behaviour if I have it there.

我刚刚问过:

GNU在多行变量声明中有所作为

要弄清这里发生的事情...

To get some clarification on what's happening here...

这篇关于为什么GNU Make罐装食谱不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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