ui: fall back to xterm-256color if term initialization fails
[vis.git] / Makefile
blob063727bc180e41b9591eb9eef1fa71c14d7a8466
1 include config.mk
3 SRCDIR = $(realpath $(dir $(firstword $(MAKEFILE_LIST))))
5 ALL = *.c *.h config.mk Makefile LICENSE README.md vis.1
7 DEPS_ROOT = $(SRCDIR)/dependency/install
8 DEPS_PREFIX = $(DEPS_ROOT)/usr
9 DEPS_BIN = $(DEPS_PREFIX)/bin
10 DEPS_LIB = $(DEPS_PREFIX)/lib
11 DEPS_INC = $(DEPS_PREFIX)/include
13 LIBMUSL = musl-1.1.12
14 LIBMUSL_SHA1 = e098ce88e7dd4398c178240b4c380771c5b4fe6b
16 LIBNCURSES = ncurses-6.0
17 LIBNCURSES_SHA1 = acd606135a5124905da770803c05f1f20dd3b21c
19 LIBTERMKEY = libtermkey-0.18
20 LIBTERMKEY_SHA1 = 0a78ba7aaa2f3b53f2273268366fef349c9be4ab
22 #LIBLUA = lua-5.3.1
23 #LIBLUA_SHA1 = 1676c6a041d90b6982db8cef1e5fb26000ab6dee
24 #LIBLUA = lua-5.2.4
25 #LIBLUA_SHA1 = ef15259421197e3d85b7d6e4871b8c26fd82c1cf
26 LIBLUA = lua-5.1.5
27 LIBLUA_SHA1 = b3882111ad02ecc6b972f8c1241647905cb2e3fc
29 LIBLPEG = lpeg-1.0.0
30 LIBLPEG_SHA1 = 64a0920c9243b624a277c987d2219b6c50c43971
32 LIBNCURSES_CONFIG = --disable-database --with-fallbacks=st-256color,xterm-256color,vt100 \
33 --with-shared --enable-widec --enable-ext-colors --with-termlib=tinfo \
34 --without-ada --without-cxx --without-cxx-binding --without-manpages --without-progs \
35 --without-tests --without-progs --without-debug --without-profile \
36 --without-cxx-shared --without-termlib --without--ticlib
38 all: vis
40 config.h:
41 cp config.def.h config.h
43 vis: config.h config.mk *.c *.h
44 @echo ${CC} ${CFLAGS} ${CFLAGS_VIS} *.c ${LDFLAGS} ${LDFLAGS_VIS} -o $@
45 @${CC} ${CFLAGS} ${CFLAGS_VIS} *.c ${LDFLAGS} ${LDFLAGS_VIS} -o $@
47 debug: clean
48 @$(MAKE) CFLAGS_VIS='${DEBUG_CFLAGS_VIS}'
50 profile: clean
51 @$(MAKE) CFLAGS_VIS='${DEBUG_CFLAGS_VIS} -pg'
53 clean:
54 @echo cleaning
55 @rm -f vis vis-${VERSION}.tar.gz
57 dist: clean
58 @echo creating dist tarball
59 @mkdir -p vis-${VERSION}
60 @cp -R ${ALL} vis-${VERSION}
61 @rm -f vis-${VERSION}/config.h
62 @tar -cf vis-${VERSION}.tar vis-${VERSION}
63 @gzip vis-${VERSION}.tar
64 @rm -rf vis-${VERSION}
66 install: vis
67 @echo stripping executable
68 @${STRIP} vis
69 @echo installing executable file to ${DESTDIR}${PREFIX}/bin
70 @mkdir -p ${DESTDIR}${PREFIX}/bin
71 @cp -f vis ${DESTDIR}${PREFIX}/bin
72 @chmod 755 ${DESTDIR}${PREFIX}/bin/vis
73 @cp -f vis-open ${DESTDIR}${PREFIX}/bin
74 @chmod 755 ${DESTDIR}${PREFIX}/bin/vis-open
75 @echo installing support files to ${DESTDIR}${SHAREPREFIX}
76 @mkdir -p ${DESTDIR}${SHAREPREFIX}
77 @cp -r lexers ${DESTDIR}${SHAREPREFIX}
78 @echo installing manual page to ${DESTDIR}${MANPREFIX}/man1
79 @mkdir -p ${DESTDIR}${MANPREFIX}/man1
80 @sed "s/VERSION/${VERSION}/g" < vis.1 > ${DESTDIR}${MANPREFIX}/man1/vis.1
81 @chmod 644 ${DESTDIR}${MANPREFIX}/man1/vis.1
83 uninstall:
84 @echo removing executable file from ${DESTDIR}${PREFIX}/bin
85 @rm -f ${DESTDIR}${PREFIX}/bin/vis
86 @echo removing manual page from ${DESTDIR}${MANPREFIX}/man1
87 @rm -f ${DESTDIR}${MANPREFIX}/man1/vis.1
89 release:
90 @git archive --prefix=vis-$(RELEASE)/ -o vis-$(RELEASE).tar.gz $(RELEASE)
92 dependency/sources:
93 mkdir -p $@
95 dependency/sources/musl-%: | dependency/sources
96 wget -c -O $@.part http://www.musl-libc.org/releases/$(LIBMUSL).tar.gz
97 mv $@.part $@
98 [ -z $(LIBMUSL_SHA1) ] || (echo '$(LIBMUSL_SHA1) $@' | sha1sum -c)
100 dependency/sources/extract-libmusl: dependency/sources/$(LIBMUSL).tar.gz
101 tar xzf $< -C $(dir $<)
102 touch $@
104 dependency/sources/configure-libmusl: dependency/sources/extract-libmusl
105 cd $(dir $<)/$(LIBMUSL) && ./configure --prefix=$(DEPS_PREFIX) --syslibdir=$(DEPS_PREFIX)/lib
106 touch $@
108 dependency/sources/build-libmusl: dependency/sources/configure-libmusl
109 make -C $(dir $<)/$(LIBMUSL)
110 touch $@
112 dependency/sources/install-libmusl: dependency/sources/build-libmusl
113 make -C $(dir $<)/$(LIBMUSL) install
114 touch $@
116 dependency/sources/ncurses-%: | dependency/sources
117 wget -c -O $@.part http://ftp.gnu.org/gnu/ncurses/$(LIBNCURSES).tar.gz
118 mv $@.part $@
119 [ -z $(LIBNCURSES_SHA1) ] || (echo '$(LIBNCURSES_SHA1) $@' | sha1sum -c)
121 dependency/sources/extract-libncurses: dependency/sources/$(LIBNCURSES).tar.gz
122 tar xzf $< -C $(dir $<)
123 touch $@
125 dependency/sources/configure-libncurses: dependency/sources/extract-libncurses
126 cd $(dir $<)/$(LIBNCURSES) && ./configure --prefix=/usr --libdir=/usr/lib $(LIBNCURSES_CONFIG)
127 touch $@
129 dependency/sources/build-libncurses: dependency/sources/configure-libncurses
130 make -C $(dir $<)/$(LIBNCURSES)
131 touch $@
133 dependency/sources/install-libncurses: dependency/sources/build-libncurses
134 make -C $(dir $<)/$(LIBNCURSES) install.libs DESTDIR=$(DEPS_ROOT)
135 touch $@
137 dependency/sources/libtermkey-%: | dependency/sources
138 wget -c -O $@.part http://www.leonerd.org.uk/code/libtermkey/$(LIBTERMKEY).tar.gz
139 mv $@.part $@
140 [ -z $(LIBTERMKEY_SHA1) ] || (echo '$(LIBTERMKEY_SHA1) $@' | sha1sum -c)
142 dependency/sources/extract-libtermkey: dependency/sources/$(LIBTERMKEY).tar.gz
143 tar xzf $< -C $(dir $<)
144 touch $@
146 dependency/sources/build-libtermkey: dependency/sources/extract-libtermkey
147 # TODO no sane way to avoid pkg-config and specify LDFLAGS?
148 sed -i 's/LDFLAGS+=-lncurses$$/LDFLAGS+=-lncursesw/g' $(dir $<)/$(LIBTERMKEY)/Makefile
149 make -C $(dir $<)/$(LIBTERMKEY) PREFIX=$(DEPS_PREFIX) termkey.h libtermkey.la
150 touch $@
152 dependency/sources/install-libtermkey: dependency/sources/build-libtermkey
153 make -C $(dir $<)/$(LIBTERMKEY) PREFIX=$(DEPS_PREFIX) install-inc install-lib
154 touch $@
156 dependency/sources/lua-%: | dependency/sources
157 wget -c -O $@.part http://www.lua.org/ftp/$(LIBLUA).tar.gz
158 mv $@.part $@
159 [ -z $(LIBLUA_SHA1) ] || (echo '$(LIBLUA_SHA1) $@' | sha1sum -c)
161 dependency/sources/extract-liblua: dependency/sources/$(LIBLUA).tar.gz
162 tar xzf $< -C $(dir $<)
163 touch $@
165 dependency/sources/patch-liblua: dependency/sources/extract-liblua
166 cd $(dir $<) && ([ -e $(LIBLUA)-lpeg.patch ] || wget http://www.brain-dump.org/projects/vis/$(LIBLUA)-lpeg.patch)
167 cd $(dir $<)/$(LIBLUA) && patch -p1 < ../$(LIBLUA)-lpeg.patch
168 touch $@
170 dependency/sources/build-liblua: dependency/sources/patch-liblua dependency/sources/install-liblpeg
171 make -C $(dir $<)/$(LIBLUA)/src all CC=$(CC) MYCFLAGS="-DLUA_COMPAT_5_1 -DLUA_COMPAT_5_2 -DLUA_COMPAT_ALL -DLUA_USE_POSIX -DLUA_USE_DLOPEN -fPIC" MYLIBS="-Wl,-E -ldl -lncursesw -lm"
172 #make -C $(dir $<)/$(LIBLUA) posix CC=$(CC)
173 touch $@
175 dependency/sources/install-liblua: dependency/sources/build-liblua
176 make -C $(dir $<)/$(LIBLUA) INSTALL_TOP=$(DEPS_PREFIX) install
177 touch $@
179 dependency/sources/lpeg-%: | dependency/sources
180 wget -c -O $@.part http://www.inf.puc-rio.br/~roberto/lpeg/$(LIBLPEG).tar.gz
181 mv $@.part $@
182 [ -z $(LIBLPEG_SHA1) ] || (echo '$(LIBLPEG_SHA1) $@' | sha1sum -c)
184 dependency/sources/extract-liblpeg: dependency/sources/$(LIBLPEG).tar.gz
185 tar xzf $< -C $(dir $<)
186 touch $@
188 dependency/sources/build-liblpeg: dependency/sources/extract-liblpeg
189 make -C $(dir $<)/$(LIBLPEG) LUADIR=../$(LIBLUA)/src CC=$(CC)
190 touch $@
192 dependency/sources/install-liblpeg: dependency/sources/build-liblpeg dependency/sources/extract-liblua
193 cp $(dir $<)/$(LIBLPEG)/*.o $(dir $<)/$(LIBLUA)/src
194 touch $@
196 dependencies: dependency/sources/install-libtermkey dependency/sources/install-liblua dependency/sources/install-liblpeg
198 dependencies-full: dependency/sources/install-libncurses dependencies
200 local: dependencies
201 CFLAGS="$(CFLAGS) -I$(DEPS_INC)" LDFLAGS="$(LDFLAGS) -L$(DEPS_LIB)" make CFLAGS_LUA= CFLAGS_TERMKEY= LDFLAGS_LUA=-llua LDFLAGS_TERMKEY=-ltermkey
202 @echo Run with: LD_LIBRARY_PATH=$(DEPS_LIB) VIS_PATH=. ./vis
204 standalone: dependency/sources/install-libmusl
205 PATH=$(DEPS_BIN):$$PATH CC=musl-gcc PKG_CONFIG_PATH= PKG_CONFIG_LIBDIR= CFLAGS=-I$(DEPS_INC)/ncursesw $(MAKE) dependencies-full
206 PATH=$(DEPS_BIN):$$PATH CC=musl-gcc PKG_CONFIG_PATH= PKG_CONFIG_LIBDIR= CFLAGS="--static -Wl,--as-needed -I$(DEPS_INC)/ncursesw" $(MAKE) CFLAGS_LIBS= debug
207 @echo Run with: VIS_PATH=. ./vis
209 .PHONY: all clean dist install uninstall debug profile standalone dependencies dependencies-full local