2015-02-09 64 views
1

我一直想把文件功能的结果,在Makefile中为我演示用小makefile文件为:的Makefile文件功能演示错误

CMD = cat 

OBJECTS = Makefile Makefile-filter-func 

program : $(OBJECTS) 
     $(file >[email protected]) $(foreach O,$^,$(file >>[email protected],$O)) 
     @echo The file has been created. 
all : 
     $(CMD) $(CMDFLAGS) @[email protected] 
     @echo The file contents are printed. 
     @rm [email protected] 
     @echo The file removed. 

我想用ls命令来查看文件的文件名,但这makefile有以下错误:

Makefile-file-func:7: *** recipe commences before first target. Stop. 

我在哪里出错。

回答

1

的指针答案可以在源代码中找到make(版本3.82),该文件read.c在:

989  /* This line starts with a tab but was not caught above because there 
990   was no preceding target, and the line might have been usable as a 
991   variable definition. But now we know it is definitely lossage. */ 
992  if (line[0] == cmd_prefix) 
993  O (fatal, fstart, _("recipe commences before first target")); 

有了这些信息,可以通过插入空格,重现您的问题正确的位置。在下面的代码,~表示空间和<TAB>表示TAB

program : $(OBJECTS) 
~~~~~~~~$(file >[email protected]) $(foreach O,$^,$(file >>[email protected],$O)) 
<TAB> @echo The file has been created. 

由于空格和制表符得到你的问题失去了,这是一个有点很难看到,如果这正是你的情况,以及虽然。

请注意,食谱通常应该以TAB开头。

+0

非常感谢@ReinierTorenbeek的回复。它解决了我的问题,并帮助我从您提供链接的源代码中了解配方。 – 2015-02-09 05:40:16

+0

很高兴帮助,制表符/空格总是令人讨厌'make'。 – 2015-02-09 05:45:00

+0

是的,先生!再次感谢@ReinierTorenbeek – 2015-02-09 06:19:31