Project

General

Profile

Statistics
| Branch: | Revision:

gdp-router-click / Makefile @ master

History | View | Annotate | Download (13.6 KB)

1
# For a gdp-router-click installation from the source:
2
#
3
#   invoke "adm/install-gdp-router-click.sh", which will leverage this
4
#   Makefile to git the correct version of click, configure userlevel
5
#   click, compile, install, and set up gdp-router-click service on
6
#   the current host.
7
#
8
# For a gdp-router-click2 installation from the source: work in progress
9
#
10

    
11
GDP_BLD=			build/gdp
12
GDP_REPO=			https://repoman@repo.eecs.berkeley.edu/git-anon/projects/swarmlab/gdp.git
13

    
14
GDP_NET3_BRANCH=	net3-legacy
15

    
16
CLICK_BLD=			build/click
17
CLICK_REPO=			https://github.com/kohler/click.git
18
CLICK_M=			${CLICK_BLD}/Makefile
19

    
20
# major version
21
VERSION=			2
22
VERHH=				version_gdp_v4_router.hh
23
S_VERHH=			src/${VERHH}
24

    
25
# userlevel workspace
26
CLICK_UL_M=			${CLICK_BLD}/userlevel/Makefile
27
UL_M_O=				ul_m_orig
28
CLICK_UL_M_O=		${CLICK_BLD}/userlevel/Makefile.$(UL_M_O)
29
CLICK_UL_BINARY=	$(CLICK_BLD)/userlevel/click
30
CLICK_ELEMS_LOCAL=	${CLICK_BLD}/elements/local
31

    
32
# linuxmodule workspace
33
CLICK_LM_PATCH=		${CLICK_BLD}/click.git_apply_patch.linuxmodule_target
34
UNAME_R=			$(shell /bin/uname -r)
35
GDP_LM_PATCH=		adm/click.git_apply_patch.linuxmodule_target
36

    
37
# builds with the latest Click, unless the next line is uncommented and updated
38
#CLICK_COMMIT=	f40363bb492188d44ba2f1251d2fe5dc553b97c9
39

    
40
# default
41
all: gdp-router-click2
42

    
43
# no target should survive recipe errors
44
.DELETE_ON_ERROR:
45

    
46
remove_gdp:
47
	@if [ -d "${GDP_BLD}" ]; \
48
	then \
49
		echo "Removing ${GDP_BLD}" ; \
50
		rm -rf ${GDP_BLD} ; \
51
	else \
52
		echo "${GDP_BLD} not found" ; \
53
	fi
54

    
55
remove_click:
56
	@if [ -d "${CLICK_BLD}" ]; \
57
	then \
58
		echo "Removing ${CLICK_BLD}" ; \
59
		rm -rf ${CLICK_BLD} ; \
60
	else \
61
		echo "${CLICK_BLD} not found" ; \
62
	fi
63

    
64
#
65
# (default) set up a userlevel workspace then build gdp-router-click
66
#
67

    
68
.PHONY: unconfigure_userlevel install stop start reinstall clean
69

    
70
configure_userlevel:
71
	@test ! -e configure_userlevel2 || \
72
		{ echo "WARN: detected userlevel2 config, command ignored."; exit 1; }
73
	@test ! -e configure_linuxmodule || \
74
		{ echo "WARN: detected linuxmodule config, command ignored."; exit 1; }
75
	@if [ -d ${GDP_BLD} ]; \
76
	then \
77
		echo "Error: pre-existing ${GDP_BLD} (make remove_gdp)" ; \
78
		exit 1 ; \
79
	fi
80
	@if [ -d ${CLICK_BLD} ]; \
81
	then \
82
		echo "Error: pre-existing ${CLICK_BLD} (make remove_click)" ; \
83
		exit 1 ; \
84
	fi
85
	@git clone ${GDP_REPO} ${GDP_BLD} && \
86
			( cd ${GDP_BLD} && git checkout ${GDP_NET3_BRANCH} && make && make )
87
	@if [ -z "${CLICK_COMMIT}" ]; \
88
	then \
89
		git clone --depth 1 ${CLICK_REPO} ${CLICK_BLD} ; \
90
	else \
91
		git clone -n ${CLICK_REPO} ${CLICK_BLD} && \
92
				( cd ${CLICK_BLD} && git checkout ${CLICK_COMMIT} ) ; \
