【问题标题】:Makefile Errors - "***missing separator" & "***recipe commences before first target"Makefile 错误 - “***缺少分隔符”和“***recipe 在第一个目标之前开始”
【发布时间】:2017-05-20 02:34:57
【问题描述】:

我正在尝试为 os161 构建用户空间。当我在命令行中输入 make 时,出现以下错误:

Makefile 24: ***缺少分隔符(您的意思是 TAB 而不是 8 个空格?)。停下来。

我在第 24 行检查了 Makefile,并尝试在行首添加一个 TAB,但这没有奏效,因为我得到了另一个错误:

Makefile 24: ***recipe 在第一个目标之前开始。停下来。

这是完整的 makefile 供参考:

#
# Toplevel makefile for OS/161.
#
#
# Main rules:
#    all (default):  depend and compile system; install into staging area
#    rebuild:        likewise, but start with a clean slate.
#    fullrebuild:    likewise, but start with a very clean slate.
#
# What all does, in order:
#    tools:          depend and compile the tools used in build.
#    includes:       install header files.
#    build:          depend and compile the system.
#
# Other targets:
#    depend:         just update make dependency information.
#    tags:           generate/regenerate "tags" files.
#    install:        install into $(OSTREE).
#    clean:          remove generated files.
#    distclean:      remove all generated files.
#

TOP=.
.include "$(TOP)/mk/os161.config.mk"

all:;  # make this first

MKDIRS=$(OSTREE)

.include "$(TOP)/mk/os161.mkdirs.mk"

all: tools .WAIT includes .WAIT build

rebuild:
    $(MAKE) clean
    $(MAKE) all

fullrebuild:
    $(MAKE) distclean
    $(MAKE) all

# currently no tools required, hence no tools/ dir or work to do
tools:
    @true

build:
    (cd userland && $(MAKE) build)
    (cd man && $(MAKE) install-staging)
    (cd testscripts && $(MAKE) build)

includes tags depend:
    (cd kern && $(MAKE) $@)
    (cd userland && $(MAKE) $@)

clean:
    (cd kern && $(MAKE) $@)
    (cd userland && $(MAKE) $@)
    rm -rf $(INSTALLTOP)

distclean: clean
    rm -rf $(WORKDIR)

install: $(OSTREE)
    (cd $(INSTALLTOP) && tar -cf - .) | (cd $(OSTREE) && tar -xvf -)


.PHONY: all rebuild fullrebuild tools build includes tags depend
.PHONY: clean distclean

# old BSD name, same as distclean
cleandir: distclean
.PHONY: cleandir

问题(24)是:

.include "$(TOP)/mk/os161.config.mk"

任何帮助将不胜感激。我检查了类似的 makefile 错误,但似乎找不到问题所在。

【问题讨论】:

  • 该行至少应在all: 行之后
  • 仍有缺少分隔符的错误。试着把所有:;在第 24 行之前。
  • 我解决了这个问题,它与 makefile 语法没有任何关系。我的默认 make 是 GNU make,我不得不改用 BSD make。
  • 您的Makefile 使用的是什么编辑器?一些编辑器需要专门配置以允许插入 tab 字符

标签: linux os161 makefile


【解决方案1】:

仔细阅读documentation of GNU make,尤其是include directive

你的

.include "$(TOP)/mk/os161.config.mk"

(错误地)请求包含一个路径以双引号开头的文件(您可能没有,所以include 失败...)

你想要

-include $(TOP)/mk/os161.config.mk

并且该行以减号或破折号开头,而不是点。

请务必使用保持制表符字符完整的编辑器。

顺便说一句,FreeBSD make 接受带有起始点的 .include 指令,并且需要双引号中的路径。

【讨论】:

  • 这有助于人们将来参考。在这种情况下,鉴于 OS161 文档,我确实需要 BSD make,但我使用的是 GNU make。我想知道 GNU make 的语法不正确,但 BSD 的语法不正确,这样更容易找到错误!谢谢:)
【解决方案2】:

分隔符是 <TAB> 。请不要在 Makefile、Makefile.in 中的行开头使用空格 ...

片段:

21  #
22  
23  
24  TOP=.
25  
26  all:;  # make this first
27  
28  MKDIRS=$(OSTREE)
29  
30  <TAB>include "$(TOP)/mk/os161.mkdirs.mk"
31  
32  all: tools .WAIT includes .WAIT build
33  
34  rebuild:
35  <TAB>$(MAKE) clean
36  <TAB>$(MAKE) all
37  
38  <TAB>fullrebuild:
39  <TAB>$(MAKE) distclean
40  <TAB>$(MAKE) all

【讨论】:

    猜你喜欢
    • 2016-10-04
    • 1970-01-01
    • 1970-01-01
    • 2012-05-13
    • 1970-01-01
    • 2011-02-24
    • 1970-01-01
    • 2022-01-05
    • 2011-03-19
    相关资源
    最近更新 更多