2015-02-09 62 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