93
	fi
94
	ln src/gdp_router_nat.hh ${CLICK_ELEMS_LOCAL}/gdp_router_nat.hh
95
	ln src/gdp_router_nat.cc ${CLICK_ELEMS_LOCAL}/gdp_router_nat.cc
96
	@test -r ${CLICK_UL_M_O} || \
97
		( cd ${CLICK_BLD} ; \
98
		  ./configure --disable-linuxmodule --enable-local ; \
99
		  make elemlist ; \
100
		  sed -i.${UL_M_O} \
101
			-e '/^OBJS = /s/$$/ \.\.\/\.\.\/gdp\/libs\/libgdp.a \.\.\/\.\.\/gdp\/libs\/libep.a /' \
102
			-e '/^LIBS = /s/$$/ -lpthread -levent -levent_pthreads -ljansson -luuid -lssl -lcrypto -lavahi-common -lavahi-client -lsystemd/' \
103
			-e 's/-I\$$(top_srcdir) /-I\$$(top_srcdir) -I\.\.\/\.\.\/gdp\/ /' \
104
			-e 's/CXXFLAGS = -g -O2 -W -Wall/CXXFLAGS = -g -O2 -W -Wall -fno-strict-aliasing/' \
105
				userlevel/Makefile )
106
	@touch configure_userlevel
107

    
108
unconfigure_userlevel:
109
	@test ! -e configure_userlevel2 || \
110
		{ echo "WARN: detected userlevel2 config, command ignored."; exit 1; }
111
	@test ! -e configure_linuxmodule || \
112
		{ echo "WARN: detected linuxmodule config, command ignored."; exit 1; }
113
	@if [ -d ${GDP_BLD} ]; \
114
	then \
115
		echo "Remove ${GDP_BLD}..." ; \
116
		rm -rf ${GDP_BLD} ; \
117
	else \
118
		echo "${GDP_BLD} not found" ; \
119
	fi
120
	@if [ -d ${CLICK_BLD} ]; \
121
	then \
122
		echo "Remove ${CLICK_BLD}..." ; \
123
		rm -rf ${CLICK_BLD} ; \
124
	else \
125
		echo "${CLICK_BLD} not found" ; \
126
	fi
127
	@rm -f configure_userlevel
