-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
427 lines (355 loc) · 10.9 KB
/
Makefile
File metadata and controls
427 lines (355 loc) · 10.9 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
#
# Copyright (C) Hamish Coleman
#
# Our default make target
all:
export AR
export CC
export CFLAGS
export CONFIG_HOST_OS
export EXE
export INSTALL
export INSTALL_DOC
export INSTALL_PROG
export LDFLAGS
export LDLIBS_EXTRA
export LDLIBS_LOCAL
export MKDIR
VERSION:=$(shell scripts/version.sh)
CFLAGS+=-DVERSION='"$(VERSION)"'
BUILDDATE+=$(shell scripts/version.sh date)
CFLAGS+=-DBUILDDATE='"$(BUILDDATE)"'
-include config.mak
ifndef CONFIG_HOST
# TODO:
# dont error if we are installing build-deps or other non-compile action
$(error Please run ./configure)
endif
#Ultrasparc64 users experiencing SIGBUS should try the following gcc options
#(thanks to Robert Gibbon)
# PLATOPTS_SPARC64=-mcpu=ultrasparc -pipe -fomit-frame-pointer -ffast-math -finline-functions -fweb -frename-registers -mapp-regs
# CFLAGS+=$(PLATOPTS)
# Only do the openssl pkg config and flags if it has been enabled
ifeq ($(CONFIG_WITH_OPENSSL), yes)
OPENSSL_CFLAGS=$(shell pkg-config openssl; echo $$?)
ifeq ($(OPENSSL_CFLAGS), 0)
CFLAGS+=$(shell pkg-config --cflags-only-I openssl)
endif
endif
ifneq (,$(findstring musl,$(CONFIG_HOST_OS)))
CFLAGS+=-D__MUSL__
endif
# To output extensive malloc stats to stderr when verbosity is >= DEBUG
# uncomment this line. This is intended for helping to track difficult
# errors with memory allocation and not for any normal use.
# CFLAGS+=-DDEBUG_MALLOC
CFLAGS+=-Wall
CFLAGS+=-MMD
# Quick sanity check on our build environment
UNAME_S := $(shell uname -s)
ifndef UNAME_S
# This could happen if the Makefile is unable to run "uname", which can
# happen if the shell has a bad path (or is the wrong shell)
$(error Could not run uname command, cannot continue)
endif
MKDIR=mkdir -p
INSTALL=install
INSTALL_PROG=$(INSTALL) -m555
INSTALL_DOC=$(INSTALL) -m444
# DESTDIR set in debian make system
PREFIX=$(DESTDIR)/$(CONFIG_PREFIX)
# Note that these two install dirs are outside of the CONFIG_PREFIX.
# The ETCDIR is not configurable in the code, so no changes should be done
# without code changes.
ETCDIR=$(DESTDIR)/etc/n3n
CONFIG_RUNDIR?=$(DESTDIR)/run
CONFIG_BINDIR?=$(PREFIX)/bin
CONFIG_SBINDIR?=$(PREFIX)/sbin
CONFIG_MANDIR?=$(PREFIX)/share/man
MAN7DIR=$(CONFIG_MANDIR)/man7
MAN8DIR=$(CONFIG_MANDIR)/man8
CONFIG_DOCDIR?=$(PREFIX)/share/doc/n3n
CONFIG_SYSTEMDDIR?=$(PREFIX)/lib/systemd/system
CFLAGS+=-DCONFIG_RUNDIR='"$(CONFIG_RUNDIR)"'
#######################################
# All the additions needed for using the n3n library
#
CFLAGS+=-I$(abspath include)
LDFLAGS+=-L$(abspath src)
CFLAGS+=-DHAVE_BRIDGING_SUPPORT
OBJS=\
src/aes.o \
src/auth.o \
src/base64.o \
src/cc20.o \
src/conffile.o \
src/conffile_defs.o \
src/curve25519.o \
src/edge_utils.o \
src/header_encryption.o \
src/hexdump.o \
src/initfuncs.o \
src/json.o \
src/logging.o \
src/mainloop.o \
src/management.o \
src/metrics.o \
src/minilzo.o \
src/n2n.o \
src/n2n_port_mapping.o \
src/n2n_regex.o \
src/network_traffic_filter.o \
src/pearson.o \
src/peer_info.o \
src/pktbuf.o \
src/random_numbers.o \
src/resolve.o \
src/sn_selection.o \
src/sn_utils.o \
src/speck.o \
src/test_hashing.o \
src/tf.o \
src/transform.o \
src/transform_aes.o \
src/transform_cc20.o \
src/transform_lzo.o \
src/transform_none.o \
src/transform_null.o \
src/transform_speck.o \
src/transform_tf.o \
src/transform_zstd.o \
src/tuntap_freebsd.o \
src/tuntap_linux.o \
src/tuntap_netbsd.o \
src/tuntap_osx.o \
src/wire.o \
DEPS+=$(OBJS:%.o=%.d)
CLEAN_FILES+=$(OBJS)
CLEAN_FILES+=$(DEPS)
# TODO: add performance testing and then try to avoid ignoring this warning
CFLAGS_src/speck.c := -Wno-maybe-uninitialized
ifneq (,$(findstring mingw,$(CONFIG_HOST_OS)))
OBJS+=src/win32/edge_rc.o
OBJS+=src/win32/edge_utils_win32.o
OBJS+=src/win32/getopt.o
OBJS+=src/win32/getopt1.o
OBJS+=src/win32/win32.o
OBJS+=src/win32/wintap.o
endif
src/management.o: src/management_index.html.h
src/management.o: src/management_script.js.h
CLEAN_FILES+=src/management_index.html.h src/management_script.js.h
src/libn3n.a: $(OBJS)
@echo " AR $@"
@$(AR) rcs $@ $^
SUBDIR_LIBS+=src/libn3n.a
#######################################
# Add non system library version of natpmp
# TODO: this library doesnt compile for win64 without a patch
#
ifdef THIRDPARTY_LIBNATPMP
CFLAGS+=-I$(abspath thirdparty/libnatpmp)
CFLAGS+=-DNATPMP_STATICLIB=1
CFLAGS+=-DHAVE_LIBNATPMP=1
LDFLAGS+=-L$(abspath thirdparty/libnatpmp)
LDLIBS_EXTRA+=-lnatpmp
thirdparty/libnatpmp/libnatpmp.a:
$(MAKE) -C $(dir $@) $(notdir $@)
SUBDIR_LIBS+=thirdparty/libnatpmp/libnatpmp.a
SUBDIR_CLEAN+=thirdparty/libnatpmp
endif
#######################################
# Add non system library version of miniupnpc
#
ifdef THIRDPARTY_MINIUPNPC
CFLAGS+=-I$(abspath thirdparty/miniupnp/miniupnpc)
CFLAGS+=-DMINIUPNP_STATICLIB=1
CFLAGS+=-DHAVE_LIBMINIUPNPC=1
LDFLAGS+=-L$(abspath thirdparty/miniupnp/miniupnpc/build)
LDLIBS_EXTRA+=-lminiupnpc
thirdparty/miniupnp/miniupnpc/build/libminiupnpc.a:
$(MAKE) -C thirdparty/miniupnp/miniupnpc build/libminiupnpc.a
SUBDIR_LIBS+=thirdparty/miniupnp/miniupnpc/build/libminiupnpc.a
SUBDIR_CLEAN+=thirdparty/miniupnp/miniupnpc
endif
#######################################
# All the additions needed for using the connslot library
#
CFLAGS+=-I$(abspath libs)
LDFLAGS+=-L$(abspath libs/connslot)
LDLIBS_LOCAL+=-lconnslot
libs/connslot/libconnslot.a:
$(MAKE) -C $(dir $@) $(notdir $@) httpd-test
SUBDIR_LIBS+=libs/connslot/libconnslot.a
SUBDIR_CLEAN+=libs/connslot
#######################################
# As source files pass the linter, they can be added here (As all the non
# library source is passing the linter tests, this could be refactored)
LINT_CCODE=\
apps/ \
include/ \
src/ \
tools/ \
# Some files currently cause the linter to fail, so they need to be excluded
# TODO: change either the files or the linter to remove these failures
LINT_EXCLUDE=include/uthash.h|include/lzodefs.h|src/minilzo.c
DOCS=n3n-edge.8.gz n3n-supernode.8.gz n3n.7.gz
# This is the list of Debian/Ubuntu packages that are needed during the build.
# Mostly of use in automated build systems.
# TODO: hook into the debian/control file and avoid replicating this list.
BUILD_DEP:=\
autoconf \
build-essential \
dh-python \
flake8 \
gcovr \
libcap-dev \
libzstd-dev \
shellcheck \
uncrustify \
yamllint \
jq \
COVERAGEDIR?=coverage
.PHONY: all
all: version $(DOCS) tools apps
.PHONY: version
# This allows breaking the build if the version.sh script discovers
# any inconsistancies
version:
@scripts/version.sh >/dev/null
@echo "Build for version: $(VERSION)"
.PHONY: tools
tools: $(SUBDIR_LIBS)
$(MAKE) -C tools
SUBDIR_CLEAN+=tools
.PHONY: apps
apps: $(SUBDIR_LIBS)
$(MAKE) -C apps
SUBDIR_CLEAN+=apps
.PHONY: examples
examples: $(SUBDIR_LIBS)
$(MAKE) -C apps examples
src/win32/edge.rc: src/win32/edge.manifest
src/win32/edge_rc.o: src/win32/edge.rc
$(WINDRES) $< -O coff -o $@
# Remember to keep the two CC lines in sync
$(info CC is: $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $$@ $$<)
%.o: %.c
@echo " CC $@ $(CFLAGS_$<)"
@$(CC) $(CFLAGS) $(CFLAGS_$<) $(CPPFLAGS) -c -o $@ $< -MT$@ -MT$(<:.c=.d)
%.gz : %
gzip -n -c $< > $@
%.h : %
libs/connslot/file2strbufc $< $(basename $(notdir $<)) >$@
.PHONY: test test.units test.integration
test: test.builtin test.units test.integration
test.units: tools # needs tools
scripts/test_harness.sh tests/tests_units.list
test.integration: apps # needs apps
scripts/test_harness.sh tests/tests_integration.list
test.builtin: apps # needs apps
scripts/test_harness.sh tests/tests_builtin.list
.PHONY: lint lint.python lint.ccode lint.shell lint.yaml
lint: lint.python lint.ccode lint.shell lint.yaml
lint.python:
flake8 scripts/n3nctl scripts/n3n-convert_old_conf
lint.ccode:
scripts/indent.sh -e '$(LINT_EXCLUDE)' $(LINT_CCODE)
lint.shell:
shellcheck scripts/*.sh
lint.yaml:
yamllint .
# To generate coverage information, run configure with
# CFLAGS="-fprofile-arcs -ftest-coverage" LDFLAGS="--coverage"
# and run the desired tests. Ensure that package gcovr is installed
# and then run "make cover"
.PHONY: cover
cover:
mkdir -p $(COVERAGEDIR)
gcovr \
--gcov-ignore-errors=no_working_dir_found \
-s --html --html-details --output=$(COVERAGEDIR)/index.html
# Use coverage data to generate gcov text report files.
# Unfortunately, these end up in the wrong directory due to the
# makefile layout
# The steps to use this are similar to the "make cover" above
.PHONY: gcov
gcov:
gcov $(OBJS)
$(MAKE) -C tools gcov
$(MAKE) -C apps gcov
# This is a convinent target to use during development or from a CI/CD system
.PHONY: build-dep
ifneq (,$(findstring darwin,$(CONFIG_HOST_OS)))
build-dep: build-dep-brew
else
build-dep: build-dep-dpkg
endif
.PHONY: build-dep-dpkg
build-dep-dpkg:
sudo apt install $(BUILD_DEP)
.PHONY: build-dep-brew
build-dep-brew:
brew install automake gcovr
.PHONY: clean.cov
clean.cov:
rm -f \
src/*.gcno src/*.gcda \
apps/*.gcno apps/*.gcda \
tools/*.gcno tools/*.gcda
.PHONY: iwyu
iwyu: iwyu.out
iwyu.out:
CFLAGS="-Xiwyu --error_always" $(MAKE) -k CC=include-what-you-use 2> iwyu.out
.PHONY: clean
clean: clean.cov
rm -rf $(SUBDIR_LIBS) $(DOCS) $(COVERAGEDIR)/ *.dSYM *~
rm -f tests/*.out
rm -f $(CLEAN_FILES)
for dir in $(SUBDIR_CLEAN); do $(MAKE) -C $$dir clean; done
.PHONY: distclean
distclean:
rm -f tests/*.out src/*.indent src/*.unc-backup*
rm -rf autom4te.cache/
rm -f config.mak config.log config.status configure include/config.h include/config.h.in
rm -f n3n-edge.8.gz n3n.7.gz n3n-supernode.8.gz
rm -f packages/debian/config.log packages/debian/config.status
rm -rf packages/debian/autom4te.cache/
rm -f packages/rpm/config.log packages/rpm/config.status
# A quick way to generate a dpkg from a checkout.
#
DEBEMAIL?=builder@example.com
DEBFULLNAME?="Auto Build"
export DEBEMAIL
export DEBFULLNAME
.PHONY: dpkg
dpkg:
rm -f debian/changelog
dch --create --empty --package n3n -v ${VERSION}-1 --no-auto-nmu local package Auto Build
env -u CFLAGS dpkg-buildpackage -rfakeroot -d -us -uc --host-type ${CONFIG_HOST}
.PHONY: install.bin
install.bin: apps
$(MAKE) -C apps install CONFIG_SBINDIR=$(abspath $(CONFIG_SBINDIR))
$(INSTALL) -d $(CONFIG_BINDIR) $(ETCDIR)
$(INSTALL_PROG) scripts/n3nctl $(CONFIG_BINDIR)
# TODO: dont install.systemd for a non systemd host
.PHONY: install.systemd
install.systemd:
$(INSTALL) -d $(CONFIG_SYSTEMDDIR)
$(INSTALL_DOC) packages/lib/systemd/system/n3n-edge@.service $(CONFIG_SYSTEMDDIR)
$(INSTALL_DOC) packages/lib/systemd/system/n3n-edge.service $(CONFIG_SYSTEMDDIR)
$(INSTALL_DOC) packages/lib/systemd/system/n3n-supernode.service $(CONFIG_SYSTEMDDIR)
.PHONY: install.doc
install: n3n-edge.8.gz n3n-supernode.8.gz n3n.7.gz
$(INSTALL) -d $(MAN7DIR) $(MAN8DIR) $(CONFIG_DOCDIR)
$(INSTALL_DOC) n3n-edge.8.gz $(MAN8DIR)/
$(INSTALL_DOC) n3n-supernode.8.gz $(MAN8DIR)/
$(INSTALL_DOC) n3n.7.gz $(MAN7DIR)/
$(INSTALL_DOC) doc/*.md doc/*.sample $(CONFIG_DOCDIR)/
# TODO:
# install wireshark dissector
.PHONY: install
install: install.bin install.doc install.systemd
ifeq (0, $(words $(findstring $(MAKECMDGOALS), clean)))
-include $(DEPS)
endif