-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
114 lines (89 loc) · 3.2 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
# @file Makefile
# @brief Makefile
# @author Jozef Zuzelka <xzuzel00@stud.fit.vutbr.cz>
# @date
# - Created: 08.02.2017
# - Edited: 23.06.2017 11:54
# @version 1.0.0
# @par make: GNU Make 3.81
######################## Compiler & flags ##########################
#CXX=g++
CXXFLAGS=-std=c++14 -O3 -Wall -Wextra -pedantic
LDFLAGS=-lpcap -pthread
######################## Variables ##########################
SHELL:=/bin/bash
SRCDIR=src
OBJDIR=obj
TESTSDIR=tests
BINDIR=bin
BIN=namon
SRC_TMP=$(wildcard $(SRCDIR)/*.cpp)
SRC=$(filter-out src/namon_%,$(SRC_TMP))
ifeq ($(OS),Windows_NT)
SRC += $(SRCDIR)/namon_win.cpp
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
SRC += $(SRCDIR)/namon_linux.cpp
endif
ifeq ($(UNAME_S),Darwin)
SRC += $(SRCDIR)/namon_apple.cpp
endif
endif
OBJ=$(patsubst $(SRCDIR)/%.cpp, $(OBJDIR)/%.o, $(SRC))
TESTS=$(patsubst %.cpp, %, $(wildcard $(TESTSDIR)/*.cpp))
#if [ "$(uname -a | grep -i "Darwin")" == "" ]; then
# setcap cap_net_raw ./$(BIN)
#else
# chmod +r /dev/bpf*
.PHONY: test, clean, pack, doxygen, debug, unit-tests, directories, pf_ring, libs, netmap
###################### #######################
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@ $(LDFLAGS)
all: directories $(BIN)
$(BIN): $(OBJ)
$(CXX) $(CXXFLAGS) -o $(BINDIR)/$@ $^ $(LDFLAGS)
directories:
@mkdir -p $(BINDIR) $(OBJDIR)
debug: TMP := $(CXXFLAGS)
debug: CXXFLAGS = $(filter-out -O3,$(TMP)) -O0 -g -DDEBUG_BUILD
debug: clean all
tests: CXXFLAGS += -I./src/ -DDEBUG_BUILD -g
#tests: clean-tests $(TESTS)
tests: $(TESTS)
$(TESTS): %: %.cpp $(filter-out src/main.cpp,$(SRC))
$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
# -------------------------------------
libs:
@mkdir -p libs
@cd scripts && ./install_libs.sh
pf_ring: CXXFLAGS += -I./libs/PF_RING/libpcap -I./libs/PF_RING/userland/lib
pf_ring: LDFLAGS += -L./libs/PF_RING/libpcap -L./libs/PF_RING/userland/lib #-lpfring
pf_ring: debug
netmap: CXXFLAGS += -I./libs/netmap/libpcap -I./libs/netmap/lib
netmap: LDFLAGS += -L./libs/netmap/libpcap -L./libs/netmap/lib
netmap: debug
pfq: CXXFLAGS += -I./libs/PFQ/libpcap -I./libs/PFQ/lib
pfq: LDFLAGS += -L./libs/PFQ/libpcap -L./libs/PFQ/lib
pfq: debug
# -------------------------------------
test: all
#valgrind --tool=callgrind ./$(BIN)
@echo
-$(shell echo "# CppCheck test..."; cppcheck -v --enable=all --language=c++ -f --std=c++11 --error-exitcode=10 $(SRCDIR)/*.cpp >/dev/null 2>&1; if [ $$? -eq 10 ]; then echo "# ERROR"; else "# OK"; fi)
-$(shell echo "# Valgrind test..."; valgrindResult=$$(valgrind ./$(BIN) 2>&1 >/dev/null) ; if [ $$(echo $$valgrindResult | grep "ERROR SUMMARY: 0 errors from 0 contexts" | wc -l) = "1" ]; then echo "# OK" ; else /bin/echo '#'; echo "$$valgrindResult" | grep "ERROR SUMMARY:" ; fi)
# -------------------------------------
pack: clean
tar czf bp.tar.gz src/ tests/ win32/ docs/*.pdf docs/mainpage.dox docs/doxygen.conf Makefile README.md LICENSE appveyor.yml .travis.yml
# zip -r
doxygen:
doxygen docs/doxygen.conf
clean:
rm -f xzuzel00.tar.gz .fuse_hidden*
rm -rf *.dSYM $(OBJDIR) $(BINDIR)
clean-tests:
rm -f $(TESTS)
rm -rf $(TESTSDIR)/*.dSYM
clean-doc:
rm -rf docs/latex docs/html
clean-all: clean clean-tests clean-doc