128

    
129
gdp-router-click: configure_userlevel src/*.hh src/*.cc
130
	@test ! -e configure_userlevel2 || \
131
		{ echo "WARN: detected userlevel2 config, command ignored."; exit 1; }
132
	@test ! -e configure_linuxmodule || \
133
		{ echo "WARN: detected linuxmodule config, command ignored."; exit 1; }
134
	@echo "Refresh source hardlinks in ${CLICK_BLD} (required post git pull)"
135
	@ln -f src/gdp_router_nat.hh ${CLICK_ELEMS_LOCAL}/gdp_router_nat.hh
136
	@ln -f src/gdp_router_nat.cc ${CLICK_ELEMS_LOCAL}/gdp_router_nat.cc
137
	@( cd $(CLICK_BLD) && make )
138
	@cp -p ${CLICK_UL_BINARY} $@
139

    
140
install: gdp-router-click
141
	@test ! -e configure_userlevel2 || \
142
		{ echo "WARN: detected userlevel2 config, command ignored."; exit 1; }
143
	@test ! -e configure_linuxmodule || \
144
		{ echo "WARN: detected linuxmodule config, command ignored."; exit 1; }
145
	cp -p ./gdp-router-click /usr/sbin/gdp-router-click
146
	chmod 755 /usr/sbin/gdp-router-click
147
	chown gdp:gdp /usr/sbin/gdp-router-click
148

    
149
stop:
150
	@test ! -e configure_userlevel2 || \
151
		{ echo "WARN: detected userlevel2 config, command ignored."; exit 1; }
152
	@test ! -e configure_linuxmodule || \
153
		{ echo "WARN: detected linuxmodule config, command ignored."; exit 1; }
154
	systemctl stop gdplogd
155
	systemctl stop gdp-router-click
156

    
157
start:
158
	@test ! -e configure_userlevel2 || \
159
		{ echo "WARN: detected userlevel2 config, command ignored."; exit 1; }
160
	@test ! -e configure_linuxmodule || \
161
		{ echo "WARN: detected linuxmodule config, command ignored."; exit 1; }
162
	systemctl start gdp-router-click
163
	systemctl start gdplogd
164

    
165
reinstall: gdp-router-click
166
	@test ! -e configure_userlevel2 || \
167
		{ echo "WARN: detected userlevel2 config, command ignored."; exit 1; }
168
	@test ! -e configure_linuxmodule || \
169
		{ echo "WARN: detected linuxmodule config, command ignored."; exit 1; }
170
	systemctl stop gdplogd
171
	systemctl stop gdp-router-click
172
	cp -p ./gdp-router-click /usr/sbin/gdp-router-click
173
	chmod 755 /usr/sbin/gdp-router-click
174
	chown gdp:gdp /usr/sbin/gdp-router-click
175
	systemctl start gdp-router-click
176
	systemctl start gdplogd
177

    
178
clean:
179
	@test ! -e configure_userlevel2 || \
180
		{ echo "WARN: detected userlevel2 config, command ignored."; exit 1; }
181
	@test ! -e configure_linuxmodule || \
182
		{ echo "WARN: detected linuxmodule config, command ignored."; exit 1; }
183
	@test ! -r ${CLICK_M} || ( cd $(CLICK_BLD) && make clean )
184
	@rm -f ${CLICK_UL_BINARY} gdp-router-click gdp-router-click*.deb README.html
185

    
186
#
187
# (non-default) set up a userlevel2 workspace then build gdp-router-click2
188
#
189

    
190
.PHONY: unconfigure_userlevel2 install2 install-gdp-router-click2
191
.PHONY: stop2 start2 reinstall2
192

    
193
configure_userlevel2:
194
	@test ! -e configure_userlevel || \
195
		{ echo "WARN: detected userlevel config, command ignored."; exit 1; }
196
	@test ! -e configure_linuxmodule || \
197
		{ echo "WARN: detected linuxmodule config, command ignored."; exit 1; }
198
	@if [ ! -d ${GDP_BLD} ]; \
199
	then \
200
		git clone ${GDP_REPO} ${GDP_BLD} ; \
201
	fi
202
	@( cd ${GDP_BLD}/util && make )
203
	@if [ -d ${CLICK_BLD} ]; \
204
	then \
205
		echo "Error: pre-existing ${CLICK_BLD} (make remove_click)" ; \
206
		exit 1 ; \
207
	fi
208
	@if [ -z "${CLICK_COMMIT}" ]; \
209
	then \
210
		git clone --depth 1 ${CLICK_REPO} ${CLICK_BLD} ; \
211
	else \
212
		git clone -n ${CLICK_REPO} ${CLICK_BLD} && \
213
				( cd ${CLICK_BLD} && git checkout ${CLICK_COMMIT} ) ; \
214
	fi
215
	ln src/gdp_v4_router.hh ${CLICK_ELEMS_LOCAL}/gdp_v4_router.hh
216
	ln src/gdp_v4_router.cc ${CLICK_ELEMS_LOCAL}/gdp_v4_router.cc
217
	@test -r ${CLICK_UL_M_O} || \
218
		( cd ${CLICK_BLD} ; \
219
		  ./configure --disable-linuxmodule --enable-local ; \
220
		  make elemlist ; \
221
		  sed -i.${UL_M_O} \
222
			-e '/^LIBS = /s/$$/ -lssl -lcrypto -lsystemd -lresolv /' \
223
			-e 's/CXXFLAGS = -g -O2 -W -Wall/CXXFLAGS = -g -O2 -W -Wall -fno-strict-aliasing/' \
224
				userlevel/Makefile )
225
	@touch configure_userlevel2
226

    
227
unconfigure_userlevel2:
228
	@test ! -e configure_userlevel || \
229
		{ echo "WARN: detected userlevel config, command ignored."; exit 1; }
230
	@test ! -e configure_linuxmodule || \
231
		{ echo "WARN: detected linuxmodule config, command ignored."; exit 1; }
232
	@if [ -d ${GDP_BLD} ]; \
233
	then \
234
		echo "Remove ${GDP_BLD}..." ; \
235
		rm -rf ${GDP_BLD} ; \
236
	else \
237
		echo "${GDP_BLD} not found" ; \
238
	fi
239
	@if [ -d ${CLICK_BLD} ]; \
240
	then \
241
		echo "Remove ${CLICK_BLD}..." ; \
242
		rm -rf ${CLICK_BLD} ; \
243
	else \
244
		echo "${CLICK_BLD} not found" ; \
245
	fi
246
	@rm -f configure_userlevel2
247

    
248
gdp-router-click2: configure_userlevel2 src/*.hh src/*.cc
249
	@test ! -e configure_userlevel || \
250
		{ echo "WARN: detected userlevel config, command ignored."; exit 1; }
251
	@test ! -e configure_linuxmodule || \
252
		{ echo "WARN: detected linuxmodule config, command ignored."; exit 1; }
253
	@echo "Refresh source hardlinks in ${CLICK_BLD} (required post git pull)"
254
	@ln -f src/gdp_v4_router.hh ${CLICK_ELEMS_LOCAL}/gdp_v4_router.hh
255
	@ln -f src/gdp_v4_router.cc ${CLICK_ELEMS_LOCAL}/gdp_v4_router.cc
256
	@echo "/* autogenerated for gdp-router-click2 - do not edit */" > ${S_VERHH}
