将选项传递给 makefile

sma*_*ber 15 make parameter

生成文件

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)

  • 实际上我想使用 `ifdef` 因为在我的例子中 `toto` 的值并不有趣,我只需要知道它是否在这里 (2认同)
  • @smarber 那么`toto` 是否应该成为目标?请编辑您的问题以澄清您想要做什么。 (2认同)