text: move I/O related code to separate file
[vis.git] / Makefile
blobc43ed12c5eed735901593a57bcbab1d73e9afa1c
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-io.c \
13 text-motions.c \
14 text-objects.c \
15 text-util.c \
16 ui-terminal.c \
17 view.c \
18 vis.c \
19 vis-lua.c \
20 vis-marks.c \
21 vis-modes.c \
22 vis-motions.c \
23 vis-operators.c \
24 vis-prompt.c \
25 vis-registers.c \
26 vis-text-objects.c \
27 $(REGEX_SRC)
29 ELF = vis vis-menu vis-digraph
30 EXECUTABLES = $(ELF) vis-clipboard vis-complete vis-open
32 MANUALS = $(EXECUTABLES:=.1)
34 DOCUMENTATION = LICENSE README.md
36 VERSION = $(shell git describe --always --dirty 2>/dev/null || echo "v0.6-git")
38 CONFIG_HELP ?= 1
39 CONFIG_CURSES ?= 1
40 CONFIG_LUA ?= 1
41 CONFIG_LPEG ?= 0
42 CONFIG_TRE ?= 0
43 CONFIG_ACL ?= 0
44 CONFIG_SELINUX ?= 0
46 CFLAGS_STD ?= -std=c99 -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -DNDEBUG
47 CFLAGS_STD += -DVERSION=\"${VERSION}\"
48 LDFLAGS_STD ?= -lc
50 CFLAGS_LIBC ?= -DHAVE_MEMRCHR=0
52 CFLAGS_VIS = $(CFLAGS_AUTO) $(CFLAGS_TERMKEY) $(CFLAGS_CURSES) $(CFLAGS_ACL) \
53 $(CFLAGS_SELINUX) $(CFLAGS_TRE) $(CFLAGS_LUA) $(CFLAGS_LPEG) $(CFLAGS_STD) \
54 $(CFLAGS_LIBC)
56 CFLAGS_VIS += -DVIS_PATH=\"${SHAREPREFIX}/vis\"
57 CFLAGS_VIS += -DCONFIG_HELP=${CONFIG_HELP}
58 CFLAGS_VIS += -DCONFIG_CURSES=${CONFIG_CURSES}
59 CFLAGS_VIS += -DCONFIG_LUA=${CONFIG_LUA}
60 CFLAGS_VIS += -DCONFIG_LPEG=${CONFIG_LPEG}
61 CFLAGS_VIS += -DCONFIG_TRE=${CONFIG_TRE}
62 CFLAGS_VIS += -DCONFIG_SELINUX=${CONFIG_SELINUX}
63 CFLAGS_VIS += -DCONFIG_ACL=${CONFIG_ACL}
65 LDFLAGS_VIS = $(LDFLAGS_AUTO) $(LDFLAGS_TERMKEY) $(LDFLAGS_CURSES) $(LDFLAGS_ACL) \
66 $(LDFLAGS_SELINUX) $(LDFLAGS_TRE) $(LDFLAGS_LUA) $(LDFLAGS_LPEG) $(LDFLAGS_STD)
68 STRIP?=strip
69 TAR?=tar
70 DOCKER?=docker
72 all: $(ELF)
74 config.h:
75 cp config.def.h config.h
77 config.mk:
78 @touch $@
80 vis: config.h config.mk *.c *.h
81 ${CC} ${CFLAGS} ${CFLAGS_VIS} ${CFLAGS_EXTRA} ${SRC} ${LDFLAGS} ${LDFLAGS_VIS} -o $@
83 vis-menu: vis-menu.c
84 ${CC} ${CFLAGS} ${CFLAGS_AUTO} ${CFLAGS_STD} ${CFLAGS_EXTRA} $< ${LDFLAGS} ${LDFLAGS_STD} ${LDFLAGS_AUTO} -o $@
86 vis-digraph: vis-digraph.c
87 ${CC} ${CFLAGS} ${CFLAGS_AUTO} ${CFLAGS_STD} ${CFLAGS_EXTRA} $< ${LDFLAGS} ${LDFLAGS_STD} ${LDFLAGS_AUTO} -o $@
89 vis-single-payload.inc: $(EXECUTABLES) lua/*
90 for e in $(ELF); do \
91 ${STRIP} "$$e"; \
92 done
93 echo '#ifndef VIS_SINGLE_PAYLOAD_H' > $@
94 echo '#define VIS_SINGLE_PAYLOAD_H' >> $@
95 echo 'static unsigned char vis_single_payload[] = {' >> $@
96 $(TAR) --mtime='2014-07-15 01:23Z' --owner=0 --group=0 --numeric-owner --mode='a+rX-w' -c \
97 $(EXECUTABLES) $$(find lua -name '*.lua' | LC_ALL=C sort) | xz -T 1 | \
98 od -t x1 -v | sed -e 's/^[0-9a-fA-F]\{1,\}//g' -e 's/\([0-9a-f]\{2\}\)/0x\1,/g' >> $@
99 echo '};' >> $@
100 echo '#endif' >> $@
102 vis-single: vis-single.c vis-single-payload.inc
103 ${CC} ${CFLAGS} ${CFLAGS_AUTO} ${CFLAGS_STD} ${CFLAGS_EXTRA} $< ${LDFLAGS} ${LDFLAGS_STD} ${LDFLAGS_AUTO} -luntar -llzma -o $@
104 ${STRIP} $@
106 docker-kill:
107 -$(DOCKER) kill vis && $(DOCKER) wait vis
109 docker: docker-kill clean
110 $(DOCKER) build -t vis .
111 $(DOCKER) run --rm -d --name vis vis tail -f /dev/null
112 $(DOCKER) exec vis apk update
113 $(DOCKER) exec vis apk upgrade
114 $(DOCKER) cp . vis:/build/vis
115 $(DOCKER) exec -w /build/vis vis ./configure CC='cc --static' \
116 --enable-acl \
117 --enable-lua \
118 --enable-lpeg-static
119 $(DOCKER) exec -w /build/vis vis make VERSION="$(VERSION)" clean vis-single
120 $(DOCKER) cp vis:/build/vis/vis-single vis
121 $(DOCKER) kill vis
123 docker-clean: docker-kill clean
124 -$(DOCKER) image rm vis
126 debug: clean
127 @$(MAKE) CFLAGS_EXTRA='${CFLAGS_EXTRA} ${CFLAGS_DEBUG}'
129 profile: clean
130 @$(MAKE) CFLAGS_AUTO='' LDFLAGS_AUTO='' CFLAGS_EXTRA='-pg -O2'
132 coverage: clean
133 @$(MAKE) CFLAGS_EXTRA='--coverage'
135 test-update:
136 git submodule init
137 git submodule update --remote --rebase
139 test:
140 [ -e test/Makefile ] || $(MAKE) test-update
141 @$(MAKE) -C test
143 testclean:
144 @echo cleaning the test artifacts
145 [ ! -e test/Makefile ] || $(MAKE) -C test clean
147 clean:
148 @echo cleaning
149 @rm -f $(ELF) vis-single vis-single-payload.inc vis-*.tar.gz *.gcov *.gcda *.gcno
151 distclean: clean testclean
152 @echo cleaning build configuration
153 @rm -f config.h config.mk
155 dist: distclean
156 @echo creating dist tarball
157 @git archive --prefix=vis-${VERSION}/ -o vis-${VERSION}.tar.gz HEAD
159 man:
160 @for m in ${MANUALS}; do \
161 echo "Generating $$m"; \
162 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; \
163 done
165 luadoc:
166 @cd lua/doc && ldoc . && sed -e "s/RELEASE/${VERSION}/" -i index.html
168 luadoc-all:
169 @cd lua/doc && ldoc -a . && sed -e "s/RELEASE/${VERSION}/" -i index.html
171 luacheck:
172 @luacheck --config .luacheckrc lua test/lua | less -RFX
174 install: $(ELF)
175 @echo installing executable files to ${DESTDIR}${PREFIX}/bin
176 @mkdir -p ${DESTDIR}${PREFIX}/bin
177 @for e in ${EXECUTABLES}; do \
178 cp -f "$$e" ${DESTDIR}${PREFIX}/bin && \
179 chmod 755 ${DESTDIR}${PREFIX}/bin/"$$e"; \
180 done
181 @test ${CONFIG_LUA} -eq 0 || { \
182 echo installing support files to ${DESTDIR}${SHAREPREFIX}/vis; \
183 mkdir -p ${DESTDIR}${SHAREPREFIX}/vis; \
184 cp -r lua/* ${DESTDIR}${SHAREPREFIX}/vis; \
185 rm -rf "${DESTDIR}${SHAREPREFIX}/vis/doc"; \
187 @echo installing documentation to ${DESTDIR}${DOCPREFIX}/vis
188 @mkdir -p ${DESTDIR}${DOCPREFIX}/vis
189 @for d in ${DOCUMENTATION}; do \
190 cp "$$d" ${DESTDIR}${DOCPREFIX}/vis && \
191 chmod 644 "${DESTDIR}${DOCPREFIX}/vis/$$d"; \
192 done
193 @echo installing manual pages to ${DESTDIR}${MANPREFIX}/man1
194 @mkdir -p ${DESTDIR}${MANPREFIX}/man1
195 @for m in ${MANUALS}; do \
196 sed -e "s/VERSION/${VERSION}/" < "man/$$m" > "${DESTDIR}${MANPREFIX}/man1/$$m" && \
197 chmod 644 "${DESTDIR}${MANPREFIX}/man1/$$m"; \
198 done
200 install-strip: install
201 @echo stripping executables
202 @for e in $(ELF); do \
203 ${STRIP} ${DESTDIR}${PREFIX}/bin/"$$e"; \
204 done
206 uninstall:
207 @echo removing executable file from ${DESTDIR}${PREFIX}/bin
208 @for e in ${EXECUTABLES}; do \
209 rm -f ${DESTDIR}${PREFIX}/bin/"$$e"; \
210 done
211 @echo removing documentation from ${DESTDIR}${DOCPREFIX}/vis
212 @for d in ${DOCUMENTATION}; do \
213 rm -f ${DESTDIR}${DOCPREFIX}/vis/"$$d"; \
214 done
215 @echo removing manual pages from ${DESTDIR}${MANPREFIX}/man1
216 @for m in ${MANUALS}; do \
217 rm -f ${DESTDIR}${MANPREFIX}/man1/"$$m"; \
218 done
219 @echo removing support files from ${DESTDIR}${SHAREPREFIX}/vis
220 @rm -rf ${DESTDIR}${SHAREPREFIX}/vis
222 .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