Makefile with conditional logic based on external variables
Oct 13, 2022
a variable passed to the makefile target MYVAR=1 make mytask
` is visible with `$(MYVAR)` inside mytask
To use it with a conditional if/else, e.g. to skip a target like Maven surefire skipTests
, you can use ifeq
(reference here).
Full example
# Makefilemytask:
ifeq ($(MYVAR),1)
@echo "yes"
else
@echo "no"
endif
Then launch with:make mytask
to print “no”MYVAR=1 make mytask
to print “yes”
Thanks for reading !
What to do next:
- Clap if useful
- Buy me a coffee
- Follow me for more
- Read my other articles below or from my profile
- Keep in touch on LinkedIn