-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
155 lines (124 loc) · 4.59 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
# Debian package name & version
MAJOR_VER=0
MINOR_VER=2
PATCH_VER=3
PKG_NAME=borderpatrol
BUILD_VER=0${BUILD_NUMBER}-dev
# binaries
CC:=clang
LUAROCKS=luarocks
# nginx and lua modules
MODULE_PATH=${PWD}
MODULE_PKG_DIR=${MODULE_PATH}/pkg
CONTRIB_PATH=${MODULE_PATH}/contrib
NGINX_PATH=${CONTRIB_PATH}/nginx
NDK_PATH=${CONTRIB_PATH}/ngx_devel_kit
MEMC_NGINX_PATH=${CONTRIB_PATH}/memc-nginx-module
LUA_MODULE_PATH=${CONTRIB_PATH}/lua-nginx-module
ECHO_MODULE_PATH=${CONTRIB_PATH}/echo-nginx-module
STICKY_MODULE_PATH=${CONTRIB_PATH}/nginx-sticky-module-ng
HEADERS_MORE_MODULE_PATH=${CONTRIB_PATH}/headers-more-nginx-module
NGINX_MODULES=--add-module=${NDK_PATH} \
--add-module=${MEMC_NGINX_PATH} \
--add-module=${LUA_MODULE_PATH} \
--add-module=${STICKY_MODULE_PATH} \
--add-module=${HEADERS_MORE_MODULE_PATH} \
--add-module=${ECHO_MODULE_PATH} # only needed for
# build locations
BUILD_PATH=${MODULE_PATH}/build
DESTDIR=${PWD}/${PKG_NAME}
# packaging locations
CONF_DIR=/etc/${PKG_NAME}
SBIN_DIR=/usr/sbin
LOG_DIR=/var/log/${PKG_NAME}
SHARE_DIR=/usr/share/${PKG_NAME}
# test locations
TEST_DIR = ${MODULE_PATH}/t
TEST_RUN_DIR = ${TEST_DIR}/servroot
UNAME:=$(shell uname -s)
ifeq ($(UNAME), Darwin)
CFLAGS+="-I /usr/local/include -Wno-error"
LD_FLAGS+="-L /usr/local/lib -L /usr/lib -liconv"
endif
all: build
$(BUILD_PATH)/.install_rocks:
@$(LUAROCKS) install luajson --to=$(BUILD_PATH)/usr
@$(LUAROCKS) install luacrypto --to=$(BUILD_PATH)/usr
@$(LUAROCKS) install statsd --to=$(BUILD_PATH)/usr
@touch $(BUILD_PATH)/.install_rocks
build: submodules compile mkdirs $(BUILD_PATH)/.install_rocks
@cp ${NGINX_PATH}/objs/nginx ${BUILD_PATH}${SBIN_DIR}/${PKG_NAME}
@cp -rp ${PWD}/src/*.lua ${BUILD_PATH}${SHARE_DIR}
@cp ${PWD}/src/robots.txt ${BUILD_PATH}${SHARE_DIR}
@cp ${PWD}/src/config/nginx.conf.sample ${BUILD_PATH}${CONF_DIR}/sites-available/${PKG_NAME}.conf.sample
@cp ${PWD}/src/config/*.conf ${BUILD_PATH}${CONF_DIR}/
@cp ${PWD}/src/ssl/server.crt ${BUILD_PATH}${CONF_DIR}/ssl/server.crt
@cp ${PWD}/src/ssl/server.key ${BUILD_PATH}${CONF_DIR}/ssl/server.key
submodules:
git submodule init
git submodule update
mkdirs:
@mkdir -p ${BUILD_PATH}${CONF_DIR}/conf.d
@mkdir -p ${BUILD_PATH}${CONF_DIR}/sites-available
@mkdir -p ${BUILD_PATH}${CONF_DIR}/sites-enabled
@mkdir -p ${BUILD_PATH}${CONF_DIR}/ssl
@mkdir -p ${BUILD_PATH}${SHARE_DIR}
@mkdir -p ${BUILD_PATH}${CONF_DIR}
@mkdir -p ${BUILD_PATH}${SBIN_DIR}
@mkdir -p ${BUILD_PATH}${LOG_DIR}
compile: contrib
@if [ ! -f ${NGINX_PATH}/Makefile ]; then (cd ${NGINX_PATH} && \
./configure --prefix=/usr \
--sbin-path=${SBIN_DIR}/borderpatrol \
--conf-path=${CONF_DIR}/borderpatrol.conf \
--pid-path=/var/run/borderpatrol.pid \
--error-log-path=${LOG_DIR}/error.log \
--http-log-path=${LOG_DIR}/access.log \
${NGINX_MODULES} \
--with-ld-opt=${LD_FLAGS} \
--with-cc-opt=${CFLAGS} \
--with-http_ssl_module); \
fi;
@(cd ${NGINX_PATH} && make -j2)
test: build
@TEST_NGINX_BINARY=${PKG_NAME} PATH=${BUILD_PATH}${SBIN_DIR}:${PATH} prove -r ${TEST_DIR}/*.t
mocktest: build
god -Dbc t/borderpatrol.god
clean:
rm -rf ${BUILD_PATH}
rm -rf ${DESTDIR}
rm -rf ngx_borderpatrol*
rm -rf *.deb
distclean: clean
(cd ${NGINX_PATH} && if [ -f Makefile ]; then make clean; fi;)
pkg: test
# copy the build target dir to the package dir
rm -rf ${DESTDIR}
mv ${BUILD_PATH} ${DESTDIR}
# Install configs under /etc/borderpatrol
cp ${MODULE_PKG_DIR}/borderpatrol.conf ${DESTDIR}${CONF_DIR}/borderpatrol.conf
chmod 0600 ${DESTDIR}${CONF_DIR}/borderpatrol.conf
chmod 0600 ${DESTDIR}${CONF_DIR}/sites-available/*
# Install package hooks
cp ${MODULE_PKG_DIR}/after-install.sh ${DESTDIR}
# Setup upstart config
mkdir -p ${DESTDIR}/etc/init.d
cp ${MODULE_PKG_DIR}/borderpatrol.init ${DESTDIR}/etc/init.d/borderpatrol
chmod 755 ${DESTDIR}/etc/init.d/borderpatrol
# Create extra directories
mkdir -p ${DESTDIR}/var/borderpatrol
mkdir -p ${DESTDIR}/var/cache/borderpatrol
##########################################################################
# create the borderpatrol package
# install fpm if needed
test -n "$(shell gem query --local fpm|grep fpm)" || gem install fpm
cd ${DESTDIR} && fpm -s dir -t deb -n borderpatrol -v ${MAJOR_VER}.${MINOR_VER}.${PATCH_VER}-${BUILD_VER} -C ${DESTDIR} \
-p borderpatrol-VERSION_ARCH.deb \
--after-install after-install.sh \
-d libssl1.0.0 \
-d luarocks \
usr/ etc/ var/
mv ${DESTDIR}/*.deb ${PWD}/
doc:
dot -Tpng -odoc/borderpatrol.png doc/borderpatrol.dot
.PHONY : test build mocktest mkdirs submodules build pkg distclean clean compile all doc