Makefile refactoring and cleanup.
[pwl6.git] / rules / programs.mk
index d706d3f..bd5b850 100644 (file)
@@ -9,5 +9,24 @@ UNZIP = unzip $(UNZIPFLAGS)
 ZIP = zip $(ZIPFLAGS)
 
 ifneq ($(OS),Windows_NT)
-       WINE ?= wine
+WINE ?= wine
 endif
+
+find-files = $(shell find $1 -type f $2 -print $3)
+
+rmdir-r = [ ! -e $1 ] || find -d $1 -type d -delete
+
+# Use to find the best command to execute out of a series of possible
+# equivalent ones, or provide a fallback. If a second argument is
+# supplied it is used as the fallback, otherwise the first element of
+# the checked executables is used. e.g.
+#     PYLINTER := $(call command-v,flake8 pyflakes,python -mpy_compile)
+# will pick flake8 if it's installed, or pyflakes if it isn't,
+# or python -mpy_compile (a syntax check) if neither is
+# installed.
+command-v = $(firstword $(shell command -v $1) $2 $1)
+
+# Use in place of 'mkdir -p' to avoid littering every other line of
+# output with a redundant mkdir call; the downside is that it can't be
+# silenced itself.
+MKDIR = @$(SHELL) -c '[ -d "$$0" ] || echo mkdir -p "$$0" && mkdir -p "$$0"'