forked from luvit/luvit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
385 lines (322 loc) · 11.1 KB
/
Makefile
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
### OPTIONS ###
# export the following variables to use the system libraries
# instead of the bundled ones:
# USE_SYSTEM_SSL=1
# USE_SYSTEM_LUAJIT=1
# USE_SYSTEM_ZLIB=1
# USE_SYSTEM_YAJL=1
#
# default is to use the bundled libraries
#
# disable debug symbols:
# DEBUG=0
#
## disable -Werror:
# WERROR=0
VERSION=$(shell git describe --tags)
LUADIR=deps/luajit
LUAJIT_VERSION=$(shell git --git-dir ${LUADIR}/.git describe --tags)
YAJLDIR=deps/yajl
YAJL_VERSION=$(shell git --git-dir ${YAJLDIR}/.git describe --tags)
UVDIR=deps/uv
UV_VERSION=$(shell git --git-dir ${UVDIR}/.git describe --all --long | cut -f 3 -d -)
HTTPDIR=deps/http-parser
HTTP_VERSION=$(shell git --git-dir ${HTTPDIR}/.git describe --tags)
ZLIBDIR=deps/zlib
SSLDIR=deps/openssl
BUILDDIR=build
CRYPTODIR=deps/luacrypto
CARESDIR=deps/cares
PREFIX?=/usr/local
BINDIR?=${DESTDIR}${PREFIX}/bin
INCDIR?=${DESTDIR}${PREFIX}/include/luvit
LIBDIR?=${DESTDIR}${PREFIX}/lib/luvit
RANLIB?=ranlib
USE_SYSTEM_SSL?=0
USE_SYSTEM_LUAJIT?=0
USE_SYSTEM_ZLIB?=0
USE_SYSTEM_YAJL?=0
DEBUG ?= 1
ifeq (${DEBUG},1)
CFLAGS += -g
endif
WERROR ?= 1
ifeq (${WERROR},1)
CFLAGS += -Werror
endif
OS_NAME=$(shell uname -s)
MH_NAME=$(shell uname -m)
ifeq (${OS_NAME},Darwin)
ifeq (${MH_NAME},x86_64)
LDFLAGS+=-framework CoreServices -framework Carbon -pagezero_size 10000 -image_base 100000000
else
LDFLAGS+=-framework CoreServices
endif
else ifeq (${OS_NAME},Linux)
LDFLAGS+=-Wl,-E
else ifeq (${OS_NAME},FreeBSD)
LDFLAGS+=-lkvm -Wl,-E
endif
# LUAJIT CONFIGURATION #
#XCFLAGS=-g
#XCFLAGS+=-DLUAJIT_DISABLE_JIT
XCFLAGS+=-DLUAJIT_ENABLE_LUA52COMPAT
#XCFLAGS+=-DLUA_USE_APICHECK
export XCFLAGS
# verbose build
export Q=
MAKEFLAGS+=-e
LDFLAGS+=-L${BUILDDIR}
LIBS += -lluvit -lpthread
ifeq (${USE_SYSTEM_ZLIB},1)
CPPFLAGS+=$(shell pkg-config --cflags zlib)
LIBS+=$(shell pkg-config --libs zlib)
else
CPPFLAGS+=-I${ZLIBDIR}
LIBS+=${ZLIBDIR}/libz.a
endif
ifeq (${USE_SYSTEM_YAJL},1)
CPPFLAS+=$(shell pkg-config --cflags yajl)
LIBS+=$(shell pkg-config --libs yajl)
else
CPPFLAGS += -I${YAJLDIR}/src -I${YAJLDIR}/src/api
LIBS+=${YAJLDIR}/yajl.a
endif
LIBS += ${UVDIR}/libuv.a
LIBS += ${CARESDIR}/libcares.a
ifeq (${USE_SYSTEM_LUAJIT},1)
CPPFLAGS+=$(shell pkg-config --cflags luajit)
LIBS+=$(shell pkg-config --libs luajit)
else
CPPFLAGS+=-I${LUADIR}/src
LIBS+=${LUADIR}/src/libluajit.a
endif
LIBS += -lm
ifeq (${USE_SYSTEM_SSL},1)
CFLAGS+=-Wall -w
CPPFLAGS+=$(shell pkg-config --cflags openssl)
LIBS+=$(shell pkg-config --libs openssl)
else
CPPFLAGS+=-I${SSLDIR}/openssl/include
LIBS+=${SSLDIR}/libopenssl.a
endif
ifeq (${OS_NAME},Linux)
LIBS+=-lrt -ldl
endif
CPPFLAGS += -DUSE_OPENSSL
CPPFLAGS += -DL_ENDIAN
CPPFLAGS += -DOPENSSL_THREADS
CPPFLAGS += -DPURIFY
CPPFLAGS += -D_REENTRANT
CPPFLAGS += -DOPENSSL_NO_ASM
CPPFLAGS += -DOPENSSL_NO_INLINE_ASM
CPPFLAGS += -DOPENSSL_NO_RC2
CPPFLAGS += -DOPENSSL_NO_RC5
CPPFLAGS += -DOPENSSL_NO_MD4
CPPFLAGS += -DOPENSSL_NO_HW
CPPFLAGS += -DOPENSSL_NO_GOST
CPPFLAGS += -DOPENSSL_NO_CAMELLIA
CPPFLAGS += -DOPENSSL_NO_CAPIENG
CPPFLAGS += -DOPENSSL_NO_CMS
CPPFLAGS += -DOPENSSL_NO_FIPS
CPPFLAGS += -DOPENSSL_NO_IDEA
CPPFLAGS += -DOPENSSL_NO_MDC2
CPPFLAGS += -DOPENSSL_NO_MD2
CPPFLAGS += -DOPENSSL_NO_SEED
CPPFLAGS += -DOPENSSL_NO_SOCK
CPPFLAGS += -DOPENSSL_NO_SCTP
CPPFLAGS += -DOPENSSL_NO_EC2M
ifeq (${MH_NAME},x86_64)
CPPFLAGS += -I${SSLDIR}/openssl-configs/x64
else ifeq (${MH_NAME},amd64)
CPPFLAGS += -I${SSLDIR}/openssl-configs/x64
else
CPPFLAGS += -I${SSLDIR}/openssl-configs/ia32
endif
LUVLIBS=${BUILDDIR}/utils.o \
${BUILDDIR}/luv_fs.o \
${BUILDDIR}/luv_dns.o \
${BUILDDIR}/luv_debug.o \
${BUILDDIR}/luv_handle.o \
${BUILDDIR}/luv_udp.o \
${BUILDDIR}/luv_fs_watcher.o \
${BUILDDIR}/luv_timer.o \
${BUILDDIR}/luv_process.o \
${BUILDDIR}/luv_signal.o \
${BUILDDIR}/luv_stream.o \
${BUILDDIR}/luv_tcp.o \
${BUILDDIR}/luv_tls.o \
${BUILDDIR}/luv_tls_conn.o \
${BUILDDIR}/luv_pipe.o \
${BUILDDIR}/luv_poll.o \
${BUILDDIR}/luv_tty.o \
${BUILDDIR}/luv_misc.o \
${BUILDDIR}/luv.o \
${BUILDDIR}/luvit_init.o \
${BUILDDIR}/lconstants.o \
${BUILDDIR}/lenv.o \
${BUILDDIR}/lyajl.o \
${BUILDDIR}/los.o \
${BUILDDIR}/luv_zlib.o \
${BUILDDIR}/lhttp_parser.o
DEPS= ${UVDIR}/libuv.a \
${CARESDIR}/libcares.a \
${HTTPDIR}/http_parser.o
ifeq (${USE_SYSTEM_LUAJIT},0)
DEPS+=${LUADIR}/src/libluajit.a
endif
ifeq (${USE_SYSTEM_SSL},0)
DEPS+=${SSLDIR}/libopenssl.a
endif
ifeq (${USE_SYSTEM_ZLIB},0)
DEPS+=${ZLIBDIR}/libz.a
endif
ifeq (${USE_SYSTEM_YAJL},0)
DEPS+=${YAJLDIR}/yajl.a
endif
BUNDLE_LIBS= $(shell ls lib/luvit/*.lua)
all: ${BUILDDIR}/luvit
${LUADIR}/Makefile:
git submodule update --init ${LUADIR}
${LUADIR}/src/libluajit.a: ${LUADIR}/Makefile
touch -c ${LUADIR}/src/*.h
$(MAKE) -C ${LUADIR}
${YAJLDIR}/CMakeLists.txt:
git submodule update --init ${YAJLDIR}
${YAJLDIR}/Makefile: deps/Makefile.yajl ${YAJLDIR}/CMakeLists.txt
cp deps/Makefile.yajl ${YAJLDIR}/Makefile
${YAJLDIR}/yajl.a: ${YAJLDIR}/Makefile
rm -rf ${YAJLDIR}/src/yajl
cp -r ${YAJLDIR}/src/api ${YAJLDIR}/src/yajl
$(MAKE) -C ${YAJLDIR}
${UVDIR}/Makefile:
git submodule update --init ${UVDIR}
${UVDIR}/libuv.a: ${UVDIR}/Makefile
$(MAKE) -C ${UVDIR}
${CARESDIR}/Makefile:
git submodule update --init --recursive
${CARESDIR}/libcares.a: ${CARESDIR}/Makefile
$(MAKE) -C ${CARESDIR}
${HTTPDIR}/Makefile:
git submodule update --init ${HTTPDIR}
${HTTPDIR}/http_parser.o: ${HTTPDIR}/Makefile
$(MAKE) -C ${HTTPDIR} http_parser.o
${ZLIBDIR}/zlib.gyp:
git submodule update --init ${ZLIBDIR}
${ZLIBDIR}/libz.a: ${ZLIBDIR}/zlib.gyp
cd ${ZLIBDIR} && ${CC} -c *.c && \
$(AR) rvs libz.a *.o && \
$(RANLIB) libz.a
${SSLDIR}/Makefile.openssl:
git submodule update --init ${SSLDIR}
${SSLDIR}/libopenssl.a: ${SSLDIR}/Makefile.openssl
$(MAKE) -C ${SSLDIR} -f Makefile.openssl
${BUILDDIR}/%.o: src/%.c ${DEPS}
mkdir -p ${BUILDDIR}
$(CC) ${CPPFLAGS} ${CFLAGS} --std=c89 -D_GNU_SOURCE -Wall -c $< -o $@ \
-I${CARESDIR}/include \
-I${HTTPDIR} -I${UVDIR}/include -I${CRYPTODIR}/src \
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 \
-DUSE_SYSTEM_SSL=${USE_SYSTEM_SSL} \
-DHTTP_VERSION=\"${HTTP_VERSION}\" \
-DUV_VERSION=\"${UV_VERSION}\" \
-DYAJL_VERSIONISH=\"${YAJL_VERSION}\" \
-DLUVIT_VERSION=\"${VERSION}\" \
-DLUAJIT_VERSION=\"${LUAJIT_VERSION}\"
${BUILDDIR}/libluvit.a: ${CRYPTODIR}/Makefile ${LUVLIBS} ${DEPS}
$(AR) rvs ${BUILDDIR}/libluvit.a ${LUVLIBS} ${DEPS}
$(RANLIB) ${BUILDDIR}/libluvit.a
${CRYPTODIR}/Makefile:
git submodule update --init ${CRYPTODIR}
${CRYPTODIR}/src/lcrypto.o: ${CRYPTODIR}/Makefile
${CC} ${CPPFLAGS} -c -o ${CRYPTODIR}/src/lcrypto.o -I${CRYPTODIR}/src/ \
-I${LUADIR}/src/ ${CRYPTODIR}/src/lcrypto.c
${BUILDDIR}/luvit: ${BUILDDIR}/libluvit.a ${BUILDDIR}/luvit_main.o ${CRYPTODIR}/src/lcrypto.o
$(CC) ${CPPFLAGS} ${CFLAGS} ${LDFLAGS} -o ${BUILDDIR}/luvit ${BUILDDIR}/luvit_main.o ${BUILDDIR}/libluvit.a \
${CRYPTODIR}/src/lcrypto.o ${LIBS}
clean:
${MAKE} -C ${LUADIR} clean
${MAKE} -C ${SSLDIR} -f Makefile.openssl clean
${MAKE} -C ${HTTPDIR} clean
${MAKE} -C ${YAJLDIR} clean
${MAKE} -C ${UVDIR} distclean
${MAKE} -C examples/native clean
-rm ${ZLIBDIR}/*.o ${ZLIBDIR}/*.a
-rm ${CARESDIR}/src/*.o ${CARESDIR}/*.a
-rm ${CRYPTODIR}/src/lcrypto.o
rm -rf build bundle
install: all
mkdir -p ${BINDIR}
install ${BUILDDIR}/luvit ${BINDIR}/luvit
mkdir -p ${LIBDIR}
cp lib/luvit/*.lua ${LIBDIR}
mkdir -p ${INCDIR}/http_parser
cp ${HTTPDIR}/http_parser.h ${INCDIR}/http_parser/
mkdir -p ${INCDIR}/uv
cp -r ${UVDIR}/include/* ${INCDIR}/uv/
cp src/*.h ${INCDIR}/
ifeq (${USE_SYSTEM_LUAJIT},0)
mkdir -p ${INCDIR}/luajit
cp ${LUADIR}/src/lua.h ${INCDIR}/luajit/
cp ${LUADIR}/src/lauxlib.h ${INCDIR}/luajit/
cp ${LUADIR}/src/luaconf.h ${INCDIR}/luajit/
cp ${LUADIR}/src/luajit.h ${INCDIR}/luajit/
cp ${LUADIR}/src/lualib.h ${INCDIR}/luajit/
endif
uninstall:
test -f ${BINDIR}/luvit && rm -f ${BINDIR}/luvit
test -d ${LIBDIR} && rm -rf ${LIBDIR}
test -d ${INCDIR} && rm -rf ${INCDIR}
bundle: bundle/luvit
bundle/luvit: build/luvit ${BUILDDIR}/libluvit.a ${BUNDLE_LIBS}
build/luvit tools/bundler.lua
cd bundle; $(CC) --std=c89 -g -Wall -Werror -c *.c
$(CC) --std=c89 -D_GNU_SOURCE -g -Wall -Werror -DBUNDLE -c src/luvit_exports.c -o bundle/luvit_exports.o -I${HTTPDIR} -I${UVDIR}/include -I${LUADIR}/src -I${YAJLDIR}/src/api -I${YAJLDIR}/src -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHTTP_VERSION=\"${HTTP_VERSION}\" -DUV_VERSION=\"${UV_VERSION}\" -DYAJL_VERSIONISH=\"${YAJL_VERSION}\" -DLUVIT_VERSION=\"${VERSION}\" -DLUAJIT_VERSION=\"${LUAJIT_VERSION}\"
$(CC) --std=c89 -D_GNU_SOURCE -g -Wall -Werror -DBUNDLE -c src/luvit_main.c -o bundle/luvit_main.o -I${HTTPDIR} -I${UVDIR}/include -I${LUADIR}/src -I${YAJLDIR}/src/api -I${YAJLDIR}/src -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHTTP_VERSION=\"${HTTP_VERSION}\" -DUV_VERSION=\"${UV_VERSION}\" -DYAJL_VERSIONISH=\"${YAJL_VERSION}\" -DLUVIT_VERSION=\"${VERSION}\" -DLUAJIT_VERSION=\"${LUAJIT_VERSION}\"
$(CC) ${LDFLAGS} -g -o bundle/luvit ${BUILDDIR}/libluvit.a `ls bundle/*.o` ${LIBS} ${CRYPTODIR}/src/lcrypto.o
# Test section
test: test-lua test-install test-uninstall
test-lua: ${BUILDDIR}/luvit
cd tests && ../${BUILDDIR}/luvit runner.lua
ifeq ($(MAKECMDGOALS),test)
DESTDIR=test_install
endif
test-install: install
test -f ${BINDIR}/luvit
test -d ${INCDIR}
test -d ${LIBDIR}
test-uninstall: uninstall
test ! -f ${BINDIR}/luvit
test ! -d ${INCDIR}
test ! -d ${LIBDIR}
api: api.markdown
api.markdown: $(wildcard lib/*.lua)
find lib -name "*.lua" | grep -v "luvit.lua" | sort | xargs -l luvit tools/doc-parser.lua > $@
DIST_DIR?=${HOME}/luvit.io/dist
DIST_NAME=luvit-${VERSION}
DIST_FOLDER=${DIST_DIR}/${VERSION}/${DIST_NAME}
DIST_FILE=${DIST_FOLDER}.tar.gz
dist_build:
sed -e 's/^VERSION=.*/VERSION=${VERSION}/' \
-e 's/^LUAJIT_VERSION=.*/LUAJIT_VERSION=${LUAJIT_VERSION}/' \
-e 's/^UV_VERSION=.*/UV_VERSION=${UV_VERSION}/' \
-e 's/^HTTP_VERSION=.*/HTTP_VERSION=${HTTP_VERSION}/' \
-e 's/^YAJL_VERSION=.*/YAJL_VERSION=${YAJL_VERSION}/' \
-e '/^WERROR/s/1/0/' < Makefile > Makefile.dist
sed -e 's/LUVIT_VERSION=".*/LUVIT_VERSION=\"${VERSION}\"'\'',/' \
-e 's/LUAJIT_VERSION=".*/LUAJIT_VERSION=\"${LUAJIT_VERSION}\"'\'',/' \
-e 's/UV_VERSION=".*/UV_VERSION=\"${UV_VERSION}\"'\'',/' \
-e 's/HTTP_VERSION=".*/HTTP_VERSION=\"${HTTP_VERSION}\"'\'',/' \
-e 's/YAJL_VERSIONISH=".*/YAJL_VERSIONISH=\"${YAJL_VERSION}\"'\'',/' < luvit.gyp > luvit.gyp.dist
tarball: dist_build
rm -rf ${DIST_FOLDER} ${DIST_FILE}
mkdir -p ${DIST_DIR}
git clone . ${DIST_FOLDER}
cp deps/gitmodules.local ${DIST_FOLDER}/.gitmodules
cd ${DIST_FOLDER} ; git submodule update --init
find ${DIST_FOLDER} -name ".git*" | xargs rm -r
mv Makefile.dist ${DIST_FOLDER}/Makefile
mv luvit.gyp.dist ${DIST_FOLDER}/luvit.gyp
tar -czf ${DIST_FILE} -C ${DIST_DIR}/${VERSION} ${DIST_NAME}
rm -rf ${DIST_FOLDER}
.PHONY: test install uninstall all api.markdown bundle tarball