257
	@echo "#define STRINGIFY(_vs_) # _vs_" >> ${S_VERHH}
258
	@echo "const char *ver_major = { STRINGIFY(${VERSION}) };" >> ${S_VERHH}
259
	@echo ${VER_MAJOR}
260
	@echo -n "const char *git_branch = {\n\t STRINGIFY(" >> ${S_VERHH}
261
	@git rev-parse --abbrev-ref HEAD >> ${S_VERHH}
262
	@echo -n ")};\nconst char *git_hash = {\n\t STRINGIFY(" >> ${S_VERHH}
263
	@git log -n 1 --oneline --pretty=format:'%H%n' >> ${S_VERHH}
264
	@echo ")};" >> ${S_VERHH}
265
	@ln -f ${S_VERHH} ${CLICK_ELEMS_LOCAL}/${VERHH}
266
	@( cd $(CLICK_BLD) && make )
267
	@cp ${CLICK_UL_BINARY} $@
268

    
269
install2: gdp-router-click2
270
	@test ! -e configure_userlevel || \
271
		{ echo "WARN: detected userlevel config, command ignored."; exit 1; }
272
	@test ! -e configure_linuxmodule || \
273
		{ echo "WARN: detected linuxmodule config, command ignored."; exit 1; }
274
	cp -p ./gdp-router-click2 /usr/sbin/gdp-router-click2
275
	chmod 755 /usr/sbin/gdp-router-click2
276
	chown gdp:gdp /usr/sbin/gdp-router-click2
277

    
278
install-gdp-router-click2: gdp-router-click2
279
	@test ! -e configure_userlevel || \
280
		{ echo "WARN: detected userlevel config, command ignored."; exit 1; }
281
	@test ! -e configure_linuxmodule || \
282
		{ echo "WARN: detected linuxmodule config, command ignored."; exit 1; }
283
	./adm/setup-gdp-router-click2.sh
284
	cp -p ./gdp-router-click2 /usr/sbin/gdp-router-click2
285
	chmod 755 /usr/sbin/gdp-router-click2
286
	chown gdp:gdp /usr/sbin/gdp-router-click2
287

    
288
docker2: gdp-router-click2
289
	@cp -p ./gdp-router-click2 ./docker.gdp_router_click2/
290
	@( cd ./docker.gdp_router_click2/ && docker build -t gdp_router_click2 . )
291

    
292
stop2:
293
	@test ! -e configure_userlevel || \
294
		{ echo "WARN: detected userlevel config, command ignored."; exit 1; }
295
	@test ! -e configure_linuxmodule || \
296
		{ echo "WARN: detected linuxmodule config, command ignored."; exit 1; }
297
	systemctl stop gdplogd2
298
	systemctl stop gdp-router-click2
299

    
300
start2:
301
	@test ! -e configure_userlevel || \
302
		{ echo "WARN: detected userlevel config, command ignored."; exit 1; }
303
	@test ! -e configure_linuxmodule || \
304
		{ echo "WARN: detected linuxmodule config, command ignored."; exit 1; }
305
	systemctl start gdp-router-click2
306
	systemctl start gdplogd2
307

    
308
reinstall2: gdp-router-click2
309
	@test ! -e configure_userlevel || \
310
		{ echo "WARN: detected userlevel config, command ignored."; exit 1; }
311
	@test ! -e configure_linuxmodule || \
