diff --git a/Makefile b/Makefile index 37470e7788fc8a2eff6c90d651e2dfc546851f0d..28694873d966bc72414e76474c4eb7d964fa7e82 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,13 @@ MK_DESCRIPTION="This provides some additional tools for makefiles." MK_LICENSE="Released under the BSD two-clause license, see the LICENSE file for more information." +MK_ASSURE="python3 ls tree clang" include makext.mk help: .help -demo: .assure +demo-assure: .assure + @echo "All good, continuing..." build-app: clean-cache # Build the application @echo "Building the application..." diff --git a/README.md b/README.md index c6aca6b998254a7de5cfaf6a0a9daa6a0941ffcc..5f8fd865e6c8be78d34043c7932c4cb39e9b8f62 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,13 @@ > This extensions are abusing GNU Make in some sense since it was not > meant to really be a task runner. Keep that in mind. However, dispite > that, I constantly find myself using it as such. -Features include: +| Extension | Description | +|-----------|-----------------------------------------------------| +| .help | Displays all targets with a comment in help format. | +| .assure | Check for the existance of programs on a machine. | -- Enhanced help message generation with support for custom descriptions. +Additional features: + - Automatic description inclusion in help message. - Automatic license inclusion in help message. @@ -130,6 +134,27 @@ Released under the BSD two-clause license, see the LICENSE file for more information. ``` + +## Assure extension + +Often times project uses multiple programs and to ensure that these +programs are already installed before recipes are executed `assure` can +be used. If programs are missing recipes can only partially be executed +leaving project in a potentially broken state. + +```make +MK_ASSURE="python3 ls tree clang" + +include makext.mk + +build-app: .assure + @echo "Building the application..." +``` + +`.assure` prerequisite will loop over the list of programs defined in +`MK_ASSURE` variable and in case one is missing will exit `make` with +status code error 1. This will stop executing the recipe and therefore +not execute anything in target `build-app`. ## Acknowledgement diff --git a/makext.mk b/makext.mk index 06953c509633837da2ca0463b9473a07face129b..b4846c0d437706991f49b231f4e2821a677761d0 100644 --- a/makext.mk +++ b/makext.mk @@ -15,6 +15,11 @@ # # `makext` was written by Mitja Felicijan and is released under the BSD # two-clause license, see the LICENSE file for more information. +# Checks if operating system is Windows and exists with error. +ifeq ($(OS),Windows_NT) +$(error makext does not support Windows operating system) +endif + # Help extension that lists all the targets with descriptions # and adds description and license information if data provided. .PHONY: .help @@ -27,3 +32,18 @@ @grep -vE '^[[:space:]]' $(MAKEFILE_LIST) | grep -E '^.*:.* #' | sed -E 's/(.*):(.*):.*#(.*)/ \2###\3/' | column -t -s '###' ifdef MK_LICENSE @echo "\n$(MK_LICENSE)" | fmt endif + +# Checks `MK_ASSURE` variable if all the programs declared actually +# exist on a machine. If not this exists make with error. +.PHONY: .assure +.assure: +ifndef MK_ASSURE + @echo "Variable MK_ASSURE is not defined. Can not check for programs." +else + @for prog in $(shell echo $(MK_ASSURE)); do \ + if ! which $$prog > /dev/null; then \ + echo "Error: '$$prog' not found on this machine."; \ + exit 1; \ + fi; \ + done +endif