Search code examples
makefileconditional-statementsgnu

Conditional Dependencies in GNU Make


I would like to have my target have conditional dependencies. Below is an example that doesn't work

everything: foo bar \
ifndef EXTRA
  biz baz
endif
    recipe_to_do_stuff 

So if I run make it will make everything with all the dependencies foo bar biz baz. But if I ran make EXTRA=true it would make everything with only foo bar.

Is this a possibility? I could have conditionals that run two separate commands but my target has lots of possible dependencies and I don't want to have two places to change if they need updates. Thanks in advance.


Solution

  • This was my eventual answer to have an inline solution.

    everything: foo bar $(if $(EXTRA), biz baz)
        recipe_to_do_stuff