-
Notifications
You must be signed in to change notification settings - Fork 61
/
Makefile
99 lines (75 loc) · 2.47 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
INST_PREFIX ?= /usr
INST_LIBDIR ?= $(INST_PREFIX)/lib/lua/5.1
INST_LUADIR ?= $(INST_PREFIX)/share/lua/5.1
INSTALL ?= install
UNAME ?= $(shell uname)
OR_EXEC ?= $(shell which openresty)
LUAROCKS_VER ?= $(shell luarocks --version | grep -E -o "luarocks [0-9]+.")
LUAJIT_DIR ?= $(shell ${OR_EXEC} -V 2>&1 | grep prefix | grep -Eo 'prefix=(.*)/nginx\s+--' | grep -Eo '/.*/')luajit
CFLAGS := -O2 -g -Wall -fpic -std=c99 -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast
C_SO_NAME := librestyradixtree.so
LDFLAGS := -shared
# on Mac OS X, one should set instead:
# for Mac OS X environment, use one of options
ifeq ($(UNAME),Darwin)
LDFLAGS := -bundle -undefined dynamic_lookup
C_SO_NAME := librestyradixtree.dylib
endif
MY_CFLAGS := $(CFLAGS) -DBUILDING_SO
MY_LDFLAGS := $(LDFLAGS) -fvisibility=hidden
OBJS := src/rax.o src/easy_rax.o
.PHONY: default
default: compile
### test: Run test suite. Use test=... for specific tests
.PHONY: test
test: compile
TEST_NGINX_LOG_LEVEL=info \
prove -I../test-nginx/lib -I. -r -s t/
### clean: Remove generated files
.PHONY: clean
clean:
rm -f $(C_SO_NAME) $(OBJS)
### compile: Compile library
.PHONY: compile
compile: $(C_SO_NAME)
${OBJS} : %.o : %.c
$(CC) $(MY_CFLAGS) -c $< -o $@
${C_SO_NAME} : ${OBJS}
$(CC) $(MY_LDFLAGS) $(OBJS) -o $@
### install: Install the library to runtime
.PHONY: install
install:
$(INSTALL) -d $(INST_LUADIR)/resty/
$(INSTALL) lib/resty/*.lua $(INST_LUADIR)/resty/
$(INSTALL) $(C_SO_NAME) $(INST_LIBDIR)/
### deps: Installation dependencies
.PHONY: deps
deps:
ifneq ($(LUAROCKS_VER),luarocks 3.)
luarocks install rockspec/lua-resty-radixtree-master-0-0.rockspec --tree=deps --only-deps --local
else
luarocks install --lua-dir=$(LUAJIT_DIR) rockspec/lua-resty-radixtree-master-0-0.rockspec --tree=deps --only-deps --local
endif
### lint: Lint Lua source code
.PHONY: lint
lint:
luacheck -q lib
### bench: Run benchmark
.PHONY: bench
bench:
resty -I=./lib -I=./deps/share/lua/5.1 benchmark/match-parameter.lua
@echo ""
resty -I=./lib -I=./deps/share/lua/5.1 benchmark/match-prefix.lua
@echo ""
resty -I=./lib -I=./deps/share/lua/5.1 benchmark/match-static.lua
@echo ""
resty -I=./lib -I=./deps/share/lua/5.1 benchmark/match-hosts.lua
@echo ""
resty -I=./lib -I=./deps/share/lua/5.1 benchmark/match-wildcard-hosts.lua
@echo ""
### help: Show Makefile rules
.PHONY: help
help:
@echo Makefile rules:
@echo
@grep -E '^### [-A-Za-z0-9_]+:' Makefile | sed 's/###/ /'