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>
This commit is contained in:
parent
5a703bbf7a
commit
0e83851f08
43
Makefile
43
Makefile
|
@ -118,38 +118,29 @@ CROSS_BUILD_TARGETS := \
|
||||||
bin/podman.cross.linux.mips64 \
|
bin/podman.cross.linux.mips64 \
|
||||||
bin/podman.cross.linux.mips64le
|
bin/podman.cross.linux.mips64le
|
||||||
|
|
||||||
|
.PHONY: default
|
||||||
|
default: all
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: binaries docs
|
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.
|
# 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))
|
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
|
.PHONY: help
|
||||||
ifneq (, ${PYTHON})
|
help: ## (Default) Print listing of key targets with their descriptions
|
||||||
help:
|
@printf $(_HLPFMT) "Target:" "Description:"
|
||||||
@$(PYTHON) -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
|
@printf $(_HLPFMT) "--------------" "--------------------"
|
||||||
else
|
@$(_HLP_TGTS_CMD) | sort | \
|
||||||
help:
|
awk 'BEGIN {FS = ":(.*)?## "}; \
|
||||||
$(error python required for 'make help', executable not found)
|
{printf $(_HLPFMT), $$1, $$2}'
|
||||||
endif
|
|
||||||
|
|
||||||
.gopathok:
|
.gopathok:
|
||||||
ifeq ("$(wildcard $(GOPKGDIR))","")
|
ifeq ("$(wildcard $(GOPKGDIR))","")
|
||||||
|
@ -469,6 +460,8 @@ changelog: ## Generate changelog
|
||||||
$(shell cat $(TMPFILE) >> changelog.txt)
|
$(shell cat $(TMPFILE) >> changelog.txt)
|
||||||
$(shell rm $(TMPFILE))
|
$(shell rm $(TMPFILE))
|
||||||
|
|
||||||
|
# Workaround vim syntax highlighting bug: "
|
||||||
|
|
||||||
.PHONY: install
|
.PHONY: install
|
||||||
install: .gopathok install.bin install.remote install.man install.cni install.systemd ## Install binaries to system locations
|
install: .gopathok install.bin install.remote install.man install.cni install.systemd ## Install binaries to system locations
|
||||||
|
|
||||||
|
|
|
@ -14,12 +14,20 @@ valid_args() {
|
||||||
cut -d '*' -f 1
|
cut -d '*' -f 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# `git describe` does not reliably produce a useful version number.
|
# `git describe` will never produce a useful version number under all
|
||||||
|
# branches. This is because the podman release process (see `RELEASE_PROCESS.md`)
|
||||||
|
# tags release versions only on release-branches (i.e. never on master).
|
||||||
|
# Scraping the version number directly from the source, is the only way
|
||||||
|
# to reliably obtain the number from all the various contexts supported by
|
||||||
|
# the `Makefile`.
|
||||||
scrape_version() {
|
scrape_version() {
|
||||||
local versionfile='version/version.go'
|
local v
|
||||||
local version_line=$(grep -m 1 'var Version =' $versionfile)
|
# extract the value of 'var Version'
|
||||||
local version_string=$(cut -d '"' -f 2 <<<"$version_line")
|
v=$(sed -ne 's/^var\s\+Version\s\+=\s.*("\(.*\)").*/\1/p' <version/version.go)
|
||||||
echo "$version_string" | tr -d '[:space:]'
|
# If it's empty, something has changed in version.go, that would be bad!
|
||||||
|
test -n "$v"
|
||||||
|
# Value consumed literally, must not have any embedded newlines
|
||||||
|
echo -n "$v"
|
||||||
}
|
}
|
||||||
|
|
||||||
unset OUTPUT
|
unset OUTPUT
|
||||||
|
|
Loading…
Reference in New Issue