-
Notifications
You must be signed in to change notification settings - Fork 39
/
Makefile
122 lines (98 loc) · 3.45 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
121
122
CC ?= clang
LDOPTS += -Wl,-z,now -Wl,-z,relro -pie
COPTSWARN = -Wall -Wextra -Wno-unused-parameter -Wpointer-arith -Werror
COPTSSEC = -D_FORTIFY_SOURCE=2
ifeq ($(CC), cc)
CC = clang
endif
ifeq ($(CC), clang)
COPTSSEC+=-fstack-protector-strong
else
COPTSSEC+=-fstack-protector
endif
COPTSDEBUG=-g -ggdb -O0
ifeq ($(BUILD), debugaddress)
COPTSDEBUG=-g -ggdb -O0 -fsanitize=address -fsanitize=undefined
endif
ifeq ($(BUILD), release)
MARCH=-march=corei7
COPTSDEBUG=-g -ggdb -O3 $(MARCH)
endif
COPTS+=$(CFLAGS) $(COPTSDEBUG) $(COPTSWARN) $(COPTSSEC) -fPIE \
-Ideps/libpcap -I deps/libnfnetlink/include -Ideps/libnetfilter_log/include
all: pmtud
pmtud: libpcap.a libnetfilter_log.a libnfnetlink.a src/*.c src/*.h Makefile
$(CC) $(COPTS) \
src/main.c src/utils.c src/net.c src/uevent.c \
src/hashlimit.c src/csiphash.c src/sched.c \
src/bitmap.c src/nflog.c \
libpcap.a libnetfilter_log.a libnfnetlink.a \
$(LDOPTS) \
-o pmtud
libpcap.a: deps/libpcap
(cd deps/libpcap && ./configure && make)
cp deps/libpcap/libpcap.a .
libnfnetlink.a: deps/libnfnetlink
(cd deps/libnfnetlink && ./autogen.sh && CFLAGS="-fpic" ./configure --enable-static && make)
cp deps/libnfnetlink/src/.libs/libnfnetlink.a .
libnetfilter_log.a: deps/libnetfilter_log libnfnetlink.a
(cd deps/libnetfilter_log && ./autogen.sh \
&& PKG_CONFIG_PATH=$$PWD/../libnfnetlink CFLAGS="-fpic" ./configure --enable-static \
&& make CPPFLAGS=-I$$PWD/../libnfnetlink/include LDFLAGS=-L$$PWD/../libnfnetlink/src/.libs)
cp deps/libnetfilter_log/src/.libs/libnetfilter_log.a .
clean:
rm -rf pmtud pmtud_*.deb
distclean: clean
rm -f lib*.a
-(cd deps/libpcap && make clean && make distclean)
-(cd deps/libnfnetlink && make clean && make distclean)
-(cd deps/libnetfilter_log && make clean && make distclean)
format:
clang-format-3.5 -i src/*.c src/*.h
# Release process
# ---------------
GITVER := $(shell git describe --tags --always --dirty=-dev)
VERSION := $(shell python -c 'print "$(GITVER)"[1:].partition("-")[0]')
ITERATION := $(shell python -c 'print ("$(GITVER)"[1:].partition("-")[2] or "0")')
NEXT_VERSION := v0.$(shell python -c 'print int("$(GITVER)"[1:].partition("-")[0][2:]) + 1')
.PHONY: release
release:
@echo "[*] Curr version: $(VERSION)-$(ITERATION)"
@echo "[*] Next version: $(NEXT_VERSION)"
echo "$(NEXT_VERSION) (`date '+%Y%m%d-%H%M'`)" > RELEASE_NOTES.tmp
git log --reverse --date=short --format="- %ad %s" tags/v$(VERSION)..HEAD >> RELEASE_NOTES.tmp
echo "" >> RELEASE_NOTES.tmp
cat RELEASE_NOTES >> RELEASE_NOTES.tmp
mv RELEASE_NOTES.tmp RELEASE_NOTES
git add RELEASE_NOTES
git commit -m "Release $(NEXT_VERSION)"
git tag $(NEXT_VERSION)
@echo "[*] To push the release run:"
@echo "git push origin master; git push origin $(NEXT_VERSION)"
# Build process
# -------------
BIN_PREFIX ?= /usr/local/bin
PACKAGE_ROOT := $(shell pwd)/tmp/packaging
.PHONY: print-builddeps cf-package
CFDEPENDENCIES = python flex bison gcc make pkg-config
print-builddeps:
@echo $(CFDEPENDENCIES) $(DEPENDENCIES)
cf-package:
@echo "[*] resetting submodules"
git submodule sync --quiet
git submodule update --init --recursive --quiet
@echo "[*] rebuilding"
-$(MAKE) clean
-$(MAKE) distclean
$(MAKE) pmtud BUILD=release CC=gcc
-mkdir -p $(PACKAGE_ROOT)/$(BIN_PREFIX)
cp pmtud $(PACKAGE_ROOT)/$(BIN_PREFIX)
fakeroot fpm -C $(PACKAGE_ROOT) \
-s dir \
-t deb \
--deb-compression bzip2 \
-v $(VERSION) \
--iteration $(ITERATION) \
-n pmtud \
.
rm -rf $(PACKAGE_ROOT)