-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
175 lines (159 loc) · 5.71 KB
/
Makefile
File metadata and controls
175 lines (159 loc) · 5.71 KB
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
default: all
# $@ is the target name
# $+ are the names of all dependencies
# Different platforms require different build flags.
UNAME = $(shell sh -c 'uname -s 2>/dev/null || echo none')
ifeq ($(UNAME),SunOS)
LDLIBS += -ldl -lsocket -lnsl
else
ifeq ($(UNAME),Darwin)
LDFLAGS += -Wl,-undefined -Wl,dynamic_lookup
LDLIBS += -ldl
else
ifeq ($(UNAME),Linux)
LDLIBS += -ldl
endif
endif
endif
LUASRC = dep/lua-5.2.4/src
all: modserver example
dep: \
$(LUASRC)/liblua.a \
$(LUASRC)/lua \
dep/posix.a \
dep/lpeg/lpeg.a \
api/c/modserver.o \
cutil.a
LUASTATIC = @./$(LUASRC)/lua dep/luastatic.lua
modserver: dep module
$(LUASTATIC) modserver.lua api/lua/modserver.lua config.lua \
http.lua module/*.lua util.lua \
api/c/modserver.o dep/posix.a dep/lpeg/lpeg.a cutil.a \
$(LUASRC)/liblua.a -I$(LUASRC) $(LDFLAGS) $(LDLIBS)
# Build dependencies
$(LUASRC)/liblua.a:
cd $(LUASRC) && \
$(MAKE) liblua.a CFLAGS="-O2 -Wall -DLUA_COMPAT_ALL -DLUA_USE_POSIX -DLUA_USE_DLOPEN"
$(LUASRC)/lua:
cd $(LUASRC) && \
$(MAKE) lua CFLAGS="-O2 -Wall -DLUA_COMPAT_ALL -DLUA_USE_POSIX -DLUA_USE_DLOPEN" \
LIBS="-lm $(LDLIBS)"
dep/posix.a: dep/luaposix/posix.c
cc -std=c99 -O2 -c -DLPOSIX_2001_COMPLIANT=1 $+ -Idep/luaposix -I$(LUASRC) \
-o dep/posix.o && ar rcs $@ dep/posix.o
dep/lpeg/lpeg.a:
cd dep/lpeg && $(MAKE) LUADIR=../../$(LUASRC)
api/c/modserver.o: api/c/modserver.c
cc -c -O2 -std=c99 $+ -Iapi/c -I$(LUASRC) -o $@
cutil.a: util.c
cc -c -std=c99 -O2 -I$(LUASRC) $+ -o cutil.o
ar rcs $@ cutil.o
# Modules
module: \
module/guile.so \
module/python.so \
module/ruby.so
module/guile.so: module/guile.c
cc -std=c99 -fPIC -shared $(LDFLAGS) $+ $(LDLIBS) -Iapi/c -I$(LUASRC) \
`guile-config compile` `guile-config link` -o $@ || true
module/python.so: PYTHON := $(shell pkg-config --cflags --libs python3)
module/python.so: module/python.c
cc -std=c99 -fPIC -shared $(LDFLAGS) $+ $(LDLIBS) -Iapi/c -I$(LUASRC) \
$(PYTHON) -o $@ || true
module/ruby.so: RUBY := $(shell \
pkg-config --cflags --libs ruby || \
pkg-config --cflags --libs ruby-2.2 || \
pkg-config --cflags --libs ruby-2.3 \
)
module/ruby.so: module/ruby.c
cc -std=c99 -fPIC -shared $(LDFLAGS) $+ $(LDLIBS) -Iapi/c -I$(LUASRC) \
$(RUBY) -o $@ || true
# Application Examples
example: CFLAGS = -std=c99 -fPIC -shared -Wall -Wextra -Iapi/c -Wno-unused-parameter
example: CPPFLAGS = -fPIC -shared -Wall -Wextra -Iapi/c -Wno-unused-parameter
example: example/c/hello.c.so \
example/c/test.c.so \
example/c/sleep.c.so \
example/c/arg.c.so \
example/c/file.c.so \
example/c/segfault.c.so \
example/c/content-length.c.so \
example/c++/hello.cpp.so \
example/crystal/hello.cr.so \
example/crystal/test.cr.so \
example/d/hello.d.so \
example/d/test.d.so \
example/go/hello.go.so \
example/go/test.go.so \
example/haskell/hello.hs.so \
example/nim/hello.nim.so \
example/nim/test.nim.so \
example/rust/hello.rs.so \
example/rust/test.rs.so
example/c/hello.c.so: example/c/hello.c
cc $(CFLAGS) $(LDFLAGS) $+ -o $@
example/c/test.c.so: example/c/test.c
cc $(CFLAGS) $(LDFLAGS) $+ -o $@
example/c/sleep.c.so: example/c/sleep.c
cc $(CFLAGS) $(LDFLAGS) $(LDFLAGS) $+ -o $@
example/c/arg.c.so: example/c/arg.c
cc $(CFLAGS) $(LDFLAGS) $(LDFLAGS) $+ -o $@
example/c/file.c.so: example/c/file.c
cc $(CFLAGS) $(LDFLAGS) $(LDFLAGS) $+ -o $@
example/c/segfault.c.so: example/c/segfault.c
cc $(CFLAGS) $(LDFLAGS) $(LDFLAGS) $+ -o $@
example/c/content-length.c.so: example/c/content-length.c
cc $(CFLAGS) $(LDFLAGS) $(LDFLAGS) $+ -o $@
example/c++/hello.cpp.so: example/c++/hello.cpp
c++ $(CPPFLAGS) $(LDFLAGS) $(LDFLAGS) $+ -o $@ || true
example/crystal/hello.cr.so: example/crystal/hello.cr
crystal build --single-module --link-flags="-shared" $+ -o $@ || true
example/crystal/test.cr.so: example/crystal/test.cr
crystal build --single-module --link-flags="-shared" $+ -o $@ || true
example/d/hello.d.so: example/d/hello.d
ldc2 -shared $+ -Iapi/d -od=example/d/ -of $@ || true
example/d/test.d.so: example/d/test.d
ldc2 -shared $+ -Iapi/d -od=example/d/ -of $@ || true
PWD = $(shell pwd)
GOPATH = $(PWD)/api/go
example/go/hello.go.so: example/go/hello.go
GOPATH=$(GOPATH) go build -buildmode=c-shared -o $@ $+ || true
example/go/test.go.so: example/go/test.go
GOPATH=$(GOPATH) go build -buildmode=c-shared -o $@ $+ || true
example/haskell/hello.hs.so: HASKELL := -L$(shell ghc --print-libdir)/rts \
-lHSrts-ghc$(shell ghc --numeric-version)
example/haskell/hello.hs.so: example/haskell/hello.hs example/haskell/hello_stub.c
ghc --make -dynamic -shared -fPIC -Iapi/c -I/usr/lib/ghc/include \
$(HASKELL) $+ -o $@ || true
example/nim/hello.nim.so: example/nim/hello.nim
nim compile --app:lib -p=api/nim --out=$@ $+ || true
example/nim/test.nim.so: example/nim/test.nim
nim compile --app:lib -p=api/nim --out=$@ $+ || true
example/rust/hello.rs.so: example/rust/hello.rs
rustc -C prefer-dynamic -C link-args="$(LDFLAGS)" $+ -o $@ || true
example/rust/test.rs.so: example/rust/test.rs
rustc -C prefer-dynamic -C link-args="$(LDFLAGS)" $+ -o $@ || true
# Commands
run: all
./modserver config.conf
test: all
TEST=1 ./modserver config.conf
INSTALL_TOP = /tmp/opt/modserver
install: modserver
mkdir -p $(INSTALL_TOP) $(INSTALL_TOP)/module
cp modserver config.conf $(INSTALL_TOP)
cp module/*.so $(INSTALL_TOP)/module
clean:
cd dep/lua-5.2.4 && $(MAKE) clean
cd dep/lpeg && $(MAKE) clean
rm -f modserver *.o *.so *.a module/*.so modserver.lua.c *.zip \
dep/*.o dep/*.a dep/*.so
find ./api/ ./example/ -name \*.so -o -name \*.o | xargs rm -f
luacheck:
luacheck modserver.lua api/lua/modserver.lua config.lua http.lua util.lua
slowloris:
./test/slowloris.pl -dns 127.0.0.1:8080
cloc:
cloc --quiet modserver.lua api/ module/ config.lua http.lua util.lua util.c
wrk:
wrk -c 10 -t 1 -d 10 "http://127.0.0.1:8080/example/lua/hello.lua"