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.
This was my eventual answer to have an inline solution.
everything: foo bar $(if $(EXTRA), biz baz)
recipe_to_do_stuff
You can define dependencies in multiple lines by repeating the target name at the beginning of the line:
# Makefile
baz:
@echo baz
bar:
@echo bar
foo: bar
foo: baz
foo:
@echo foo
$ make foo
bar
baz
foo
Hence, you can ifdef
around one or more of these dependency lines:
# Makefile
baz:
@echo baz
bar:
@echo bar
foo: bar
ifdef DO_BAZ
foo: baz
endif
foo:
@echo foo
And define the variable if you want the extra dependencies:
$ make foo
bar
foo
$ make foo DO_BAZ=1
bar
baz
foo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With