forked from cloudposse/build-harness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.helpers
68 lines (54 loc) · 1.62 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
#
# Helpers - stuff that's shared between make files
#
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
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:: $(DEFAULT_HELP_TARGET)
@exit 0
## Help screen
help:
@printf "Available targets:\n\n"
@$(SELF) -s help/generate | grep -E "\w($(HELP_FILTER))"
## Display help for all targets
help/all:
@printf "Available targets:\n\n"
@$(SELF) -s help/generate
## This help short screen
help/short:
@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"