-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
124 lines (94 loc) · 4.57 KB
/
Copy pathMakefile
File metadata and controls
124 lines (94 loc) · 4.57 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
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/sbin
MANDIR ?= $(PREFIX)/share/man
DBDIR ?= /var/neighbot
CC ?= cc
CFLAGS ?= -O2 -pipe
CFLAGS += -Wall -Wextra -Wpedantic -Wformat=2
CFLAGS += -D_FORTIFY_SOURCE=2
CFLAGS += -fstack-protector-strong
LDFLAGS += -Wl,-z,relro -Wl,-z,now
LDFLAGS += -lpcap
# Flags that must survive a command-line CFLAGS override (e.g. RPM %{optflags}).
# GNU Make ignores CFLAGS += when CFLAGS is set on the command line, so these
# go into internal variables referenced directly in the compile rules.
# _ALIAS keeps the packet parsers (which overlay structs on the capture
# buffer) well-defined even when a distro replaces CFLAGS.
_STD = -std=c11
_GNU_SOURCE != [ "$$(uname -s)" = Linux ] && echo -D_GNU_SOURCE || true
_ALIAS = -fno-strict-aliasing
SRCS = neighbot.c log.c db.c parse.c notify.c capture.c oui.c probe.c
OBJS = $(SRCS:.c=.o)
DEPS = $(SRCS:.c=.d)
BIN = neighbot
all: $(BIN)
$(BIN): $(OBJS)
$(CC) $(OBJS) $(LDFLAGS) -o $@
.c.o:
$(CC) $(_STD) $(_GNU_SOURCE) $(_ALIAS) $(CFLAGS) -MMD -MP -c $<
-include $(DEPS)
clean:
rm -f $(BIN) $(OBJS) $(DEPS) fuzz_parse fuzz_dbload fuzz_ouiload
rm -f tests/test_parse tests/test_dbload tests/test_dbexpire tests/test_ouiload tests/test_probe tests/test_capture tests/test_notify
oui.txt:
curl -sL https://standards-oui.ieee.org/oui/oui.txt | \
awk '/\(hex\)/ { gsub(/-/, ":", $$1); v=""; \
for (i=3; i<=NF; i++) v = v (i>3?" ":"") $$i; \
print tolower($$1) " " v }' > oui.txt
oui-update:
rm -f oui.txt
$(MAKE) oui.txt
install: $(BIN) oui.txt
install -d $(DESTDIR)$(BINDIR)
install -m 755 $(BIN) $(DESTDIR)$(BINDIR)/$(BIN)
install -d $(DESTDIR)$(MANDIR)/man8
install -m 644 neighbot.8 $(DESTDIR)$(MANDIR)/man8/neighbot.8
install -d $(DESTDIR)$(DBDIR)
install -m 644 oui.txt $(DESTDIR)$(DBDIR)/oui.txt
install-systemd: install
install -d $(DESTDIR)/etc/systemd/system
install -m 644 neighbot.service $(DESTDIR)/etc/systemd/system/neighbot.service
install-rcd: install
install -m 755 neighbot.rc $(DESTDIR)/etc/rc.d/neighbot
uninstall:
rm -f $(DESTDIR)$(BINDIR)/$(BIN)
rm -f $(DESTDIR)$(MANDIR)/man8/neighbot.8
rm -f $(DESTDIR)$(DBDIR)/oui.txt
rm -f $(DESTDIR)/etc/systemd/system/neighbot.service
rm -f $(DESTDIR)/etc/rc.d/neighbot
# Fuzz targets (requires clang with libFuzzer support)
FUZZ_CC = clang
FUZZ_CFLAGS = -std=c11 -g -O1 -fno-omit-frame-pointer $(_GNU_SOURCE)
FUZZ_CFLAGS += -fno-strict-aliasing
FUZZ_CFLAGS += -fsanitize=fuzzer,address,undefined
FUZZ_LDFLAGS = -fsanitize=fuzzer,address,undefined -lpcap
fuzz: fuzz_parse fuzz_dbload fuzz_ouiload
fuzz_parse: fuzz/fuzz_parse.c parse.c db.c oui.c log.c
$(FUZZ_CC) $(FUZZ_CFLAGS) -o $@ fuzz/fuzz_parse.c parse.c db.c oui.c log.c $(FUZZ_LDFLAGS)
fuzz_dbload: fuzz/fuzz_dbload.c db.c oui.c log.c
$(FUZZ_CC) $(FUZZ_CFLAGS) -o $@ fuzz/fuzz_dbload.c db.c oui.c log.c $(FUZZ_LDFLAGS)
fuzz_ouiload: fuzz/fuzz_ouiload.c oui.c log.c
$(FUZZ_CC) $(FUZZ_CFLAGS) -o $@ fuzz/fuzz_ouiload.c oui.c log.c $(FUZZ_LDFLAGS)
fuzz-clean:
rm -f fuzz_parse fuzz_dbload fuzz_ouiload
# Test harnesses (for valgrind, no sanitizers)
test: tests/test_parse tests/test_dbload tests/test_dbexpire tests/test_ouiload tests/test_probe tests/test_capture tests/test_notify
tests/test_parse: tests/test_parse.c parse.c db.c oui.c log.c
$(CC) $(_STD) $(_GNU_SOURCE) $(_ALIAS) $(CFLAGS) -o $@ tests/test_parse.c parse.c db.c oui.c log.c $(LDFLAGS)
tests/test_dbload: tests/test_dbload.c db.c oui.c log.c
$(CC) $(_STD) $(_GNU_SOURCE) $(_ALIAS) $(CFLAGS) -o $@ tests/test_dbload.c db.c oui.c log.c $(LDFLAGS)
tests/test_dbexpire: tests/test_dbexpire.c db.c oui.c log.c
$(CC) $(_STD) $(_GNU_SOURCE) $(_ALIAS) $(CFLAGS) -o $@ tests/test_dbexpire.c db.c oui.c log.c $(LDFLAGS)
tests/test_ouiload: tests/test_ouiload.c oui.c log.c
$(CC) $(_STD) $(_GNU_SOURCE) $(_ALIAS) $(CFLAGS) -o $@ tests/test_ouiload.c oui.c log.c $(LDFLAGS)
tests/test_probe: tests/test_probe.c probe.c log.c db.c oui.c
$(CC) $(_STD) $(_GNU_SOURCE) $(_ALIAS) $(CFLAGS) -o $@ tests/test_probe.c probe.c log.c db.c oui.c $(LDFLAGS)
tests/test_capture: tests/test_capture.c capture.c log.c
$(CC) $(_STD) $(_GNU_SOURCE) $(_ALIAS) $(CFLAGS) -o $@ tests/test_capture.c capture.c log.c $(LDFLAGS)
tests/test_notify: tests/test_notify.c notify.c db.c oui.c log.c
$(CC) $(_STD) $(_GNU_SOURCE) $(_ALIAS) $(CFLAGS) -o $@ tests/test_notify.c notify.c db.c oui.c log.c $(LDFLAGS)
test-clean:
rm -f tests/test_parse tests/test_dbload tests/test_dbexpire tests/test_ouiload tests/test_probe tests/test_capture tests/test_notify
.PHONY: all clean install install-systemd install-rcd oui-update uninstall
.PHONY: fuzz fuzz-clean
.PHONY: test test-clean