-
Notifications
You must be signed in to change notification settings - Fork 72
/
Makefile
309 lines (274 loc) · 11.9 KB
/
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
PREFIX?=/usr/local
prefix=${PREFIX}
SYSCONFDIR=${prefix}/etc
INSTALL=./scripts/install-sh
MKPATH=${INSTALL} -m 755 -d
INSTALLBIN=${INSTALL} -m 555
INSTALLFILE=${INSTALL} -m 444
INSTALLMAN=${INSTALL} -m 444
INSTALLDOC=${INSTALL} -m 444
INSTALLCONF=${INSTALL} -m 644
PANDOC=./scripts/pandoc-sh
DOC_SRC=markdown_src/vimpager.md markdown_src/vimcat.md
GEN_DOCS=man/vimpager.1 man/vimcat.1 html/vimpager.html html/vimcat.html markdown/vimpager.md markdown/vimcat.md
ANSIESC=autoload/AnsiEsc.vim plugin/AnsiEscPlugin.vim plugin/cecutil.vim
RUNTIME=autoload/vimpager.vim autoload/vimpager_utils.vim autoload/vimcat.vim plugin/vimpager.vim macros/less.vim syntax/perldoc.vim ${ANSIESC}
SRC=vimcat ${RUNTIME}
PROGRAMS=vimpager vimcat
all: ${PROGRAMS:=-vertag-stamp} standalone/vimpager standalone/vimcat docs
# set tag from git or ChangeLog
%-vertag-stamp: %
@echo updating version tag in $<
@tag=`git tag 2>/dev/null | tail -1`; \
[ -z "$$tag" ] && tag=`sed -n '/^[0-9][0-9.]* [0-9-]*:$$/{s/ .*//;p;q;}' ChangeLog_$<.yml`; \
if [ -n "$$tag" ]; then \
sed -e 's/^version_tag=.*/version_tag='"$$tag"'/' $< > $<.work; \
mv -f $<.work $<; \
fi
@chmod +x $<
@touch $@
# other recipes need the version, get it from git describe or ChangeLog
%-version.txt: %
@echo building $@
@git describe >$<-version.txt 2>/dev/null \
|| sed -n '/^[0-9][0-9.]* [0-9-]*:$$/{s/ .*//;p;q;}' ChangeLog_$<.yml >$<-version.txt
standalone/vimpager: vimpager vimpager-version.txt ${SRC:=.uu} inc/* Makefile
@echo building $@
@${MKPATH} ${@D}
@sed \
-e '/^ *\. .*inc\/prologue.sh"$$/{' \
-e 'r inc/prologue.sh' \
-e d \
-e '}' \
-e 's/^\( *\)# EXTRACT BUNDLED SCRIPTS HERE$$/\1extract_bundled_scripts/' \
-e 's|^version=.*|version="'"`cat vimpager-version.txt`"' (standalone, shell=\$$(command -v \$$POSIX_SHELL))"|' \
-e 's!^\( *\)runtime=.*$$!\1runtime='\''\$$tmp/runtime'\''!' \
-e 's!^\( *\)vimcat=.*$$!\1vimcat='\''\$$runtime/bin/vimcat'\''!' \
-e 's!^\( *\)system_vimpagerrc=.*$$!\1system_vimpagerrc='\'\''!' \
-e '/^# INCLUDE BUNDLED SCRIPTS HERE$$/{ q; }' \
vimpager > $@
@cat inc/do_uudecode.sh >> $@
@cat inc/bundled_scripts.sh >> $@
@cat ${SRC:=.uu} >> $@
@sed -n '/^# END OF BUNDLED SCRIPTS$$/,$$p' vimpager >> $@
@chmod +x $@
standalone/vimcat: vimcat autoload/vimcat.vim vimcat-version.txt inc/prologue.sh Makefile
@echo building $@
@${MKPATH} ${@D}
@nlinit=`echo 'nl="'; echo '"'`; eval "$$nlinit"; \
sed -e '1a\'"$$nl"': if 0' \
-e '/^# FIND REAL PARENT DIRECTORY$$/,/^# END OF FIND REAL PARENT DIRECTORY$$/d' \
-e 's/^\( *\)# INSERT VIMCAT_DEBUG PREPARATION HERE$$/\1if [ "$${VIMCAT_DEBUG:-0}" -eq 0 ]; then silent="silent! "; else silent=; fi/' \
-e 's|^version=.*|version="'"`cat vimcat-version.txt`"' (standalone, shell=\$$(command -v \$$POSIX_SHELL))"|' \
-e '/^runtime=.*/d' \
-e '/^ *--cmd "set rtp^=\$$runtime" \\$$/d' \
-e '/call vimcat#Init/i\'"$$nl"'--cmd "$$silent source $$0" \\' \
-e 's/vimcat#\([^ ]*\)(/\1(/g' \
-e '/^ *\. .*inc\/prologue.sh"$$/{' \
-e 'r inc/prologue.sh' \
-e d \
-e '}' \
vimcat > $@
@cp $@ [email protected]
@awk '/^[ ]*(if|for|while)/ { print $$1 }' $@ \
| sed '1!G;h;$$!d' \
| sed -e 's/^/: end/' >> [email protected]
@mv -f [email protected] $@
@echo ': endif' >> $@
@sed -e 's/vimcat#\([^ ]*\)(/\1(/g' autoload/vimcat.vim >> $@
@chmod +x $@
vimcat.uu: vimcat vimcat-version.txt
@echo uuencoding vimcat
@echo 'vimcat_script() {' > $@
@printf "\t(cat <<'EOF') | do_uudecode > bin/vimcat\n" >> $@
@sed \
-e 's|^version=.*|version="'"`cat vimcat-version.txt`"' (bundled, shell=\$$(command -v \$$POSIX_SHELL))"|' \
-e '/^ *\. .*inc\/prologue.sh"$$/{' \
-e 'r inc/prologue.sh' \
-e d \
-e '}' \
vimcat > [email protected]
@uuencode [email protected] vimcat >> $@
@echo EOF >> $@
@echo '}' >> $@
%.uu: %
@echo uuencoding $<
@echo '$<() {' | sed 's|[/.]|_|g' > $@
@printf "\t(cat <<'EOF') | do_uudecode > $<\n" >> $@
@uuencode $< $< >> $@
@echo EOF >> $@
@echo '}' >> $@
uninstall:
rm -f "${prefix}/bin/vimpager"
rm -f "${prefix}/bin/vimcat"
rm -f "${prefix}/share/man/man1/vimpager.1"
rm -f "${prefix}/share/man/man1/vimcat.1"
rm -rf "${prefix}/share/doc/vimpager"
rm -rf "${prefix}/share/vimpager"
@if [ '${PREFIX}' = '/usr' ] && diff /etc/vimpagerrc vimpagerrc >/dev/null 2>&1; then \
echo rm -f /etc/vimpagerrc; \
rm -rf /etc/vimpagerrc; \
elif diff "${SYSCONFDIR}/vimpagerrc" vimpagerrc >/dev/null 2>&1; then \
echo rm -f "${SYSCONFDIR}/vimpagerrc"; \
rm -f "${SYSCONFDIR}/vimpagerrc"; \
fi
install: docs vimpager.configured vimcat.configured
@chmod +x ./install-sh 2>/dev/null || true
@${MKPATH} "${DESTDIR}${prefix}/bin"
${INSTALLBIN} vimpager.configured "${DESTDIR}${prefix}/bin/vimpager"
${INSTALLBIN} vimcat.configured "${DESTDIR}${prefix}/bin/vimcat"
@if [ -d man ]; then \
${MKPATH} "${DESTDIR}${prefix}/share/man/man1"; \
echo ${INSTALLMAN} man/vimpager.1 "${DESTDIR}${prefix}/share/man/man1/vimpager.1"; \
${INSTALLMAN} man/vimpager.1 "${DESTDIR}${prefix}/share/man/man1/vimpager.1"; \
echo ${INSTALLMAN} man/vimcat.1 "${DESTDIR}${prefix}/share/man/man1/vimcat.1"; \
${INSTALLMAN} man/vimcat.1 "${DESTDIR}${prefix}/share/man/man1/vimcat.1"; \
fi
@${MKPATH} "${DESTDIR}${prefix}/share/doc/vimpager"
${INSTALLDOC} markdown_src/vimpager.md "${DESTDIR}${prefix}/share/doc/vimpager/vimpager.md"
${INSTALLDOC} markdown_src/vimcat.md "${DESTDIR}${prefix}/share/doc/vimpager/vimcat.md"
${INSTALLDOC} TODO.yml "${DESTDIR}${prefix}/share/doc/vimpager/TODO.yml"
${INSTALLDOC} DOC_AUTHORS.yml "${DESTDIR}${prefix}/share/doc/vimpager/DOC_AUTHORS.yml"
${INSTALLDOC} ChangeLog_vimpager.yml "${DESTDIR}${prefix}/share/doc/vimpager/ChangeLog_vimpager.yml"
${INSTALLDOC} ChangeLog_vimcat.yml "${DESTDIR}${prefix}/share/doc/vimpager/ChangeLog_vimcat.yml"
${INSTALLDOC} uganda.txt "${DESTDIR}${prefix}/share/doc/vimpager/uganda.txt"
${INSTALLDOC} debian/copyright "${DESTDIR}${prefix}/share/doc/vimpager/copyright"
@if [ -d html ]; then \
${MKPATH} "${DESTDIR}${prefix}/share/doc/vimpager/html"; \
echo ${INSTALLDOC} html/vimpager.html "${DESTDIR}${prefix}/share/doc/vimpager/html/vimpager.html"; \
${INSTALLDOC} html/vimpager.html "${DESTDIR}${prefix}/share/doc/vimpager/html/vimpager.html"; \
echo ${INSTALLDOC} html/vimcat.html "${DESTDIR}${prefix}/share/doc/vimpager/html/vimcat.html"; \
${INSTALLDOC} html/vimcat.html "${DESTDIR}${prefix}/share/doc/vimpager/html/vimcat.html"; \
fi
${MKPATH} "${DESTDIR}${prefix}/share/vimpager"
@for rt_file in ${RUNTIME}; do \
if [ ! -d "`dirname "${DESTDIR}${prefix}/share/vimpager/$$rt_file"`" ]; then \
echo ${MKPATH} "`dirname "${DESTDIR}${prefix}/share/vimpager/$$rt_file"`"; \
${MKPATH} "`dirname "${DESTDIR}${prefix}/share/vimpager/$$rt_file"`"; \
fi; \
echo ${INSTALLFILE} "$$rt_file" "${DESTDIR}${prefix}/share/vimpager/$$rt_file"; \
${INSTALLFILE} "$$rt_file" "${DESTDIR}${prefix}/share/vimpager/$$rt_file"; \
done
@SYSCONFDIR='${DESTDIR}${SYSCONFDIR}'; \
if [ '${PREFIX}' = /usr ]; then \
SYSCONFDIR='${DESTDIR}/etc'; \
fi; \
${MKPATH} "$${SYSCONFDIR}" 2>/dev/null || true; \
echo ${INSTALLCONF} vimpagerrc "$${SYSCONFDIR}/vimpagerrc"; \
${INSTALLCONF} vimpagerrc "$${SYSCONFDIR}/vimpagerrc"
%.configured: % %-version.txt
@echo configuring $<
@POSIX_SHELL="`scripts/find_shell`"; \
if [ '${PREFIX}' = /usr ]; then \
vimpagerrc=/etc/vimpagerrc; \
else \
vimpagerrc='${SYSCONFDIR}/vimpagerrc'; \
fi; \
sed -e '1{ s|.*|#!'"$$POSIX_SHELL"'|; }' \
-e 's|\$$POSIX_SHELL|'"$$POSIX_SHELL|" \
-e '/^ *\. .*inc\/prologue.sh"$$/d' \
-e 's|^version=.*|version="'"`cat $<-version.txt`"' (configured, shell='"$$POSIX_SHELL"')"|' \
-e '/^# FIND REAL PARENT DIRECTORY$$/,/^# END OF FIND REAL PARENT DIRECTORY$$/d' \
-e 's!^\( *\)runtime=.*!\1runtime='\''${PREFIX}/share/vimpager'\''!' \
-e 's!^\( *\)vimcat=.*!\1vimcat='\''${PREFIX}/bin/vimcat'\''!' \
-e 's!^\( *\)system_vimpagerrc=.*!\1system_vimpagerrc='\'"$$vimpagerrc"\''!' \
$< > $@
@chmod +x $@
check-root:
@if [ "`id | cut -d= -f2 | cut -d'(' -f1`" -ne 0 ]; then \
echo '[1;31mERROR[0m: You must be root, try sudo.' >&2; \
echo >&2; \
exit 1; \
fi
build-deb-deps-prereqs: check-root
@-apt-get -qq update
@apt-get -yqq install debhelper devscripts equivs gdebi-core
build-deb-deps-build: build-deb-deps-prereqs clean
@mk-build-deps
@echo y | LANG=C gdebi vimpager-build-deps*.deb
build-deb-deps-clean:
@rm -f vimpager-build-deps*.deb
build-deb-deps: build-deb-deps-build build-deb-deps-clean
build-deb-build: build-deb-deps
@orig_tar_ball=../vimpager_"`sed -ne '/^vimpager (/{ s/^vimpager (\([^)-]*\).*/\1/p; q; }' debian/changelog`".orig.tar; \
rm -f "$$orig_tar_ball".gz; \
tar cf "$$orig_tar_ball" * .travis.yml .mailmap .gitignore; \
gzip "$$orig_tar_ball"
@dpkg-buildpackage -us -uc
build-deb-clean:
@dpkg --purge vimpager-build-deps
@-[ "$${CLEAN_BUILD_DEPS:-1}" -ne 0 ] && apt-get -yqq autoremove
@debian/rules clean
build-deb: build-deb-build build-deb-clean
install-deb: build-deb
@echo y | LANG=C gdebi `ls -1t ../vimpager*deb | head -1`
docs: ${GEN_DOCS} docs.tar.gz Makefile
@rm -f docs-warn-stamp doctoc-warn-stamp
docs.tar.gz: ${GEN_DOCS} ${DOC_SRC}
@rm -f $@
@if [ "`ls -1 $? 2>/dev/null | wc -l`" -eq "`echo $? | wc -w`" ]; then \
echo tar cf docs.tar $?; \
tar cf docs.tar $?; \
echo gzip -9 docs.tar; \
gzip -9 docs.tar; \
fi
# Build markdown with TOCs and gitter.im badge
markdown/%.md: markdown_src/%.md
@if command -v doctoc >/dev/null; then \
echo 'generating $@'; \
${MKPATH} `dirname '$@'` 2>/dev/null || true; \
cp $< [email protected]; \
doctoc --title '### Vimpager User Manual' [email protected] >/dev/null; \
cat markdown_src/gitter-im-badge.md [email protected] > $@; \
rm -f [email protected]; \
else \
if [ ! -r doctoc-warn-stamp ]; then \
echo >&2; \
echo "[1;31mWARNING[0m: doctoc is not available, markdown with Tables Of Contents will not be generated. If you want to generate them, install doctoc with: npm install -g doctoc" >&2; \
echo >&2; \
touch doctoc-warn-stamp; \
fi; \
fi
man/%.1: markdown_src/%.md
@if command -v pandoc >/dev/null; then \
echo 'generating $@'; \
${MKPATH} `dirname '$@'` 2>/dev/null || true; \
${PANDOC} -s -f markdown_github $< -o $@; \
else \
if [ ! -r docs-warn-stamp ]; then \
echo >&2; \
echo "[1;31mWARNING[0m: pandoc is not available, man pages and html will not be generated. If you want to install the man pages and html, install pandoc and re-run make." >&2; \
echo >&2; \
touch docs-warn-stamp; \
fi; \
fi
.SECONDARY: vimpager.md.work vimcat.md.work
# transform markdown links to html links
%.md.work: markdown_src/%.md
@sed -e 's|\(\[[^]]*\]\)(markdown/\([^.]*\)\.md)|\1(\2.html)|g' < $< > $@
html/%.html: %.md.work
@if command -v pandoc >/dev/null; then \
echo 'generating $@'; \
${MKPATH} `dirname '$@'` 2>/dev/null || true; \
${PANDOC} -s --toc -f markdown_github $< -o $@; \
rm -f $<; \
else \
if [ ! -r docs-warn-stamp ]; then \
echo >&2; \
echo "[1;31mWARNING[0m: pandoc is not available, man pages and html will not be generated. If you want to install the man pages and html, install pandoc and re-run make." >&2; \
echo >&2; \
touch docs-warn-stamp; \
fi; \
fi
realclean distclean clean:
rm -rf *.work */*.work *-stamp *-version.txt *.deb *.tar.gz *.configured *.uu */*.uu man html standalone */with_meta_*
test: standalone/vimpager standalone/vimcat
@if command -v bats >/dev/null; then \
bats test; \
else \
echo "[1;31mWARNING[0m: bats is not available, tests will not be run. If you want to run tests, install bats from https://github.com/sstephenson/bats.git or your distribution and rerun \`make test\`." >&2; \
echo >&2; \
fi
.PHONY: all install uninstall docs realclean distclean clean test check-root build-deb-deps-prereqs build-deb-deps-build build-deb-deps-clean build-deb-deps build-deb-clean build-deb install-deb
# vim: sw=4