-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template-Makefile
175 lines (146 loc) · 5.32 KB
/
template-Makefile
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/make -f
# Install/Uninstall make script for `<<TEMPLATE_PROJECT>>` Vim plugin
# Copyright (C) <<TEMPLATE_DATE>> <<TEMPLATE_AUTHOR>>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Lambda-like functions
#
path_append = $(strip $(1))$(strip $(__PATH_SEPARATOR__))$(strip $(2))
#
# Make variables to satisfy conventions
#
NAME = <<TEMPLATE_PROJECT>>
VERSION = <<TEMPLATE_VERSION>>
PKG_NAME = $(NAME)-$(VERSION)
#
# Make variables that readers &/or maintainers may wish to modify
#
PLUGIN_DIRECTORY = <<TEMPLATE_VIM>>/plugin
DOCUMENTATION_DIRECTORY = <<TEMPLATE_VIM>>/doc
#
# Make variables set upon run-time
#
## Obtain directory path that this Makefile lives in
## Note ':=' is to avoid late binding that '=' entails
ROOT_DIRECTORY_PATH := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
ROOT_DIRECTORY_NAME := $(notdir $(patsubst %/,%,$(ROOT_DIRECTORY_PATH)))
## Detect Operating System
ifeq '$(findstring :,$(PATH))' ';'
__OS__ := Windows
else
__OS__ := $(shell uname 2>/dev/null || echo 'Unknown')
__OS__ := $(patsubst CYGWIN%,Cygwin,$(__OS__))
__OS__ := $(patsubst MSYS%,MSYS,$(__OS__))
__OS__ := $(patsubst MINGW%,MSYS,$(__OS__))
endif
#
# Override variables via optional configuration file
#
CONFIG_PATH := $(call path_append, $(ROOT_DIRECTORY_PATH), .config-make)
ifneq ("$(wildcard $(CONFIG_PATH))", "")
include $(CONFIG_PATH)
endif
#
# Make options/commands
#
.PHONY: clean install uninstall upgrade git-pull list plugin-link plugin-unlink documentation-link documentation-unlink documentation-update
.SILENT: config clean debug list plugin-link plugin-unlink documentation-link documentation-unlink documentation-update
.ONESHELL: install uninstall
clean: SHELL := /bin/bash
clean: ## Removes configuration file
[[ -f "$(CONFIG)" ]] && {
rm -v "$(CONFIG)"
}
config: SHELL := /bin/bash
config: ## Writes configuration file
tee "$(CONFIG)" 1>/dev/null <<EOF
PLUGIN_DIRECTORY = $(PLUGIN_DIRECTORY)
DOCUMENTATION_DIRECTORY = $(DOCUMENTATION_DIRECTORY)
__OS__ = $(__OS__)
# vim: filetype=make
EOF
install: ## Runs targets -> plugin-link documentation-link documentation-update
install: | plugin-link documentation-link documentation-update
uninstall: ## Runs targets -> plugin-unlink documentation-unlink documentation-update
uninstall: | plugin-unlink documentation-unlink documentation-update
upgrade: ## Runs targets -> uninstall git-pull install
upgrade: | uninstall git-pull install
git-pull: SHELL := /bin/bash
git-pull: ## Pulls updates from default upstream Git remote
cd "$(ROOT_DIRECTORY_PATH)"
git pull
[[ -f "$(ROOT_DIRECTORY_PATH)/.gitmodules" ]] && {
git submodule update --init --merge --recursive
}
plugin-link: SHELL := /bin/bash
plugin-link: ## Symbolically links Vim plugin
if [[ -L "$(PLUGIN_DIRECTORY)/$(ROOT_DIRECTORY_NAME)" ]]; then
printf ' Link found for plugin -> %s\n' "$(ROOT_DIRECTORY_NAME)"
else
ln -sv "$(ROOT_DIRECTORY_PATH)" "$(PLUGIN_DIRECTORY)/$(ROOT_DIRECTORY_NAME)"
fi
plugin-unlink: SHELL := /bin/bash
plugin-unlink: ## Removes symbolic links for Vim plugin
if [[ -L "$(PLUGIN_DIRECTORY)/$(ROOT_DIRECTORY_NAME)" ]]; then
rm -v "$(PLUGIN_DIRECTORY)/$(ROOT_DIRECTORY_NAME)"
else
printf ' No link found for plugin -> %s\n' "$(ROOT_DIRECTORY_NAME)"
fi
documentation-link: SHELL := /bin/bash
documentation-link: ## Symbolically links Vim documentation
if [[ -d "$(ROOT_DIRECTORY_PATH)/doc" ]]; then
for _path in "$(ROOT_DIRECTORY_PATH)/doc/"*.txt; do
if [[ -f "$${_path}" ]] && ! [[ -L "$(DOCUMENTATION_DIRECTORY)/$${_path##*/}" ]]; then
ln -sv "$${_path}" "$(DOCUMENTATION_DIRECTORY)/$${_path##*/}"
else
printf ' Link found for documentation -> %s\n' "$${_path##*/}"
fi
done
fi
documentation-unlink: SHELL := /bin/bash
documentation-unlink: ## Removes symbolic links for Vim documentation
if [[ -d "$(ROOT_DIRECTORY_PATH)/doc" ]]; then
for _path in "$(ROOT_DIRECTORY_PATH)/doc/"*.txt; do
if [[ -L "$(DOCUMENTATION_DIRECTORY)/$${_path##*/}" ]]; then
rm -v "$(DOCUMENTATION_DIRECTORY)/$${_path##*/}"
else
printf ' No link found for documentation -> %s\n' "$${_path##*/}"
fi
done
fi
documentation-update: SHELL := /bin/bash
documentation-update: ## Updates Vim documentation tag file
vim -c ":helptags $(DOCUMENTATION_DIRECTORY)" -c ':q'
list: SHELL := /bin/bash
list: ## Lists available make commands
gawk 'BEGIN {
delete matched_lines
}
{
if ($$0 ~ "^[a-z0-9A-Z-]{1,32}: [#]{1,2}[[:print:]]*$$") {
matched_lines[length(matched_lines)] = $$0
}
}
END {
print "## Make Commands for $(NAME) ##\n"
for (k in matched_lines) {
split(matched_lines[k], line_components, ":")
gsub(" ## ", " ", line_components[2])
print line_components[1]
print line_components[2]
if ((k + 1) != length(matched_lines)) {
print
}
}
}' "$(ROOT_DIRECTORY_PATH)/Makefile"