0

I want to determine the type of recipe the user entered in the shell. However the below code always return false .

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

1 Answer 1

0

You can use MAKECMDGOALS to get the target:

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
2
  • 2
    While this will work, the OP is going about make the wrong way. Have a separate rule for each target. Then refactor using subroutine/functions to reduce repeated code (I am assuming that in the real code there is commonality). When I say wrong way, I mean there are ways to write make-files that are hard to read, hard to maintain and are slow. And there are ways to make then easy to read, easy to maintain, and fast. There is a good paper "recursive make considered harmful" that is worth a read. Jan 3, 2021 at 7:56
  • @ctrl-alt-delor You alright. I was just wondering how I can use conditional expression in Makefile. Jan 4, 2021 at 2:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .