Makefileレシピタイプの決定

Makefileレシピタイプの決定

ユーザーがシェルに入力したレシピの種類を確認したいと思います。しかし、以下のコードは常に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

おすすめ記事