aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 8fee4825da2d3a4464deef5c1b4f24e920ed3a62 (plain) (blame)
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
VERSION = 0.1
COPYRIGHT = 2018 kitsunyan
DIST_MODE = false

MAN_PAGES = \
	doc/pakku.8 \
	doc/pakku.conf.5

TARGETS =  \
	completion/bash \
	lib/bisect \
	src/pakku \
	${MAN_PAGES}

TARGETS_NODIST = \
	${MAN_PAGES:=.in}

DIST = \
	COPYING \
	Makefile \
	pakku.conf \
	completion/bash.in \
	completion/make.sh \
	doc/asciidoc.conf \
	${MAN_PAGES:=.txt} \
	lib/*.nim \
	src/*.nim \
	src/feature/*.nim \
	src/wrapper/*.nim

EXTRA_DIST = \
	${MAN_PAGES:=.in}

DESTDIR =
PREFIX = /usr/local

BINDIR = ${PREFIX}/bin
PKGLIBDIR = ${PREFIX}/lib/pakku
COMPLETIONSDIR = ${PREFIX}/share/bash-completion/completions
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 distcheck

all: \
	${TARGETS} \
	${TARGETS_NODIST}

completion/bash: completion/bash.in
	@echo "GEN: $@"
	@(cd completion && ./make.sh)

${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},' \
	< "${@:=.in}" > "$@"

lib/bisect: lib/bisect.nim
	@echo "NIM: $@"
	@nim c ${NIM_OPTIONS} \
	--nimcache:"${NIM_CACHE_DIR}/bisect" \
	-o:"$@" "$<"

src/pakku: src/main.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','${COMPLETIONSDIR}/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/bisect','${PKGLIBDIR}/bisect')
	$(call install,755,'src/pakku','${BINDIR}/pakku')
	$(call install,644,'pakku.conf','${SYSCONFDIR}/pakku.conf')

uninstall:
	$(call uninstall,'${COMPLETIONSDIR}','pakku')
	$(call uninstall,'${MANDIR}/man8','pakku.8')
	$(call uninstall,'${MANDIR}/man5','pakku.conf.5')
	$(call uninstall,'${PKGLIBDIR}','bisect')
	$(call uninstall,'${BINDIR}','pakku')
	$(call uninstall,'${SYSCONFDIR}','pakku.conf')

distcheck:
	@rm -rf 'pakku-${RVERSION}'
	@mkdir 'pakku-${RVERSION}'
	@for f in ${DIST}; do cp --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}'