A can test whether a variable holds a non-empty value in the current process. With GNU make, any variable can be checked. With BSD make, you must set the needvars variable to the list of variables that can be checked. and elegant way to test whether a variable is defined in your make run. Works with both GNU Make and BSD Make.
With make-needvar you can test whether a variable holds a non-empty value in the current make process. This is done with a target
Include mk/needvar.mk at the top level in your project.
include mk/needvar.mkFor BSD make, define the variables you want to check:
needvars = foo bar bazCheck that a variable is set to a non-empty value in a target:
mytarget: needvar.X
...That's it!
- Works with both GNU Make and BSD Make
- Simple implementation
- Easy to integrate into existing projects
-
Copy the
mk/directory to your project, which contains:- mk/needvar.mk
- mk/needvar.gnu.mk
- mk/needvar.bsd.mk
-
Add this line to your Makefile:
include mk/needvar.mkThat's it! Now running make will show help for all documented targets.
The included example Makefile demonstrates the features:
needvars = a b c
foo: needvar.a
echo "this is foo, now with $(a)"This project is released into the public domain. Feel free to use it however you like!
Feel free to open issues or submit pull requests on GitHub.