Require a Program in a Makefile
I’ve said it before, and I’ll say it again: I hate the collection of crap
colliquially referred to as the GNU Build System
Since it seems a lot of projects really only use this for discovery of a needed program, here is a snip which shows how to do this without megabytes of really crappy stuff being required to discover and use a program you need to build or process something or another.
define REQUIRE_PROGRAM $(1) := $$(shell which $(3) 2> /dev/null) ifeq ($$($(1)),) $$(error Required program '$(3)' ($(2)) not found. Install it and try again) endif endef
Usage is really easy:
$(eval $(call REQUIRE_PROGRAM,HUGO,Hugo static site generator,hugo))
The macro takes three parameters:
- The name of the variable you want the path of the program stored in.
- A description to facilitate error reporting.
- The name of the program binary that you want to search for.
Simple as that.