forked from kernelsauce/turbo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
executable file
·201 lines (184 loc) · 6.7 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
########
## Turbo.lua Makefile for installation.
## Copyright (C) 2013 John Abrahamsen.
## See LICENSE file for license information.
########
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
CC= gcc
ifeq ($(uname_S),Darwin)
CC= clang
endif
RM= rm -f
UNINSTALL= rm -rf
MKDIR= mkdir -p
RMDIR= rmdir 2>/dev/null
SYMLINK= ln -sf
INSTALL_X= install -m 0755
INSTALL_F= install -m 0644
CP_R= cp -r
LDCONFIG= ldconfig -n
TAR = tar -zcvf
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
ALL_LUA_FILES := $(call rwildcard,./,*.lua)
ALL_LUAC_FILES := $(call rwildcard,./,*.luac)
MAJVER= 2
MINVER= 1
MICVER= 3
TVERSION= $(MAJVER).$(MINVER).$(MICVER)
PREFIX ?= /usr/local
TDEPS= deps
HTTP_PARSERDIR = $(TDEPS)/http-parser
INSTALL_LIB= $(PREFIX)/lib
INSTALL_BIN= $(PREFIX)/bin
TEST_DIR = tests
PACKAGE_DIR = package/turbo
LUA_MODULEDIR = $(PREFIX)/share/lua/5.1
LUA_LIBRARYDIR = $(PREFIX)/lib/lua/5.1
LUAJIT_VERSION?=2.0.4
LUAJIT_LIBRARYDIR = $(PREFIX)/lib/lua/5.1
LUAJIT_MODULEDIR = $(PREFIX)/share/luajit-$(LUAJIT_VERSION)
INC = -I$(HTTP_PARSERDIR)/
CFLAGS = -O3 -Wall -g
MYCFLAGS = $(CFLAGS)
MYCPPFLAGS = $(CPPFLAGS)
MYLDFLAGS = $(LDFLAGS)
# For Windows builds.
INSTALL_TFFI_WRAP_SOSHORT= libtffi_wrap.dll
ifeq ($(uname_S),Linux)
INSTALL_TFFI_WRAP_SOSHORT= libtffi_wrap.so
MYCPPFLAGS += -fPIC
endif
ifeq ($(uname_S),Darwin)
INSTALL_TFFI_WRAP_SOSHORT= libtffi_wrap.dylib
MYCPPFLAGS += -I/usr/include/malloc
endif
INSTALL_TFFI_WRAP_SONAME= $(INSTALL_TFFI_WRAP_SOSHORT).$(TVERSION)
INSTALL_TFFI_WRAP_DYN= $(INSTALL_LIB)/$(INSTALL_TFFI_WRAP_SONAME)
INSTALL_TFFI_WRAP_SHORT= $(INSTALL_LIB)/$(INSTALL_TFFI_WRAP_SOSHORT)
ifeq ($(SSL), axTLS)
# axTLS only uses axtls lib from luajit
# Don't link with crypto or ssl if using axTLS
# C wrapper needs TURBO_NO_SSL set in order
# to not include any of the OpenSSL wrapper
MYCPPFLAGS += -DTURBO_NO_SSL=1
endif
ifeq ($(SSL), none)
# No SSL option.
MYCPPFLAGS += -DTURBO_NO_SSL=1
endif
ifeq ($(SSL),)
# Default to OpenSSL
SSL=openssl
endif
ifeq ($(SSL), openssl)
# Link OpenSSL
MYLDFLAGS += -lcrypto -lssl
endif
all:
$(MAKE) -C deps/http-parser library
$(CC) $(INC) -shared $(MYCFLAGS) $(MYCPPFLAGS) $(HTTP_PARSERDIR)/libhttp_parser.o $(TDEPS)/turbo_ffi_wrap.c -o $(INSTALL_TFFI_WRAP_SOSHORT) $(MYLDFLAGS)
clean:
$(MAKE) -C deps/http-parser clean
$(RM) $(INSTALL_TFFI_WRAP_SOSHORT)
rm -rf $(PACKAGE_DIR)
$(RM) $(ALL_LUAC_FILES)
rm -rf *.dSYM
uninstall:
@echo "==== Uninstalling Turbo.lua ===="
ifeq ($(uname_S),Linux)
$(UNINSTALL) $(INSTALL_TFFI_WRAP_SHORT) $(INSTALL_TFFI_WRAP_DYN)
$(LDCONFIG) $(INSTALL_LIB)
endif
ifeq ($(uname_S),Darwin)
$(UNINSTALL) $(INSTALL_TFFI_WRAP_SHORT)
endif
$(UNINSTALL) $(LUA_MODULEDIR)/turbo/
$(UNINSTALL) $(LUAJIT_MODULEDIR)/turbo/
$(UNINSTALL) $(INSTALL_BIN)/turbovisor
$(RM) $(LUA_MODULEDIR)/turbo.lua
$(RM) $(LUAJIT_MODULEDIR)/turbo.lua
$(RM) $(LUAJIT_MODULEDIR)/turbovisor.lua
@echo "==== Turbo.lua uinstalled. Welcome back. ===="
install:
@echo "==== Installing Turbo.lua v$(TVERSION) to: ===="
@echo "==== $(LUAJIT_LIBRARYDIR) and ===="
@echo "==== $(LUAJIT_MODULEDIR) ===="
$(MKDIR) $(INSTALL_LIB)
$(MKDIR) $(INSTALL_BIN)
$(MKDIR) $(LUA_MODULEDIR)/turbo
$(MKDIR) $(LUAJIT_MODULEDIR)/turbo
$(CP_R) turbo/* $(LUA_MODULEDIR)/turbo
$(CP_R) turbo.lua $(LUA_MODULEDIR)
$(CP_R) turbovisor.lua $(LUA_MODULEDIR)
$(CP_R) turbo/* $(LUAJIT_MODULEDIR)/turbo
$(CP_R) turbo.lua $(LUAJIT_MODULEDIR)
$(CP_R) turbovisor.lua $(LUAJIT_MODULEDIR)
$(INSTALL_X) bin/turbovisor $(INSTALL_BIN)
@echo "==== Building 3rdparty modules ===="
make -C deps/http-parser library
$(CC) $(INC) -shared $(MYCFLAGS) $(MYCPPFLAGS) $(HTTP_PARSERDIR)/libhttp_parser.o $(TDEPS)/turbo_ffi_wrap.c -o $(INSTALL_TFFI_WRAP_SOSHORT) $(MYLDFLAGS)
@echo "==== Installing libtffi_wrap ===="
ifeq ($(uname_S),Linux)
test -f $(INSTALL_TFFI_WRAP_SOSHORT) && \
$(INSTALL_X) $(INSTALL_TFFI_WRAP_SOSHORT) $(INSTALL_TFFI_WRAP_DYN) && \
$(LDCONFIG) $(INSTALL_LIB) && \
$(SYMLINK) $(INSTALL_TFFI_WRAP_SONAME) $(INSTALL_TFFI_WRAP_SHORT)
endif
ifeq ($(uname_S),Darwin)
$(INSTALL_X) $(INSTALL_TFFI_WRAP_SOSHORT) $(INSTALL_TFFI_WRAP_SHORT)
endif
@echo "==== Successfully installed Turbo.lua $(TVERSION) to $(PREFIX) ===="
bytecode:
@echo "==== Creating bytecode for Turbo.lua v$(TVERSION) ===="
for f in $(ALL_LUA_FILES); do \
luajit -b -g "$$f" "$$f"c; \
done
@echo "==== Successfully created bytecode for Turbo.lua v$(TVERSION) ===="
minimize: bytecode
rm -rf package
@echo "==== Creating minimal Turbo.lua v$(TVERSION) ===="
$(MKDIR) $(PACKAGE_DIR)/turbo/structs
$(CP_R) $(INSTALL_TFFI_WRAP_SOSHORT) $(PACKAGE_DIR)
$(CP_R) turbo.luac $(PACKAGE_DIR)
$(CP_R) turbovisor.luac $(PACKAGE_DIR)
$(CP_R) turbo/*.luac $(PACKAGE_DIR)/turbo
$(CP_R) turbo/structs/*.luac $(PACKAGE_DIR)/turbo/structs
$(MKDIR) $(PACKAGE_DIR)/turbo/3rdparty/middleclass
$(CP_R) turbo/3rdparty/*.luac $(PACKAGE_DIR)/turbo/3rdparty/
$(CP_R) turbo/3rdparty/middleclass/*.luac $(PACKAGE_DIR)/turbo/3rdparty/middleclass
rename "s/\.luac$$/\.lua/" $(PACKAGE_DIR)/*.luac $(PACKAGE_DIR)/turbo/*.luac $(PACKAGE_DIR)/turbo/3rdparty/*.luac $(PACKAGE_DIR)/turbo/3rdparty/middleclass/*.luac $(PACKAGE_DIR)/turbo/structs/*.luac
@echo "==== Successfully created minimal Turbo.lua $(TVERSION) ===="
bcodeinstall: package
@echo "==== Installing Turbo.lua v$(TVERSION) by bytecode to: ===="
@echo "==== $(LUAJIT_LIBRARYDIR) and ===="
@echo "==== $(LUAJIT_MODULEDIR) ===="
$(MKDIR) $(INSTALL_LIB)
$(MKDIR) $(LUA_MODULEDIR)/turbo
$(MKDIR) $(LUAJIT_MODULEDIR)/turbo
$(CP_R) package/turbo/* $(LUA_MODULEDIR)
$(CP_R) package/turbo/* $(LUAJIT_MODULEDIR)
$(INSTALL_X) bin/turbovisor $(INSTALL_BIN)
@echo "==== Building 3rdparty modules ===="
make -C deps/http-parser library
$(CC) $(INC) -shared $(MYCFLAGS) $(MYCPPFLAGS) $(HTTP_PARSERDIR)/libhttp_parser.o $(TDEPS)/turbo_ffi_wrap.c -o $(INSTALL_TFFI_WRAP_SOSHORT) $(MYLDFLAGS)
@echo "==== Installing libturbo_parser ===="
test -f $(INSTALL_TFFI_WRAP_SOSHORT) && \
$(INSTALL_X) $(INSTALL_TFFI_WRAP_SOSHORT) $(INSTALL_TFFI_WRAP_DYN) && \
$(LDCONFIG) $(INSTALL_LIB) && \
$(SYMLINK) $(INSTALL_TFFI_WRAP_SONAME) $(INSTALL_TFFI_WRAP_SHORT)
@echo "==== Successfully installed Turbo.lua $(TVERSION) to $(PREFIX) ===="
package: all minimize
@echo "==== Packaging minimal Turbo.lua v$(TVERSION) ===="
$(TAR) turbo.$(MAJVER).$(MINVER).$(MICVER).tar.gz package
@echo "==== Created turbo.$(MAJVER).$(MINVER).$(MICVER).tar.gz package: ===="
md5sum turbo.$(MAJVER).$(MINVER).$(MICVER).tar.gz
test:
@echo "==== Running tests for Turbo.lua. NOTICE: busted module is required ===="
export TURBO_TEST_SSL=1; valgrind busted
luajit examples/helloworld.lua &
sleep 1
wget http://127.0.0.1:8888/
test -f index.html
rm -f index.html
pkill luajit
@echo "==== Successfully ran all tests for Turbo.lua $(TVERSION) ===="