Makefile文件函数演示错误

时间:2015-02-09 05:07:29

标签: linux makefile

我试图通过一个小的makefile在我的演示中获取makefile文件函数的结果:

CMD = cat

OBJECTS = Makefile Makefile-filter-func

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

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

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

我在哪里出错。

1 个答案:

答案 0 :(得分:1)

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

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 >$@.in) $(foreach O,$^,$(file >>$@.in,$O))
 <TAB>  @echo The file has been created.

由于空格和标签在你的问题中丢失了,但是很难看出这是否也是你的情况。

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