summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2024-05-12 03:25:48 +0200
committerMitja Felicijan <mitja.felicijan@gmail.com>2024-05-12 03:25:48 +0200
commit2871b670f47b7d04d18abae56ce23ffd38a32249 (patch)
treee434a1399de8b8eb3c3f6459827ad183e38bfd0e
parent45e996e7c954217efcbc9d07187a070b14e19d53 (diff)
downloadmakext-2871b670f47b7d04d18abae56ce23ffd38a32249.tar.gz
Added .assure extension
-rw-r--r--Makefile4
-rw-r--r--README.md29
-rw-r--r--makext.mk20
3 files changed, 50 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 37470e7..2869487 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 c6aca6b..5f8fd86 100644
--- a/README.md
+++ b/README.md
@@ -11,9 +11,13 @@ tasks.
> 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. |
+
+Additional features:
-- Enhanced help message generation with support for custom descriptions.
- Automatic description inclusion in help message.
- Automatic license inclusion in help message.
@@ -131,6 +135,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
- https://stackoverflow.com/a/59087509
diff --git a/makext.mk b/makext.mk
index 06953c5..b4846c0 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 @@ endif
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