Makefile 105: syntax

5.1 注释

井号(#)在Makefile中表示注释。

1
2
3
4
# 这是注释
result.txt: source.txt
# 这是注释
cp source.txt result.txt # 这也是注释
5.2 回声(echoing)

@ suppress the normal ‘echo’ of the command that is executed.
正常情况下,make会打印每条命令,然后再执行,这就叫做回声(echoing)。

1
2
3
test:
# 这是测试
执行上面的规则,会得到下面的结果。
1
2
$ make test
# 这是测试

在命令的前面加上@,就可以关闭回声。

1
2
test:
@# 这是测试

5.3 减号-

- means ignore the exit status of the command that is executed (normally, a non-zero exit status would stop that part of htat build)

通常情况下,Makefile在执行到某一条命令时,如果返回值不正常,就会推出当前make进程,通常结合 rm ,mkdir 命令使用,(空文件或者文件不存在都会返回错误)

这个符号的目的就是如果这条命令执行失败了继续执行,不影响后续命令的执行。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
➜   cat Makefile
all: stage1 stage2

stage1: ;@echo "run stage1.....";
@echo "I am stage1"

stage2:
echo "I am stage2"

#执行
➜ make
run stage1.....
I am stage1
echo "I am stage2"
I am stage2

5.4 加号+

+ means execute this comand under make -n (when commands are not normally executed)
对于命令行前面加上加号+的含义,表明在使用 make -n 命令的时候,其他行都只是显示命令而不执行,只有+ 行的才会被执行。

Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2019-2024 John Doe
  • Visitors: | Views:

请我喝杯咖啡吧~