my_test:
ifdef $(toto)
@echo 'toto is defined'
else
@echo 'no toto around'
endif
Run Code Online (Sandbox Code Playgroud)
$ make my_test
no toto around
$ make my_test toto
toto is defined
Run Code Online (Sandbox Code Playgroud)
$ make my_test
no toto around
$ make my_test toto
no toto around
make: *** No rule to make target `toto'. Stop.
Run Code Online (Sandbox Code Playgroud)
当我运行时,make my_test我按预期得到 else 文本no toto around。然而
make my_test toto
no toto around
make: *** No rule to make target `toto'. Stop.
Run Code Online (Sandbox Code Playgroud)
生成文件版本
$ make -v
GNU Make 3.81
Run Code Online (Sandbox Code Playgroud)
SLE版本
$ cat /etc/*release
VERSION_ID="11.4"
PRETTY_NAME="SUSE Linux Enterprise Server 11 SP4"
Run Code Online (Sandbox Code Playgroud)
关键是要make my_test详细 if toto,如果toto没有给出,则命令将静默运行
ami*_*sax 22
您需要删除toto周围的美元,并以不同的方式从命令行传递toto
命令行
make toto=1 my_test
Run Code Online (Sandbox Code Playgroud)
生成文件
my_test:
ifdef toto
@echo 'toto is defined'
else
@echo 'no toto around'
endif
Run Code Online (Sandbox Code Playgroud)