-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
171 lines (144 loc) · 4.97 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
ifndef FIFTYONEDEGREES_NGINX_VERSION
VERSION := 1.20.0
else
VERSION := $(FIFTYONEDEGREES_NGINX_VERSION)
endif
ifndef DONT_CLEAN_TESTS
CLEANTESTS := 1
else
CLEANTESTS := 0
endif
TESTS := tests/51degrees.t
$(eval $(API):;@:)
ifneq (test,$(firstword $(MAKECMDGOALS)))
API := hash
ARGS := -std=gnu11 -Wall -Wno-unused-variable -Wno-missing-braces
endif
FULLPATH := $(shell pwd)
ifndef FIFTYONEDEGREES_DATAFILE
DATAFILE := 51Degrees-LiteV4.1.hash
else
DATAFILE := $(FIFTYONEDEGREES_DATAFILE)
endif
MODULEPATH := $(FULLPATH)/build/modules/ngx_http_51D_module.so
FILEPATH := $(FULLPATH)/device-detection-cxx/device-detection-data/$(DATAFILE)
ifndef STATIC_BUILD
MODULE_ARG := --add-dynamic-module
else
MODULE_ARG := --add-module
endif
.PHONY hash:
clean:
if [ -d "51Degrees_module/src" ]; then \
rm -rf 51Degrees_module/src; \
fi
if [ -d "build" ]; then \
rm -rf build; \
fi
if [ -f "nginx" ]; then \
rm -f nginx; \
fi
if [ -f "vendor/nginx-$(VERSION)/Makefile" ]; then \
cd $(CURDIR)/vendor/nginx-$(VERSION) && make clean; \
fi
if [ "$(CLEANTESTS)" -eq "1" ]; then \
if [ -d "tests/nginx-tests" ]; then \
rm -r tests/nginx-tests; \
fi; \
fi;
build: clean
mkdir -p 51Degrees_module/src/hash
mkdir -p 51Degrees_module/src/common-cxx
exit
cp module_conf/$(API)_config 51Degrees_module/config
cp device-detection-cxx/src/*.c 51Degrees_module/src/
cp device-detection-cxx/src/*.h 51Degrees_module/src/
cp device-detection-cxx/src/hash/*.c 51Degrees_module/src/hash/
cp device-detection-cxx/src/hash/*.h 51Degrees_module/src/hash/
cp device-detection-cxx/src/common-cxx/*.c 51Degrees_module/src/common-cxx/
cp device-detection-cxx/src/common-cxx/*.h 51Degrees_module/src/common-cxx/
get-source:
if [ ! -d "vendor" ]; then mkdir vendor; fi
cd vendor && curl -L -O "http://nginx.org/download/nginx-$(VERSION).tar.gz"
cd vendor && tar xzf "nginx-$(VERSION).tar.gz"
configure: build
if [ ! -d "vendor/nginx-$(VERSION)" ]; then $(MAKE) get-source; fi
cd $(CURDIR)/vendor/nginx-$(VERSION) && \
./configure \
--prefix=$(CURDIR)/build \
--with-ld-opt="-lm -latomic $(MEM_LD_FLAGS)" \
$(MODULE_ARG)=$(CURDIR)/51Degrees_module \
--with-compat \
--with-cc-opt="$(ARGS) $(MEM_CC_FLAGS)" \
--with-debug \
--sbin-path=$(CURDIR) \
--conf-path="nginx.conf" \
--with-http_sub_module
configure-no-module: clean
if [ ! -d "vendor/nginx-$(VERSION)" ]; then $(MAKE) get-source; fi
cd $(CURDIR)/vendor/nginx-$(VERSION) && \
./configure \
--prefix=$(CURDIR)/build \
--with-compat \
--with-debug \
--sbin-path=$(CURDIR) \
--conf-path="nginx.conf" \
--with-http_sub_module
install: configure
cd $(CURDIR)/vendor/nginx-$(VERSION) && make install
sed "/\/\*\*/,/\*\//d" examples/$(API)/gettingStarted.conf > build/nginx.conf
sed -i "s!%%DAEMON_MODE%%!on!g" build/nginx.conf
sed -i "s!%%MODULE_PATH%%!!g" build/nginx.conf
sed -i "s!%%FILE_PATH%%!$(FILEPATH)!g" build/nginx.conf
sed -i "s!%%TEST_GLOBALS%%!!g" build/nginx.conf
sed -i "s!%%TEST_GLOBALS_HTTP%%!!g" build/nginx.conf
echo > build/html/$(API)
install-no-module: configure-no-module
cd $(CURDIR)/vendor/nginx-$(VERSION) && make install
module: configure
cd $(CURDIR)/vendor/nginx-$(VERSION) && make modules
if [ ! -d "build/modules" ]; then mkdir -p build/modules; fi
cp $(CURDIR)/vendor/nginx-$(VERSION)/objs/*.so build/modules
all-versions:
mkdir modules
$(foreach version, \
1.19.0 1.19.5 1.19.8 1.20.0, \
$(MAKE) module VERSION=$(version); \
mv build/modules/ngx_http_51D_module.so modules/ngx_http_51D_hash_module-$(version).so;)
set-mem:
$(eval MEM_CC_FLAGS := -O0 -g -fsanitize=address)
$(eval MEM_LD_FLAGS := -g -fsanitize=address)
mem-check: set-mem install
test-prep:
if [ ! -f "tests/nginx-tests/lib/Test/Nginx.pm" ]; then \
if ls tests/nginx-tests* 1> /dev/null 2>&1; then \
rm -r tests/nginx-tests*; \
fi; \
cd tests && curl -L -O "http://hg.nginx.org/nginx-tests/archive/tip.tar.gz"; \
tar zxf tip.tar.gz; \
mv nginx-tests* nginx-tests; \
fi;
test-full:
$(MAKE) test TESTS="$(TESTS) tests/nginx-tests"
test-examples: test-prep
ifeq (,$(wildcard $(FULLPATH)/nginx))
$(error Local binary must be built first (use "make install"))
else
$(eval CMD := TEST_NGINX_BINARY="$(FULLPATH)/nginx" TEST_MODULE_PATH="$(FULLPATH)/build/" TEST_FILE_PATH="$(FILEPATH)" ASAN_OPTIONS=detect_odr_violation=0 LSAN_OPTIONS=suppressions=suppressions.txt prove $(FIFTYONEDEGREES_FORMATTER) -v tests/examples :: $(DATAFILE))
ifdef FIFTYONEDEGREES_TEST_OUTPUT
$(CMD) > $(FIFTYONEDEGREES_TEST_OUTPUT)
else
$(CMD)
endif
endif
test: test-prep
ifeq (,$(wildcard $(FULLPATH)/nginx))
$(error Local binary must be built first (use "make install"))
else
$(eval CMD := TEST_NGINX_BINARY="$(FULLPATH)/nginx" TEST_NGINX_GLOBALS="load_module $(MODULEPATH);" TEST_NGINX_GLOBALS_HTTP="51D_file_path $(FILEPATH);" ASAN_OPTIONS=detect_odr_violation=0 LSAN_OPTIONS=suppressions=suppressions.txt prove $(FIFTYONEDEGREES_FORMATTER) -v $(TESTS) :: $(DATAFILE))
ifdef FIFTYONEDEGREES_TEST_OUTPUT
$(CMD) > $(FIFTYONEDEGREES_TEST_OUTPUT)
else
$(CMD)
endif
endif