Passing parameters to a Makefile rule
Published on 2020-12-09 • Modified on 2020-12-09
In this snippet, we will see how to pass parameters to a Makefile rule. You can do so by adding parameter=value to the make call, then, in your rules you can access the values with $(parameter). In the following snippet, I also handle default parameters with the help of the eval function. In this case, if nothing is passed to make test then the final command is ./vendor/bin/phpunit --testsuite='main' --filter='.' --stop-on-failure. Check out my full Makefile here.
## —— Tests ✅ —————————————————————————————————————————————————————————————————
test: phpunit.xml ## Run tests with optional suite and filter
@$(eval testsuite ?=)
@$(eval filter ?= '.')
@if [ -z "$(testsuite)" ]; then \
$(PHPUNIT) --filter=$(filter) --stop-on-failure; \
else \
$(PHPUNIT) --testsuite=$(testsuite) --filter=$(filter) --stop-on-failure; \
fi
More on Stackoverflow Read the doc More on the web Random snippet
Call to action
Did you like this post? You can help me back in several ways: (use the "reply" link on the right to comment or to contact me )
- Report any error/typo.
- Report something that could be improved.
- Like and repost!
- Follow me on Bluesky 🦋
- Subscribe to the RSS feed.
- Click on the More on Stackoverflow buttons to make me win "Announcer" badges 🏅.
Thank you for reading! And see you soon on Strangebuzz! 😉