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 main functional and unit tests
	$(eval testsuite ?= 'main') # or "external"
	$(eval filter ?= '.')
	$(PHPUNIT) --testsuite=$(testsuite) --filter=$(filter) --stop-on-failure

 More on Stackoverflow   Read the doc  More on the web  Random snippet