aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 829eeb41f5cf3559cb9198b68610e3287268da92 (plain)
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
CC = gcc
PROJECT_CFLAGS += -Wall -Wextra $(EXTRA_CFLAGS) -I.
DEPS_CFLAGS := -DJSMN_STATIC=1 -DJSMN_STRICT=1 -Idependencies -Idependencies/uthash/src
LIBS += -pthread -lpcap -lm -lmaxminddb

GOCC =
GOFLAGS = -ldflags='-s -w'

UNIX_SOCK_DISTRIBUTOR = /tmp/ndpid-distributor.sock
UNIX_SOCK_COLLECTOR = /tmp/ndpid-collector.sock

ifneq ($(PKG_CONFIG_BIN),)
PC_CFLAGS=$(shell $(PKG_CONFIG_BIN) --cflags libndpi)
PC_LDFLAGS=$(shell $(PKG_CONFIG_BIN) --libs libndpi)

ifneq ($(PKG_CONFIG_PATH),)
PROJECT_CFLAGS += -Wl,-rpath='$(shell dirname $(PKG_CONFIG_PATH))'
endif

else # PKG_CONFIG_BIN

ifeq ($(NDPI_WITH_GCRYPT),yes)
LIBS += -lgcrypt -lgpg-error
endif
ifeq ($(NDPI_WITH_PCRE),yes)
LIBS += -lpcre
endif

ifneq ($(CUSTOM_LIBNDPI),)
STATIC_NDPI_LIB += '$(CUSTOM_LIBNDPI)'
PROJECT_CFLAGS += '-I$(shell dirname $(CUSTOM_LIBNDPI))/../include/ndpi'
ifeq ($(findstring $*.so, $(CUSTOM_LIBNDPI)),.so)
PROJECT_CFLAGS += -Wl,-rpath='$(shell dirname $(CUSTOM_LIBNDPI))'
endif
else
LIBS += -lndpi
endif

endif # PKG_CONFIG_BIN

ifeq ($(ENABLE_MEMORY_PROFILING),yes)
PROJECT_CFLAGS += -DENABLE_MEMORY_PROFILING=1
DEPS_CFLAGS += -Duthash_malloc=nDPIsrvd_uthash_malloc -Duthash_free=nDPIsrvd_uthash_free
endif

ifeq ($(ENABLE_DEBUG),yes)
PROJECT_CFLAGS += -O0 -g3 -fno-omit-frame-pointer -fno-inline
endif

ifeq ($(ENABLE_SANITIZER),yes)
PROJECT_CFLAGS += -fsanitize=address -fsanitize=undefined -fsanitize=enum -fsanitize=leak
LIBS += -lasan -lubsan
endif

ifeq ($(ENABLE_SANITIZER_THREAD),yes)
PROJECT_CFLAGS += -fsanitize=undefined -fsanitize=enum -fsanitize=thread
LIBS += -lubsan
endif

GO_DASHBOARD_SRCS := examples/go-dashboard/main.go examples/go-dashboard/ui/ui.go

RM = rm -f
INSTALL = install

ifeq ($(ENABLE_DEBUG),yes)
INSTALL_ARGS = -s
endif

all: help nDPId nDPIsrvd examples

examples: examples/c-collectd/c-collectd examples/c-captured/c-captured examples/c-json-stdout/c-json-stdout examples/go-dashboard/go-dashboard

nDPId: nDPId.c utils.c
	$(CC) $(PROJECT_CFLAGS) $(CFLAGS) $(PC_CFLAGS) $^ -o $@ $(LDFLAGS) $(PC_LDFLAGS) $(STATIC_NDPI_LIB) $(LIBS)

nDPIsrvd: nDPIsrvd.c utils.c
	$(CC) $(PROJECT_CFLAGS) $(CFLAGS) $(DEPS_CFLAGS) $^ -o $@ $(LDFLAGS) $(STATIC_NDPI_LIB) $(LIBS)

examples/c-collectd/c-collectd: examples/c-collectd/c-collectd.c
	$(CC) $(PROJECT_CFLAGS) $(CFLAGS) $(DEPS_CFLAGS) $@.c -o $@ $(LDFLAGS) $(LIBS)

examples/c-captured/c-captured: examples/c-captured/c-captured.c utils.c
	$(CC) $(PROJECT_CFLAGS) $(CFLAGS) $(DEPS_CFLAGS) $^ -o $@ $(LDFLAGS) $(LIBS)

examples/c-json-stdout/c-json-stdout: examples/c-json-stdout/c-json-stdout.c
	$(CC) $(PROJECT_CFLAGS) $(CFLAGS) $(DEPS_CFLAGS) $@.c -o $@ $(LDFLAGS) $(LIBS)

examples/go-dashboard/go-dashboard: $(GO_DASHBOARD_SRCS)
ifneq ($(GOCC),)
	cd examples/go-dashboard && GO111MODULE=on $(GOCC) mod vendor
	cd examples/go-dashboard && GO111MODULE=on $(GOCC) build $(GOFLAGS) .
