test: update
[vis.git] / Makefile
blob3d3539e21b8b2036d13f98e820bfb9dbaff4d8d2
1 -include config.mk
3 REGEX_SRC ?= text-regex.c
5 SRC = array.c \
6 buffer.c \
7 libutf.c \
8 main.c \
9 map.c \
10 sam.c \
11 text.c \
12 text-common.c \
13 text-io.c \
14 text-iterator.c \
15 text-motions.c \
16 text-objects.c \
17 text-util.c \
18 ui-terminal.c \
19 view.c \
20 vis.c \
21 vis-lua.c \
22 vis-marks.c \
23 vis-modes.c \
24 vis-motions.c \
25 vis-operators.c \
26 vis-prompt.c \
27 vis-registers.c \
28 vis-text-objects.c \
29 $(REGEX_SRC)
31 ELF = vis vis-menu vis-digraph
32 EXECUTABLES = $(ELF) vis-clipboard vis-complete vis-open
34 MANUALS = $(EXECUTABLES:=.1)
36 DOCUMENTATION = LICENSE README.md
38 VERSION = $(shell git describe --always --dirty 2>/dev/null || echo "v0.7-git")
40 CONFIG_HELP ?= 1
41 CONFIG_CURSES ?= 1
42 CONFIG_LUA ?= 1
43 CONFIG_LPEG ?= 0
44 CONFIG_TRE ?= 0
45 CONFIG_ACL ?= 0
46 CONFIG_SELINUX ?= 0
48 CFLAGS_STD ?= -std=c99 -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -DNDEBUG
49 CFLAGS_STD += -DVERSION=\"${VERSION}\"
50 LDFLAGS_STD ?= -lc
52 CFLAGS_LIBC ?= -DHAVE_MEMRCHR=0
54 CFLAGS_VIS = $(CFLAGS_AUTO) $(CFLAGS_TERMKEY) $(CFLAGS_CURSES) $(CFLAGS_ACL) \
55 $(CFLAGS_SELINUX) $(CFLAGS_TRE) $(CFLAGS_LUA) $(CFLAGS_LPEG) $(CFLAGS_STD) \
56 $(CFLAGS_LIBC)
58 CFLAGS_VIS += -DVIS_PATH=\"${SHAREPREFIX}/vis\"
59 CFLAGS_VIS += -DCONFIG_HELP=${CONFIG_HELP}
60 CFLAGS_VIS += -DCONFIG_CURSES=${CONFIG_CURSES}
61 CFLAGS_VIS += -DCONFIG_LUA=${CONFIG_LUA}
62 CFLAGS_VIS += -DCONFIG_LPEG=${CONFIG_LPEG}
63 CFLAGS_VIS += -DCONFIG_TRE=${CONFIG_TRE}
64 CFLAGS_VIS += -DCONFIG_SELINUX=${CONFIG_SELINUX}
65 CFLAGS_VIS += -DCONFIG_ACL=${CONFIG_ACL}
67 LDFLAGS_VIS = $(LDFLAGS_AUTO) $(LDFLAGS_TERMKEY) $(LDFLAGS_CURSES) $(LDFLAGS_ACL) \
68 $(LDFLAGS_SELINUX) $(LDFLAGS_TRE) $(LDFLAGS_LUA) $(LDFLAGS_LPEG) $(LDFLAGS_STD)
70 STRIP?=strip
71 TAR?=tar
72 DOCKER?=docker
74 all: $(ELF)
76 config.h:
77 cp config.def.h config.h
79 config.mk:
80 @touch $@
82 vis: config.h config.mk *.c *.h
83 ${CC} ${CFLAGS} ${CFLAGS_VIS} ${CFLAGS_EXTRA} ${SRC} ${LDFLAGS} ${LDFLAGS_VIS} -o $@
85 vis-menu: vis-menu.c
86 ${CC} ${CFLAGS} ${CFLAGS_AUTO} ${CFLAGS_STD} ${CFLAGS_EXTRA} $< ${LDFLAGS} ${LDFLAGS_STD} ${LDFLAGS_AUTO} -o $@
88 vis-digraph: vis-digraph.c
89 ${CC} ${CFLAGS} ${CFLAGS_AUTO} ${CFLAGS_STD} ${CFLAGS_EXTRA} $< ${LDFLAGS} ${LDFLAGS_STD} ${LDFLAGS_AUTO} -o $@
91 vis-single-payload.inc: $(EXECUTABLES) lua/*
92 for e in $(ELF); do \
93 ${STRIP} "$$e"; \
94 done
95 echo '#ifndef VIS_SINGLE_PAYLOAD_H' > $@
96 echo '#define VIS_SINGLE_PAYLOAD_H' >> $@
97 echo 'static unsigned char vis_single_payload[] = {' >> $@
98 $(TAR) --mtime='2014-07-15 01:23Z' --owner=0 --group=0 --numeric-owner --mode='a+rX-w' -c \
99 $(EXECUTABLES) $$(find lua -name '*.lua' | LC_ALL=C sort) | xz -T 1 | \
100 od -t x1 -v | sed -e 's/^[0-9a-fA-F]\{1,\}//g' -e 's/\([0-9a-f]\{2\}\)/0x\1,/g' >> $@
101 echo '};' >> $@
102 echo '#endif' >> $@
104 vis-single: vis-single.c vis-single-payload.inc
105 ${CC} ${CFLAGS} ${CFLAGS_AUTO} ${CFLAGS_STD} ${CFLAGS_EXTRA} $< ${LDFLAGS} ${LDFLAGS_STD} ${LDFLAGS_AUTO} -luntar -llzma -o $@
106 ${STRIP} $@
108 docker-kill:
109 -$(DOCKER) kill vis && $(DOCKER) wait vis
111 docker: docker-kill clean
112 $(DOCKER) build -t vis .
113 $(DOCKER) run --rm -d --name vis vis tail -f /dev/null
114 $(DOCKER) exec vis apk update
115 $(DOCKER) exec vis apk upgrade
116 $(DOCKER) cp . vis:/build/vis
117 $(DOCKER) exec -w /build/vis vis ./configure CC='cc --static' \
118 --enable-acl \
119 --enable-lua \
120 --enable-lpeg-static
121 $(DOCKER) exec -w /build/vis vis make VERSION="$(VERSION)" clean vis-single
122 $(DOCKER) cp vis:/build/vis/vis-single vis
123 $(DOCKER) kill vis
125 docker-clean: docker-kill clean
126 -$(DOCKER) image rm vis
128 debug: clean
129 @$(MAKE) CFLAGS_EXTRA='${CFLAGS_EXTRA} ${CFLAGS_DEBUG}'
131 profile: clean
132 @$(MAKE) CFLAGS_AUTO='' LDFLAGS_AUTO='' CFLAGS_EXTRA='-pg -O2'
134 coverage: clean
135 @$(MAKE) CFLAGS_EXTRA='--coverage'
137 test-update:
138 git submodule init
139 git submodule update --remote --rebase
141 test:
142 [ -e test/Makefile ] || $(MAKE) test-update
143 @$(MAKE) -C test
145 testclean:
146 @echo cleaning the test artifacts
147 [ ! -e test/Makefile ] || $(MAKE) -C test clean
149 clean:
150 @echo cleaning
151 @rm -f $(ELF) vis-single vis-single-payload.inc vis-*.tar.gz *.gcov *.gcda *.gcno
153 distclean: clean testclean
154 @echo cleaning build configuration
155 @rm -f config.h config.mk
157 dist: distclean
158 @echo creating dist tarball
159 @git archive --prefix=vis-${VERSION}/ -o vis-${VERSION}.tar.gz HEAD
161 man:
162 @for m in ${MANUALS}; do \
163 echo "Generating $$m"; \
164 sed -e "s/VERSION/${VERSION}/" "man/$$m" | mandoc -W warning -T utf8 -T html -O man=%N.%S.html -O style=mandoc.css 1> "man/$$m.html" || true; \
165 done
167 luadoc:
168 @cd lua/doc && ldoc . && sed -e "s/RELEASE/${VERSION}/" -i index.html
170 luadoc-all:
171 @cd lua/doc && ldoc -a . && sed -e "s/RELEASE/${VERSION}/" -i index.html
173 luacheck:
174 @luacheck --config .luacheckrc lua test/lua | less -RFX
176 install: $(ELF)
177 @echo installing executable files to ${DESTDIR}${PREFIX}/bin
178 @mkdir -p ${DESTDIR}${PREFIX}/bin
179 @for e in ${EXECUTABLES}; do \
180 cp -f "$$e" ${DESTDIR}${PREFIX}/bin && \
181 chmod 755 ${DESTDIR}${PREFIX}/bin/"$$e"; \
182 done
183 @test ${CONFIG_LUA} -eq 0 || { \
184 echo installing support files to ${DESTDIR}${SHAREPREFIX}/vis; \
185 mkdir -p ${DESTDIR}${SHAREPREFIX}/vis; \
186 cp -r lua/* ${DESTDIR}${SHAREPREFIX}/vis; \
187 rm -rf "${DESTDIR}${SHAREPREFIX}/vis/doc"; \
189 @echo installing documentation to ${DESTDIR}${DOCPREFIX}/vis
190 @mkdir -p ${DESTDIR}${DOCPREFIX}/vis
191 @for d in ${DOCUMENTATION}; do \
192 cp "$$d" ${DESTDIR}${DOCPREFIX}/vis && \
193 chmod 644 "${DESTDIR}${DOCPREFIX}/vis/$$d"; \
194 done
195 @echo installing manual pages to ${DESTDIR}${MANPREFIX}/man1
196 @mkdir -p ${DESTDIR}${MANPREFIX}/man1
197 @for m in ${MANUALS}; do \
198 sed -e "s/VERSION/${VERSION}/" < "man/$$m" > "${DESTDIR}${MANPREFIX}/man1/$$m" && \
199 chmod 644 "${DESTDIR}${MANPREFIX}/man1/$$m"; \
200 done
202 install-strip: install
203 @echo stripping executables
204 @for e in $(ELF); do \
205 ${STRIP} ${DESTDIR}${PREFIX}/bin/"$$e"; \
206 done
208 uninstall:
209 @echo removing executable file from ${DESTDIR}${PREFIX}/bin
210 @for e in ${EXECUTABLES}; do \
211 rm -f ${DESTDIR}${PREFIX}/bin/"$$e"; \
212 done
213 @echo removing documentation from ${DESTDIR}${DOCPREFIX}/vis
214 @for d in ${DOCUMENTATION}; do \
215 rm -f ${DESTDIR}${DOCPREFIX}/vis/"$$d"; \
216 done
217 @echo removing manual pages from ${DESTDIR}${MANPREFIX}/man1
218 @for m in ${MANUALS}; do \
219 rm -f ${DESTDIR}${MANPREFIX}/man1/"$$m"; \
220 done
221 @echo removing support files from ${DESTDIR}${SHAREPREFIX}/vis
222 @rm -rf ${DESTDIR}${SHAREPREFIX}/vis
224 .PHONY: all clean testclean dist distclean install install-strip uninstall debug profile coverage test test-update luadoc luadoc-all luacheck man docker-kill docker docker-clean