Make $* check for string

Viewed 26

I am trying to check if $* matches hello . But the following is not working

 build: build-hello

 build-%:
 ifeq ($*, hello)
   echo Hello
 else
   echo World
 endif
1 Answers

The conditions in the ifeq's are processed at makefile read time -- when $* is still blank. There's a couple of workarounds to this: First, you could do a build-hello: rule, which would override the build-% rule for build-hello. If, on the other hand you wanted to minimize rules, you could use the $(if) function as so:

build-%:
   @echo $(if $(filter $*,hello),Hello,World)

Or, you could just use shell logic to accomplish this as well.

Related