-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
227 lines (179 loc) · 6.2 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
# Project parameters.
export SRCDIR := ./src
export TESTDIR := ./test
export DOCSDIR := ./docs
export SCRIPTDIR := ./script
# Installation parameters.
export prefix ?= /usr/local
export exec_prefix ?= $(prefix)
export bindir ?= $(exec_prefix)/bin
export libexecdir ?= $(exec_prefix)/libexec
export libdir ?= $(prefix)/lib
export datarootdir ?= $(prefix)/share
export mandir ?= $(datarootdir)/man
# Make parameters.
SHELL := /usr/bin/env bash
########################################################################
# BUILD
########################################################################
.PHONY: build
build: man
# Generate ROFF format man pages.
# from: $(SRCDIR)/man/*.ronn
# to: $(SRCDIR)/man/*
.PHONY: man
man: $(patsubst %.ronn,%,$(wildcard $(SRCDIR)/man/*.ronn)) ;
$(SRCDIR)/man/%: $(SRCDIR)/man/%.ronn
ronn --warnings --roff '$<'
# Delete files generated by `build'.
.PHONY: clean
clean:
-rm '$(patsubst %.ronn,%,$(wildcard $(SRCDIR)/man/*.ronn))'
########################################################################
# CHECK
########################################################################
.PHONY: check
check:
bats '$(TESTDIR)'
########################################################################
# DOCS
########################################################################
.PHONY: docs
docs: docs-man docs-img
# Generate HTML format man pages.
# from: $(SRCDIR)/man/*.ronn
# to: $(DOCSDIR)/man/*.html
.PHONY: docs-man
docs-man: $(patsubst $(SRCDIR)/man/%.ronn,\
$(DOCSDIR)/man/%.html,\
$(wildcard $(SRCDIR)/man/*.ronn)) ;
$(DOCSDIR)/man/%.html: $(SRCDIR)/man/%.ronn
ronn --warnings --html '$<'
mv '$(<:.ronn=.html)' '$(DOCSDIR)/man'
# Rasterise HTML pages and save them in PNG format.
# from: $(DOCSDIR)/src/*.html
# to: $(DOCSDIR)/img/*.png
.PHONY: docs-img
docs-img: $(patsubst $(DOCSDIR)/src/%.html,\
$(DOCSDIR)/img/%.png,\
$(wildcard $(DOCSDIR)/src/*.html)) ;
$(DOCSDIR)/img/%.png: $(DOCSDIR)/src/%.html
phantomjs '$(SCRIPTDIR)/capture.js' '$<' '$@'
# Delete files generated by `docs'.
.PHONY: docs-clean
docs-clean:
# Delete generated HTML format man pages (docs-man).
-rm '$(patsubst $(SRCDIR)/man/%.ronn,$(DOCSDIR)/man/%.html,\
$(wildcard $(SRCDIR)/man/*.ronn))'
# Delete generated PNG images (docs-img).
-rm '$(patsubst $(DOCSDIR)/src/%.html,$(DOCSDIR)/img/%.png,\
$(wildcard $(DOCSDIR)/src/*.html))'
########################################################################
# INSTALL
########################################################################
.PHONY: install
install: install-params install-files install-update
# Display parameters used.
.PHONY: install-params
install-params:
@echo '-> Parameters'; \
vars=(DESTDIR prefix exec_prefix bindir libexecdir libdir datarootdir \
mandir); \
for var in "$${vars[@]}"; do \
printf ' %-11s = %s\n' "$${var}" "$${!var}"; \
done; \
echo
# Install program files.
.PHONY: install-files
install-files:
@echo '-> Installing files'
# Install executables.
# from: $(SRCDIR)/bin/*
# to : $(DESTDIR)$(bindir)/*
@for src in '$(SRCDIR)/bin'/*; do \
src_file="$$(basename "$${src}")"; \
dst='$(DESTDIR)$(bindir)/'"$${src_file}"; \
echo " $${dst}"; \
install -Dm755 "$${src}" "$${dst}"; \
done
# Install internal executables (recursively).
# from: $(SRCDIR)/libexec/*
# to : $(DESTDIR)$(libexecdir)/*
@src_base='$(SRCDIR)/libexec'; \
IFS=$$'\n'; \
for src in $$(find "$${src_base}" -type f); do \
dst='$(DESTDIR)$(libexecdir)'"$${src#$${src_base}}"; \
echo " $${dst}"; \
install -Dm755 "$${src}" "$${dst}"; \
done
# Install libraries (recursively).
# from: $(SRCDIR)/lib/*
# to: $(DESTDIR)$(libdir)/*
@src_base='$(SRCDIR)/lib'; \
IFS=$$'\n'; \
for src in $$(find "$${src_base}" -type f); do \
dst='$(DESTDIR)$(libdir)'"$${src#$${src_base}}"; \
echo " $${dst}"; \
install -Dm644 "$${src}" "$${dst}"; \
done
# Install man pages.
# from: ./$(SRCDIR)/man/*.[0-9]
# to: $(DESTDIR)$(mandir)/*.[0-9]
@for src in '$(SRCDIR)/man'/*.[0-9]; do \
src_file="$$(basename "$${src}")"; \
dst='$(DESTDIR)$(mandir)/man'"$${src_file: -1}/$${src_file}"; \
echo " $${dst}"; \
install -Dm644 "$${src}" "$${dst}"; \
done
# Update installed files.
.PHONY: install-update
install-update:
@echo '-> Updating files' \
# Update launcher paths.
@file='$(DESTDIR)$(bindir)/varrick'; \
echo " $$file"; \
sed -r -e '/^_d8e1_BIN_DIR=".*"$$/ d' \
-e 's;^(export _d8e1_LIB_DIR)=".*"$$;\1='\''$(libdir)/varrick'\'';' \
-e 's;^(export _d8e1_LIBEXEC_DIR)=".*"$$;\1='\''$(libexecdir)/varrick'\'';' \
-i "$$file"
########################################################################
# HELP
########################################################################
define HELP_TEXT
TARGETS:
For packagers:
build build application
install install application
check run test suite
clean delete generated files
help display this help
For developers:
man generate ROFF format man pages (build-time)
docs generate HTML format man pages and images (after editing man pages)
ENVIRONMENT:
For packagers:
The following variables customise installation. Their meaning is described
in the GNU Make manual. [1] [2]
DESTDIR = /
prefix = /usr/local
exec_prefix = $$(prefix)
bindir = $$(exec_prefix)/bin
libexecdir = $$(exec_prefix)/libexec
libdir = $$(prefix)/lib
datarootdir = $$(prefix)/share
mandir = $$(datarootdir)/man
EXAMPLES:
Build, and then install execuatables in `/usr/bin' and `/usr/lib/varrick',
libraries in `/usr/lib/varrick' and man pages in `/usr/share/man'.
$$ make build
$$ make prefix='/usr' \
libexecdir='/usr/lib' \
install
REFERENCES:
[1]: http://www.gnu.org/software/make/manual/make.html#Directory-Variables
[2]: http://www.gnu.org/software/make/manual/make.html#DESTDIR
endef
export HELP_TEXT
.PHONY: help
help:
@echo "$${HELP_TEXT}"