else
	@echo '*** Not building examples/go-dashboard/go-dashboard as it requires GOCC to be set ***'
endif

install: all
	$(INSTALL) -d '$(DESTDIR)$(PREFIX)/bin' '$(DESTDIR)$(PREFIX)/sbin'
	$(INSTALL) $(INSTALL_ARGS) ./nDPIsrvd '$(DESTDIR)$(PREFIX)/bin'
	$(INSTALL) $(INSTALL_ARGS) ./nDPId '$(DESTDIR)$(PREFIX)/sbin'
	$(INSTALL) $(INSTALL_ARGS) ./examples/c-captured/c-captured '$(DESTDIR)$(PREFIX)/bin/nDPIsrvd-captured'
	$(INSTALL) $(INSTALL_ARGS) ./examples/c-json-stdout/c-json-stdout '$(DESTDIR)$(PREFIX)/bin/nDPIsrvd-json-dump'
	$(INSTALL) $(INSTALL_ARGS) ./examples/c-collectd/c-collectd '$(DESTDIR)$(PREFIX)/bin/nDPIsrvd-collectd'
	$(INSTALL) $(INSTALL_ARGS) ./examples/py-flow-info/flow-info.py '$(DESTDIR)$(PREFIX)/bin/nDPIsrvd-flow-info.py'
ifneq ($(GOCC),)
	$(INSTALL) $(INSTALL_ARGS) -t '$(DESTDIR)$(PREFIX)/bin' examples/go-dashboard/go-dashboard
endif

clean:
	$(RM) -f nDPId nDPIsrvd examples/c-collectd/c-collectd examples/c-captured/c-captured examples/c-json-stdout/c-json-stdout examples/go-dashboard/go-dashboard

help:
	@echo '------------------------------------'
	@echo 'PKG_CONFIG_BIN    = $(PKG_CONFIG_BIN)'
	@echo 'PKG_CONFIG_PATH   = $(PKG_CONFIG_PATH)'
	@echo 'PC_CFLAGS         = $(PC_CFLAGS)'
	@echo 'PC_LDFLAGS        = $(PC_LDFLAGS)'
	@echo 'CC                = $(CC)'
	@echo 'CFLAGS            = $(CFLAGS)'
	@echo 'EXTRA_CFLAGS      = $(EXTRA_CFLAGS)'
	@echo 'LDFLAGS           = $(LDFLAGS)'
	@echo 'PROJECT_CFLAGS    = $(PROJECT_CFLAGS)'
	@echo 'LIBS              = $(LIBS)'
	@echo 'GOCC              = $(GOCC)'
	@echo 'GOFLAGS           = $(GOFLAGS)'
ifeq ($(PKG_CONFIG_BIN),)
	@echo 'CUSTOM_LIBNDPI    = $(CUSTOM_LIBNDPI)'
ifeq ($(NDPI_WITH_GCRYPT),yes)
	@echo 'NDPI_WITH_GCRYPT  = yes'
else
	@echo 'NDPI_WITH_GCRYPT  = no'
endif
ifeq ($(NDPI_WITH_PCRE),yes)
	@echo 'NDPI_WITH_PCRE    = yes'
else
	@echo 'NDPI_WITH_PCRE    = no'
endif
endif # PKG_CONFIG_BIN
ifeq ($(ENABLE_MEMORY_PROFILING),yes)
	@echo 'ENABLE_MEMORY_PROFILING = yes'
else
	@echo 'ENABLE_MEMORY_PROFILING = no'
endif
ifeq ($(ENABLE_DEBUG),yes)
	@echo 'ENABLE_DEBUG      = yes'
else
	@echo 'ENABLE_DEBUG      = no'
endif
ifeq ($(ENABLE_SANITIZER),yes)
	@echo 'ENABLE_SANITIZER  = yes'
else
	@echo 'ENABLE_SANITIZER  = no'
endif
ifeq ($(ENABLE_SANITIZER_THREAD),yes)
	@echo 'ENABLE_SANITIZER_THREAD = yes'
else
	@echo 'ENABLE_SANITIZER_THREAD = no'
endif
	@echo '------------------------------------'

run-mocksrvd:
	nc -k -l -U $(UNIX_SOCK_COLLECTOR)

run-raw-out:
	nc -U $(UNIX_SOCK_DISTRIBUTOR)

run-nDPIsrvd: nDPIsrvd
	./nDPIsrvd -l -c $(UNIX_SOCK_COLLECTOR) -s $(UNIX_SOCK_DISTRIBUTOR)

run-nDPId: nDPId
	sudo ./nDPId -l -c $(UNIX_SOCK_COLLECTOR) -a run-test -u $(shell id -u -n)

.PHONY: all examples install clean help run-mocksrvd run-raw-out run-nDPIsrvd run-nDPId