💾 SuperFloppies Place! 💾

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 (autoconf/automake/libtool).

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:

Simple as that.