-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
187 lines (158 loc) · 4.41 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
VERSION = 0.14
COPYRIGHT = 2018-2020 kitsunyan
DIST_MODE = false
MAN_PAGES = \
doc/pakku.8 \
doc/pakku.conf.5
TARGETS = \
completion/bash \
completion/zsh \
lib/tools \
src/pakku \
${MAN_PAGES}
TARGETS_NODIST = \
${MAN_PAGES:=.in}
DIST = \
COPYING \
Makefile \
pakku.conf \
completion/bash.patch \
completion/bash-git.patch \
completion/make.sh \
completion/zsh.patch \
completion/zsh-git.patch \
doc/asciidoc.conf \
${MAN_PAGES:=.txt} \
$(shell find src lib -type f -name '*.nim')
EXTRA_DIST = \
${MAN_PAGES:=.in}
DESTDIR =
PREFIX = /usr/local
BINDIR = ${PREFIX}/bin
PKGLIBDIR = ${PREFIX}/lib/pakku
BASHCOMPLETIONSDIR = ${PREFIX}/share/bash-completion/completions
ZSHCOMPLETIONSDIR = ${PREFIX}/share/zsh/site-functions
MANDIR = ${PREFIX}/share/man
LOCALSTATEDIR = /var
SYSCONFDIR = /etc
ifneq ($(wildcard .git),)
RVERSION = $(shell (git describe --tags 2> /dev/null || echo v${VERSION}) | \
tail -c +2 | head -1)
else
RVERSION = ${VERSION}
endif
NIM_TARGET = release
NIM_OPTIMIZE = size
NIM_CACHE_DIR = nimcache
NIM_OPTIONS = \
--putenv:'PROG_VERSION'="${RVERSION}" \
--putenv:'PROG_COPYRIGHT'="${COPYRIGHT}" \
--putenv:'PROG_PKGLIBDIR'="${PKGLIBDIR}" \
--putenv:'PROG_LOCALSTATEDIR'="${LOCALSTATEDIR}" \
--putenv:'PROG_SYSCONFDIR'="${SYSCONFDIR}" \
-d:'${NIM_TARGET}' \
--opt:'${NIM_OPTIMIZE}' \
--hint'[Conf]':off \
--hint'[Processing]':off \
--hint'[Link]':off \
--hint'[SuccessX]':off
ASCIIDOC_OPTIONS = \
-f doc/asciidoc.conf \
-a manmanual='Pakku Manual' \
-a mansource='Pakku' \
-a manversion="${RVERSION}"
.PHONY: all clean install uninstall distcheck
all: \
${TARGETS} \
${TARGETS_NODIST}
completion/bash: \
completion/make.sh \
completion/bash.patch \
completion/bash-git.patch
@echo "GEN: $@"
@(cd completion && ./make.sh 'bash')
completion/zsh: \
completion/make.sh \
completion/zsh.patch \
completion/zsh-git.patch
@echo "GEN: $@"
@(cd completion && ./make.sh 'zsh')
${MAN_PAGES:=.in}: ${MAN_PAGES:=.txt}
@echo "GEN: $@"
@a2x \
--doctype manpage \
--format manpage \
--asciidoc-opts="${ASCIIDOC_OPTIONS}" \
"${@:.in=}.txt"
@mv "${@:.in=}" "$@"
${MAN_PAGES}: ${MAN_PAGES:=.in}
@echo "GEN: $@"
@sed \
-e 's,{sysconfdir},${SYSCONFDIR},' \
-e '/^[\.'"'"']\\"/d' \
< "${@:=.in}" > "$@"
lib/tools: lib/tools.nim $(shell find lib -name \*.nim)
@echo "NIM: $@"
@nim c ${NIM_OPTIONS} \
--nimcache:"${NIM_CACHE_DIR}/tools" \
-o:"$@" "$<"
src/pakku: src/main.nim $(shell find src -name \*.nim)
@echo "NIM: $@"
@nim c ${NIM_OPTIONS} \
--nimcache:"${NIM_CACHE_DIR}/main" \
-o:"$@" "$<"
clean:
@rm -rfv nimcache
@rm -rfv ${TARGETS}
ifneq (${DIST_MODE},true)
@rm -rfv ${TARGETS_NODIST}
endif
define install
@echo 'INSTALL: $3'
@install -Dm$1 $2 '${DESTDIR}$3'
endef
define uninstall
@echo 'UNINSTALL: $1/$2'
@rm '${DESTDIR}$1/$2'
@rmdir -p '${DESTDIR}$1' 2> /dev/null || true
endef
install:
$(call install,644,'completion/bash','${BASHCOMPLETIONSDIR}/pakku')
$(call install,644,'completion/zsh','${ZSHCOMPLETIONSDIR}/_pakku')
$(call install,644,'doc/pakku.8','${MANDIR}/man8/pakku.8')
$(call install,644,'doc/pakku.conf.5','${MANDIR}/man5/pakku.conf.5')
$(call install,755,'lib/tools','${PKGLIBDIR}/tools')
@echo 'INSTALL: ${PKGLIBDIR}/bisect'
@ln -s tools ${DESTDIR}${PKGLIBDIR}/bisect
@echo 'INSTALL: ${PKGLIBDIR}/install'
@ln -s tools ${DESTDIR}${PKGLIBDIR}/install
$(call install,755,'src/pakku','${BINDIR}/pakku')
$(call install,644,'pakku.conf','${SYSCONFDIR}/pakku.conf')
uninstall:
$(call uninstall,'${BASHCOMPLETIONSDIR}','pakku')
$(call uninstall,'${ZSHCOMPLETIONSDIR}','_pakku')
$(call uninstall,'${MANDIR}/man8','pakku.8')
$(call uninstall,'${MANDIR}/man5','pakku.conf.5')
$(call uninstall,'${PKGLIBDIR}','tools')
$(call uninstall,'${PKGLIBDIR}','bisect')
$(call uninstall,'${PKGLIBDIR}','install')
$(call uninstall,'${BINDIR}','pakku')
$(call uninstall,'${SYSCONFDIR}','pakku.conf')
distcheck:
@rm -rf 'pakku-${RVERSION}'
@mkdir 'pakku-${RVERSION}'
@for f in ${DIST}; do cp -d --parents $$f 'pakku-${RVERSION}'; done
@sed -i 'pakku-${RVERSION}/Makefile' \
-e 's/^VERSION =.*/VERSION = ${RVERSION}/' \
-e 's/^DIST_MODE =.*/DIST_MODE = true/'
@(cd 'pakku-${RVERSION}' && \
make && \
mkdir 'destdir' && \
make DESTDIR="`pwd`/destdir" install && \
make DESTDIR="`pwd`/destdir" uninstall && \
[ ! -d 'destdir' ] && \
make clean)
@tar -cJvf 'pakku-${RVERSION}.tar.xz' \
${DIST:%='pakku-${RVERSION}'/%} \
${EXTRA_DIST:%='pakku-${RVERSION}'/%}
@rm -rf 'pakku-${RVERSION}'