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.

我哪里错了。

指向答案的指针可以在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 >$@.in) $(foreach O,$^,$(file >>$@.in,$O))
 <TAB>  @echo The file has been created.

由于空格和制表符在你的问题中丢失了,所以很难判断这是否也是你的情况。

请注意,配方通常应该以TAB开头。

最新更新