首页 > 解决方案 > 为什么注释会使我的 Makefile 命令无效?

问题描述

我正在尝试向我的 Makefile 添加一些评论,但看到一些我不理解的奇怪行为。以下以 a 成功make plan-all

plan-all: \
    plan-master \
    plan-log-archive \
    plan-shared \
    plan-audit \

但是,如果我尝试添加评论:

plan-all: \
# --------------------
#  Global Accounts    |
# --------------------
    plan-master \
    plan-log-archive \
    plan-shared \
    plan-audit \

我失败了:

make: plan-master: 没有这样的文件或目录

标签: makefile

解决方案


无法将注释添加到使用反斜杠的逻辑行中。这是不可能的。

您可以在规则之前添加它们,也可以使用多个规则而不是反斜杠:

# --------------------
#  Global Accounts    |
# --------------------
plan-all: \
    plan-master \
    plan-log-archive \
    plan-shared \
    plan-audit \

或者

# --------------------
#  Global Accounts    |
# --------------------
plan-all: \
    plan-master

# -------------------
#  Other Accounts    |
# -------------------
plan-all: \
    plan-log-archive \
    plan-shared \
    plan-audit \

推荐阅读