312
		{ echo "WARN: detected linuxmodule config, command ignored."; exit 1; }
313
	systemctl stop gdplogd2
314
	systemctl stop gdp-router-click2
315
	cp -p ./gdp-router-click2 /usr/sbin/gdp-router-click2
316
	chmod 755 /usr/sbin/gdp-router-click2
317
	chown gdp:gdp /usr/sbin/gdp-router-click2
318
	systemctl start gdp-router-click2
319
	systemctl start gdplogd2
320

    
321
#
322
# (non-default) set up a linuxmodule workspace
323
#
324

    
325
.PHONY: unconfigure_linuxmodule lm_install lm_clean
326

    
327
/usr/src/linux-headers-${UNAME_R}:
328
	@echo "Installing linux-headers-${UNAME_R}"
329
	@apt install linux-headers-${UNAME_R}
330

    
331
${CLICK_LM_PATCH}: ${GDP_LM_PATCH}
332
	@echo "Applying ${GDP_LM_PATCH}"
333
	@cp -pf ${GDP_LM_PATCH} ${CLICK_LM_PATCH}
334
	@( cd ${CLICK_BLD} ; git apply ${CLICK_LM_PATCH} )
335

    
336
configure_linuxmodule: ${CLICK_BLD} \
337
						/usr/src/linux-headers-${UNAME_R} \
338
						${CLICK_LM_PATCH}
339
	@test ! -e configure_userlevel || \
340
		{ echo "WARN: detected userlevel config, command ignored."; exit 1; }
341
	@test ! -e configure_userlevel2 || \
342
		{ echo "WARN: detected userlevel2 config, command ignored."; exit 1; }
343
	@echo "Configuring linuxmodule workspace"
344
	@( cd ${CLICK_BLD} ; \
345
		  ./configure --disable-userlevel \
346
				--enable-linuxmodule --enable-multithread \
347
				--with-linux=/usr/src/linux-headers-${UNAME_R} \
348
				--with-linux-map=/boot/System.map-${UNAME_R} ; \
349
		  make elemlist ; )
350
	@touch configure_linuxmodule
351

    
352
unconfigure_linuxmodule: lm_clean
353
	@test ! -e configure_userlevel || \
354
		{ echo "WARN: detected userlevel config, command ignored."; exit 1; }
355
	@test ! -e configure_userlevel2 || \
356
		{ echo "WARN: detected userlevel2 config, command ignored."; exit 1; }
357
	@echo "Unconfiguring linuxmodule workspace"
358
	@test ! -r ${CLICK_LM_PATCH} || \
359
		( cd ${CLICK_BLD} && git apply --reverse ${CLICK_LM_PATCH} )
360
	@rm -f ${CLICK_LM_PATCH}
361
	@test ! -r ${CLICK_M} || rm -f ${CLICK_M}
362
	@rm -f configure_linuxmodule
363

    
364
lm: configure_linuxmodule src/*.hh src/*.cc
365
	@test ! -e configure_userlevel || \
366
		{ echo "WARN: detected userlevel config, command ignored."; exit 1; }
367
	@test ! -e configure_userlevel2 || \
368
		{ echo "WARN: detected userlevel2 config, command ignored."; exit 1; }
369
	@echo "Updating Click kernel loadable modules"
370
	@( cd $(CLICK_BLD) && make )
371
	@touch lm
372

    
373
lm_install: lm
374
	@test ! -e configure_userlevel || \
375
		{ echo "WARN: detected userlevel config, command ignored."; exit 1; }
376
	@test ! -e configure_userlevel2 || \
377
		{ echo "WARN: detected userlevel2 config, command ignored."; exit 1; }
378
	@( cd $(CLICK_BLD) && make install )
379

    
380
lm_clean:
381
	@test ! -e configure_userlevel || \
382
		{ echo "WARN: detected userlevel config, command ignored."; exit 1; }
383
	@test ! -e configure_userlevel2 || \
384
		{ echo "WARN: detected userlevel2 config, command ignored."; exit 1; }
385
	@test ! -r ${CLICK_M} || ( cd $(CLICK_BLD) && make clean )
386
	@rm -f lm
387

    
388
#
389
# manual targets
390
#
391

    
392
# if desired, run manually after ensuring pandoc is available
393
README.html: README.md
394
	pandoc -sS -o $@ $<