Makefile 的多行注释

来源:互联网 发布:北宋出相 知乎 编辑:程序博客网 时间:2024/05/18 17:58
Makefile 的多行注释
Makefile Comments

注释在 makefile 中起着重要的作用,它帮助我们更快更好的理解 makefile 的内容。

# 注释符
# 字符是注释符,makefile 把 # 字符后面的内容作为注释内容处理(shell、perl 脚本也是使用 # 字符作为注释符)。如果某行的第一个非空字符为 #,则此行会被 make 解释为注释行(命令行除外,如果 Tab 字符之后使用 # 字符,则会被 make 解释为命令行)。
注释行的结尾如果存在反斜线(\),那么下一行也被作为注释行。
如果需要注视多行,在注释行的结尾加行反斜线(\),下一行也被注释,可以注释多行。
建议在书写 makefile 时将注释作为一个独立的行,而不要和 makefile 的有效行放在同一行中书写。make 有时候会把 # 字符之前的内容作为有效行的内容(如定义变量的时候)。
当在 makefile 中需要使用字符 # 时,可以使用 \ 加 #(\#)来实现,表示将 # 字符作为一个普通字符而不是注释符。

示例 1
Makefile 文件的内容如下
# this makefile \
for test comments

makefile_version = 3.82  # there has two spaces before #
comments = "the \# character as the comment contents!"

print :
    echo $(comments)
    printf "make $(makefile_version) welcome! \n"

在命令提示符下输入 “make -s”,执行结果如下:
the # character as the comment contents!
make 3.82   welcome!
0 0
原创粉丝点击