make 在执行时会设置一个特殊变量 -- "MAKECMDGOALS" ,该变量记录了命令行参数指定的终极目标列表,没有通过参数指定终极目标时此变量为空。该变量仅限于用在特殊场合(比如判断),在 Makefile 中最好不要对它进行重新定义。
下面通过一个实例来说明此变量的意思,设一 Makefile 内容如下:
- ifeq ("$(MAKECMDGOALS)","are you ok cmdgoals")
- who="you"
- endif
- are:
- @echo "are"
- you:
- @echo "you"
- ok:
- @echo "ok"
- cmdgoals:
- @echo "MAKECMDGOALS: $(MAKECMDGOALS)"
- @echo "who are $(who)"
运行输出:
[beyes@SLinux tempa]$ make are you ok cmdgoals
are
you
ok
MAKECMDGOALS: are you ok cmdgoals
who are you
我们在命令行中同时指定了 "are" , "you", "ok", 以及 "cmdgoals" 这 4 个目标。这些目标的名字都会传入 MAKECMDGOALS 中。
在其中我们可以学习几个命令:
1.判断
ifeq ("$(MAKECMDGOALS)","are you ok cmdgoals") who="you" endif
2.echo
@echo