aboutsummaryrefslogtreecommitdiff
path: root/GNUmakefile
blob: 2e998d9685c8b417e13692cfc3d7555b289e1ab0 (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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
include Makefile

SRCDIR = $(realpath $(dir $(firstword $(MAKEFILE_LIST))))

DEPS_ROOT = $(SRCDIR)/dependency/install
DEPS_PREFIX = $(DEPS_ROOT)/usr
DEPS_BIN = $(DEPS_PREFIX)/bin
DEPS_LIB = $(DEPS_PREFIX)/lib
DEPS_INC = $(DEPS_PREFIX)/include

LIBMUSL = musl-1.1.16
LIBMUSL_SHA1 = 5c2204b31b1ee08a01d4d3e34c6e46f6256bdac8

LIBNCURSES = ncurses-6.0
LIBNCURSES_SHA1 = acd606135a5124905da770803c05f1f20dd3b21c

LIBTERMKEY = libtermkey-0.19
LIBTERMKEY_SHA1 = a6b55687db1c16b64f2587a81bde602e73007add

LIBLUA = lua-5.3.4
LIBLUA_SHA1 = 79790cfd40e09ba796b01a571d4d63b52b1cd950
#LIBLUA = lua-5.2.4
#LIBLUA_SHA1 = ef15259421197e3d85b7d6e4871b8c26fd82c1cf
#LIBLUA = lua-5.1.5
#LIBLUA_SHA1 = b3882111ad02ecc6b972f8c1241647905cb2e3fc

LIBLPEG = lpeg-1.0.1
LIBLPEG_SHA1 = b2f81624e0ce9c99c0731287c3475fac1f1c0f50

LIBATTR = attr-c1a7b53073202c67becf4df36cadc32ef4759c8a
LIBATTR_SHA1 = 77761b31d13d464e363621bba81835b25355f204

LIBACL = acl-38f32ea1865bcc44185f4118fde469cb962cff68
LIBACL_SHA1 = 5e6971c94bcc3803728d8eba1103f6ee4cb825d5

LIBNCURSES_CONFIG = --disable-database --with-fallbacks=st,st-256color,xterm,xterm-256color,vt100 \
	--with-shared --enable-widec --enable-ext-colors --with-termlib=tinfo \
	--without-ada --without-cxx --without-cxx-binding --without-manpages \
	--without-tests --without-progs --without-debug --without-profile \
	--without-cxx-shared --without-termlib --without--ticlib --disable-leaks

dependency/build:
	mkdir -p "$@"

dependency/sources:
	mkdir -p "$@"

# LIBMUSL

dependency/sources/musl-%: | dependency/sources
	wget -c -O $@.part http://www.musl-libc.org/releases/$(LIBMUSL).tar.gz
	mv $@.part $@
	[ -z $(LIBMUSL_SHA1) ] || (echo '$(LIBMUSL_SHA1)  $@' | sha1sum -c)

dependency/build/libmusl-extract: dependency/sources/$(LIBMUSL).tar.gz | dependency/build
	tar xzf $< -C $(dir $@)
	touch $@

dependency/build/libmusl-configure: dependency/build/libmusl-extract
	# tweak musl gcc wrapper/spec file to support static PIE linking
	sed -i 's#%{pie:S}crt1.o#%{pie:%{static:rcrt1.o%s;:Scrt1.o%s};:crt1.o%s}#' $(dir $<)/$(LIBMUSL)/tools/musl-gcc.specs.sh
	cd $(dir $<)/$(LIBMUSL) && ./configure --prefix=$(DEPS_PREFIX) --syslibdir=$(DEPS_PREFIX)/lib
	touch $@

dependency/build/libmusl-build: dependency/build/libmusl-configure
	$(MAKE) -C $(dir $<)/$(LIBMUSL)
	touch $@

dependency/build/libmusl-install: dependency/build/libmusl-build
	$(MAKE) -C $(dir $<)/$(LIBMUSL) install
	touch $@

# LIBNCURSES

dependency/sources/ncurses-%: | dependency/sources
	wget -c -O $@.part http://ftp.gnu.org/gnu/ncurses/$(LIBNCURSES).tar.gz
	mv $@.part $@
	[ -z $(LIBNCURSES_SHA1) ] || (echo '$(LIBNCURSES_SHA1)  $@' | sha1sum -c)

dependency/build/libncurses-extract: dependency/sources/$(LIBNCURSES).tar.gz | dependency/build
	tar xzf $< -C $(dir $@)
	touch $@

dependency/build/libncurses-configure: dependency/build/libncurses-extract
	cd $(dir $<)/$(LIBNCURSES) && ./configure --prefix=/usr --libdir=/usr/lib $(LIBNCURSES_CONFIG)
	touch $@

dependency/build/libncurses-build: dependency/build/libncurses-configure
	$(MAKE) -C $(dir $<)/$(LIBNCURSES)
	touch $@

dependency/build/libncurses-install: dependency/build/libncurses-build
	$(MAKE) -C $(dir $<)/$(LIBNCURSES) install.libs DESTDIR=$(DEPS_ROOT)
	touch $@

# LIBTERMKEY

dependency/sources/libtermkey-%: | dependency/sources
	wget -c -O $@.part http://www.leonerd.org.uk/code/libtermkey/$(LIBTERMKEY).tar.gz
	mv $@.part $@
	[ -z $(LIBTERMKEY_SHA1) ] || (echo '$(LIBTERMKEY_SHA1)  $@' | sha1sum -c)

dependency/build/libtermkey-extract: dependency/sources/$(LIBTERMKEY).tar.gz | dependency/build
	tar xzf $< -C $(dir $@)
	touch $@

dependency/build/libtermkey-build: dependency/build/libtermkey-extract dependency/build/libncurses-install
	# TODO no sane way to avoid pkg-config and specify LDFLAGS?
	sed -i 's/LDFLAGS+=-lncurses$$/LDFLAGS+=-lncursesw/g' $(dir $<)/$(LIBTERMKEY)/Makefile
	$(MAKE) -C $(dir $<)/$(LIBTERMKEY) PREFIX=/usr termkey.h libtermkey.la
	touch $@

dependency/build/libtermkey-install: dependency/build/libtermkey-build
	$(MAKE) -C $(dir $<)/$(LIBTERMKEY) PREFIX=/usr DESTDIR=$(DEPS_ROOT) install-inc install-lib
	touch $@

# LIBLUA

dependency/sources/lua-%.tar.gz: | dependency/sources
	wget -c -O $@.part http://www.lua.org/ftp/$(LIBLUA).tar.gz
	mv $@.part $@
	[ -z $(LIBLUA_SHA1) ] || (echo '$(LIBLUA_SHA1)  $@' | sha1sum -c)

dependency/build/liblua-extract: dependency/sources/$(LIBLUA).tar.gz | dependency/build
	tar xzf $< -C $(dir $@)
	touch $@

dependency/build/liblua-build: dependency/build/liblua-extract
	$(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 -lm"
	#$(MAKE) -C $(dir $<)/$(LIBLUA) posix CC=$(CC)
	touch $@

dependency/build/liblua-install: dependency/build/liblua-build
	$(MAKE) -C $(dir $<)/$(LIBLUA) INSTALL_TOP=$(DEPS_PREFIX) install
	touch $@

# LIBLPEG

dependency/sources/lpeg-%: | dependency/sources
	wget -c -O $@.part http://www.inf.puc-rio.br/~roberto/lpeg/$(LIBLPEG).tar.gz
	mv $@.part $@
	[ -z $(LIBLPEG_SHA1) ] || (echo '$(LIBLPEG_SHA1)  $@' | sha1sum -c)

dependency/build/liblpeg-extract: dependency/sources/$(LIBLPEG).tar.gz | dependency/build
	tar xzf $< -C $(dir $@)
	touch $@

dependency/build/liblpeg-build: dependency/build/liblpeg-extract dependency/build/liblua-extract
	# creating a shared object fails in Cygwin, we do not need it thus ignore the error
	cd $(dir $<)/$(LIBLPEG) && $(MAKE) LUADIR="../$(LIBLUA)/src" || true
	cd $(dir $<)/$(LIBLPEG) && ar rcu liblpeg.a lpvm.o lpcap.o lptree.o lpcode.o lpprint.o && ranlib liblpeg.a
	touch $@

dependency/build/liblpeg-install: dependency/build/liblpeg-build
	cd $(dir $<)/$(LIBLPEG) && cp liblpeg.a $(DEPS_LIB)
	touch $@

# LIBATTR

dependency/sources/attr-%.tar.gz: | dependency/sources
	wget -c -O $@.part http://git.savannah.gnu.org/cgit/attr.git/snapshot/$(LIBATTR).tar.gz
	mv $@.part $@
	[ -z $(LIBATTR_SHA1) ] || (echo '$(LIBATTR_SHA1)  $@' | sha1sum -c)

dependency/build/libattr-extract: dependency/sources/$(LIBATTR).tar.gz | dependency/build
	tar xzf $< -C $(dir $@)
	cd $(dir $@)/$(LIBATTR) && ./autogen.sh
	touch $@

dependency/build/libattr-configure: dependency/build/libattr-extract
	cd $(dir $<)/$(LIBATTR) && ./configure --prefix=/usr --libdir=/usr/lib --with-sysroot=$(DEPS_ROOT)
	touch $@

dependency/build/libattr-build: dependency/build/libattr-configure
	$(MAKE) -C $(dir $<)/$(LIBATTR)
	touch $@

dependency/build/libattr-install: dependency/build/libattr-build
	$(MAKE) -C $(dir $<)/$(LIBATTR) DESTDIR=$(DEPS_ROOT) install
	touch $@

# LIBACL

dependency/sources/acl-%.tar.gz: | dependency/sources
	wget -c -O $@.part http://git.savannah.gnu.org/cgit/acl.git/snapshot/$(LIBACL).tar.gz
	mv $@.part $@
	[ -z $(LIBACL_SHA1) ] || (echo '$(LIBACL_SHA1)  $@' | sha1sum -c)

dependency/build/libacl-extract: dependency/sources/$(LIBACL).tar.gz | dependency/build
	tar xzf $< -C $(dir $@)
	cd $(dir $@)/$(LIBACL) && ./autogen.sh
	touch $@

dependency/build/libacl-configure: dependency/build/libacl-extract dependency/build/libattr-install
	cd $(dir $<)/$(LIBACL) && ./configure --prefix=/usr --libdir=/usr/lib --with-sysroot=$(DEPS_ROOT)
	touch $@

dependency/build/libacl-build: dependency/build/libacl-configure
	$(MAKE) -C $(dir $<)/$(LIBACL)
	touch $@

dependency/build/libacl-install: dependency/build/libacl-build
	$(MAKE) -C $(dir $<)/$(LIBACL) DESTDIR=$(DEPS_ROOT) install
	touch $@

# COMMON

dependencies-common: dependency/build/libtermkey-install dependency/build/liblua-install dependency/build/liblpeg-install

dependency/build/local: dependencies-common
	touch $@

dependency/build/standalone: dependency/build/libncurses-install dependency/build/libacl-install dependencies-common
	touch $@

dependencies-clean:
	rm -f dependency/build/libmusl-install
	rm -rf dependency/build/*curses*
	rm -rf dependency/build/libtermkey*
	rm -rf dependency/build/*lua*
	rm -rf dependency/build/*lpeg*
	rm -rf dependency/build/*attr*
	rm -rf dependency/build/*acl*
	rm -f dependency/build/local
	rm -f dependency/build/standalone
	rm -rf dependency/install
	rm -f config.mk

dependencies-local:
	[ ! -e dependency/build/standalone ] || $(MAKE) dependencies-clean
	mkdir -p dependency/build
	[ -e dependency/build/libncurses-install ] || touch \
		dependency/build/libncurses-extract \
		dependency/build/libncurses-configure \
		dependency/build/libncurses-build \
		dependency/build/libncurses-install
	$(MAKE) dependency/build/local

local: clean
	./configure --environment-only
	$(MAKE) dependencies-local
	./configure CFLAGS="-I$(DEPS_INC)" LDFLAGS="-L$(DEPS_LIB)" LD_LIBRARY_PATH="$(DEPS_LIB)"
	$(MAKE)
	@echo Run with: LD_LIBRARY_PATH=$(DEPS_LIB) ./vis

standalone: clean
	[ ! -e dependency/build/local ] || $(MAKE) dependencies-clean
	./configure CFLAGS="-I$(DEPS_INC)" LDFLAGS="-L$(DEPS_LIB)" --environment-only --static
	CFLAGS="$(CFLAGS)" $(MAKE) dependency/build/libmusl-install
	PATH=$(DEPS_BIN):$$PATH PKG_CONFIG_PATH= PKG_CONFIG_LIBDIR= CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" $(MAKE) \
		CC=musl-gcc dependency/build/standalone
	PATH=$(DEPS_BIN):$$PATH PKG_CONFIG_PATH= PKG_CONFIG_LIBDIR= ./configure --static \
		CFLAGS="-I$(DEPS_INC) --static -Wl,--as-needed" LDFLAGS="-L$(DEPS_LIB)" CC=musl-gcc
	PATH=$(DEPS_BIN):$$PATH $(MAKE)

single: standalone
	cp vis-single.sh vis-single
	for e in $(ELF); do \
		${STRIP} "$$e"; \
	done
	tar c $(EXECUTABLES) lua/ | gzip -9 >> vis-single

.PHONY: standalone local dependencies-common dependencies-local dependencies-clean