summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorChris Evich <cevich@redhat.com>2021-04-08 08:55:56 -0400
committerChris Evich <cevich@redhat.com>2021-04-12 10:19:51 -0400
commit0e83851f080f67a7008f43136e46195a0a658819 (patch)
treea25c828d5f179399c78390ff7d4bb37e59afa737 /Makefile
parent5a703bbf7a73ef4ab3ee99db885c206abf773a49 (diff)
downloadpodman-0e83851f080f67a7008f43136e46195a0a658819.tar.gz
podman-0e83851f080f67a7008f43136e46195a0a658819.tar.bz2
podman-0e83851f080f67a7008f43136e46195a0a658819.zip
Simplify Makefile help target
An in-line Python script, while flexible, is arguably more complex and less stable than the long-lived `grep`, `awk`, and `printf`. Make use of these simple tools to display a column-aligned table of target and description help output. Also, the first target that appears in a Makefile is considered the default (when no target is specified on the command-line). However, despite it's name, the `default` target was not listed first. Fix this, and redefine "default" target to "all" as intended, instead of "help". Lastly, add a small workaround for a vim syntax-hilighting bug. Signed-off-by: Chris Evich <cevich@redhat.com>
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile43
1 files changed, 18 insertions, 25 deletions
diff --git a/Makefile b/Makefile
index 0511a17f2..0cbe7eb09 100644
--- a/Makefile
+++ b/Makefile
@@ -118,38 +118,29 @@ CROSS_BUILD_TARGETS := \
bin/podman.cross.linux.mips64 \
bin/podman.cross.linux.mips64le
+.PHONY: default
+default: all
+
.PHONY: all
all: binaries docs
-.PHONY: default
-default: help
-
-define PRINT_HELP_PYSCRIPT
-import re, sys
-
-print("Usage: make <target>")
-cmds = {}
-for line in sys.stdin:
- match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line)
- if match:
- target, help = match.groups()
- cmds.update({target: help})
-for cmd in sorted(cmds):
- print(" * '%s' - %s" % (cmd, cmds[cmd]))
-endef
-export PRINT_HELP_PYSCRIPT
-
# Dereference variable $(1), return value if non-empty, otherwise raise an error.
err_if_empty = $(if $(strip $($(1))),$(strip $($(1))),$(error Required variable $(1) value is undefined, whitespace, or empty))
+# Extract text following double-# for targets, as their description for
+# the `help` target. Otherwise These simple-substitutions are resolved
+# at reference-time (due to `=` and not `=:`).
+_HLP_TGTS_RX = '^[[:print:]]+:.*?\#\# .*$$'
+_HLP_TGTS_CMD = grep -E $(_HLP_TGTS_RX) $(MAKEFILE_LIST)
+_HLP_TGTS_LEN = $(shell $(_HLP_TGTS_CMD) | cut -d : -f 1 | wc -L)
+_HLPFMT = "%-$(_HLP_TGTS_LEN)s %s\n"
.PHONY: help
-ifneq (, ${PYTHON})
-help:
- @$(PYTHON) -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
-else
-help:
- $(error python required for 'make help', executable not found)
-endif
+help: ## (Default) Print listing of key targets with their descriptions
+ @printf $(_HLPFMT) "Target:" "Description:"
+ @printf $(_HLPFMT) "--------------" "--------------------"
+ @$(_HLP_TGTS_CMD) | sort | \
+ awk 'BEGIN {FS = ":(.*)?## "}; \
+ {printf $(_HLPFMT), $$1, $$2}'
.gopathok:
ifeq ("$(wildcard $(GOPKGDIR))","")
@@ -469,6 +460,8 @@ changelog: ## Generate changelog
$(shell cat $(TMPFILE) >> changelog.txt)
$(shell rm $(TMPFILE))
+# Workaround vim syntax highlighting bug: "
+
.PHONY: install
install: .gopathok install.bin install.remote install.man install.cni install.systemd ## Install binaries to system locations