-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
120 lines (100 loc) · 2.9 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
ifeq ($(wildcard ./config.mk),)
$(error "configure needs to be run before make. For help, use: ./configure -h")
endif
include config.mk
TESTDIR := tests
BUILDDIR := build
TARGETDIR := bin
MACHINE := $(shell uname -s)
STRIP := strip
CFLAGS += -std=gnu11 -fwrapv -Wall -Wextra -Wno-override-init
CPPFLAGS += -iquote $(CURDIR) -DVERSION=\"$(VERSION)\"
LIBS := -lncurses -lrt
UNIT_LIBS := -lcheck -lm -lpthread
ifneq ($(wildcard /etc/debian_version),)
UNIT_LIBS += -lsubunit
endif
sources = $(filter-out geoip.c,$(wildcard *.c decoder/*.c ui/*.c ui/ncurses/*.c))
ifeq ($(HAVE_GEOIP),1)
LIBS += -lGeoIP
sources += geoip.c
endif
ifeq ($(HAVE_OBSTACK),0)
sources += compat/obstack.c
endif
ifeq ($(HAVE_STRLCPY),0)
sources += compat/strlcpy.c
endif
ifeq ($(MACHINE),Linux)
sources += $(wildcard linux/*.c)
else
ifeq ($(MACHINE),FreeBSD)
LIBS += -lrt
sources += $(wildcard bsd/*.c)
endif
endif
objects = $(patsubst %.c,$(BUILDDIR)/%.o,$(sources))
bpf-objs = \
$(BUILDDIR)/bpf/bpf_parser.o \
$(BUILDDIR)/bpf/bpf_lexer.o \
$(BUILDDIR)/bpf/bpf.o \
$(BUILDDIR)/bpf/pcap_lexer.o \
$(BUILDDIR)/bpf/pcap_parser.o \
$(BUILDDIR)/bpf/genasm.o
objects += $(bpf-objs)
test-objs = $(filter-out $(BUILDDIR)/main.o,$(objects))
test-objs += $(patsubst %.c,%.o,$(wildcard $(TESTDIR)/*.c))
.PHONY : all
all : release
.PHONY : debug
debug : CFLAGS += -g3 -fsanitize=address,undefined -fno-omit-frame-pointer
debug : CPPFLAGS += -DMONITOR_DEBUG
debug : $(TARGETDIR)/jomon
.PHONY : release
release : CFLAGS += -O2
release : $(TARGETDIR)/jomon
$(TARGETDIR)/jomon : decoder/register.h decoder/decoder.h $(objects)
@mkdir -p $(TARGETDIR)
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $(objects) $(LIBS)
bpf/bpf_lexer.c : bpf/bpf_lexer.re
re2c -W $< -o $@
bpf/pcap_lexer.c : bpf/pcap_lexer.re
re2c -T -W $< -o $@
decoder/decoder.h decoder/register.h :
python3 scripts/genprotocols.py
# Compile and generate dependency files
$(BUILDDIR)/%.o : %.c
@mkdir -p $(dir $@)
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
$(CC) -MM $(CPPFLAGS) $*.c > $(BUILDDIR)/$*.d
@sed -i -r 's|.*:|$(BUILDDIR)/$*.o:|' $(BUILDDIR)/$*.d # prefix target with BUILDDIR
# Include dependency info for existing object files
-include $(objects:.o=.d)
-include $(bpf-objs:.o=.d)
install :
@install -sD --strip-program=$(STRIP) bin/jomon $(PREFIX)/bin/jomon
uninstall :
@rm -f $(PREFIX)/bin/jomon
.PHONY : clean
clean :
@echo "Cleaning..."
@rm -rf bin
@rm -rf build
@rm -f $(test-objs) $(TESTDIR)/test
@rm -f bpf/bpf_lexer.c bpf/pcap_lexer.c decoder/register.h decoder/decoder.h
.PHONY : distclean
distclean : clean
@rm -f config.h config.mk
.PHONY : testclean
testclean :
@echo "Cleaning..."
@rm -f $(test-objs) $(TESTDIR)/test
.PHONY : tags
tags :
@echo "Generating tags..."
@find . -name "*.h" -o -name "*.c" | etags -
test : CFLAGS += -O2
test : $(TESTDIR)/test
@$<
$(TESTDIR)/test : $(test-objs)
$(CC) $(CFLAGS) $(CPPFLAGS) $(test-objs) -o $@ $(LIBS) $(UNIT_LIBS)