确定 makefile 配方的类型

确定 makefile 配方的类型

我想确定用户在 shell 中输入的配方类型。但是下面的代码总是返回 false 。

all clean:    
ifeq ("$@", "clean")
        echo "This is an clean recipe"
else
    echo "This is not a clean recipe."
endif

答案1

您可以使用制定目标获得目标:

all clean:
ifeq ($(MAKECMDGOALS), clean)
  @echo "This is an clean recipe"
else
  @echo "This is not a clean recipe."
endif
$ make
This is not a clean recipe.
$ make clean
This is an clean recipe

相关内容