-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile.helpers
73 lines (58 loc) · 1.96 KB
/
Makefile.helpers
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#
# Helpers - stuff that's shared between make files
# Written Originally by https://github.com/cloudposse/build-harness/blob/master/Makefile.helpers, Apache License 2.0
# https://github.com/cloudposse/build-harness/blob/master/LICENSE
#
EDITOR ?= vim
SHELL = /bin/bash
DEFAULT_HELP_TARGET ?= help/short
HELP_FILTER ?= .*
green = $(shell echo -e '\x1b[32;01m$1\x1b[0m')
yellow = $(shell echo -e '\x1b[33;01m$1\x1b[0m')
red = $(shell echo -e '\x1b[33;31m$1\x1b[0m')
# Ensures that a variable is defined and non-empty
define assert-set
@$(if $($(1)),,$(error $(1) not defined in $(@)))
endef
# Ensures that a variable is undefined
define assert-unset
@$(if $($1),$(error $(1) should not be defined in $(@)),)
endef
warn:
@printf "\e[33m🚨 make is deprecated, all automation excepting install-host for debugging have been moved to mage. Future changes should be made to mage.\e[0m\n"
test/assert-set:
$(call assert-set,PATH)
@echo assert-set PASS
test/assert-unset:
$(call assert-unset,JKAHSDKJAHSDJKHASKD)
@echo assert-unset PASS
test/assert: test/assert-set test/assert-unset
@exit 0
default:: warn $(DEFAULT_HELP_TARGET)
@exit 0
## Help screen
help: warn
@printf "Available targets:\n\n"
@$(SELF) -s help/generate | grep -E "\w($(HELP_FILTER))"
## Display help for all targets
help/all: warn
@printf "Available targets:\n\n"
@$(SELF) -s help/generate
## This help short screen
help/short: warn
@printf "Available targets:\n\n"
@$(SELF) -s help/generate MAKEFILE_LIST="Makefile $(BUILD_HARNESS_PATH)/Makefile.helpers"
# Generate help output from MAKEFILE_LIST
help/generate:
@awk '/^[-a-zA-Z_0-9%:\\\.\/]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = $$1; \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
gsub("\\\\", "", helpCommand); \
gsub(":+$$", "", helpCommand); \
printf " \x1b[32;01m%-35s\x1b[0m %s\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST) | sort -u
@printf "\n"