-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
140 lines (106 loc) · 4.01 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#
# Copyright (c) 2021, Nutanix, Inc.
#
# Author: [email protected]
#
# Conntrack-Migrator v.1.0 is dual licensed under the BSD 3 Clause License or
# the GNU General Public License version 2.
CC := gcc
GLIB_LIBS := $(shell pkg-config --libs gio-2.0 glib-2.0 gobject-2.0 gio-unix-2.0)
LDLIBS := -lmnl \
-lnetfilter_conntrack \
-lpthread \
$(GLIB_LIBS)
INCLUDE_DIRS := include/ \
gen/ \
/usr/include/glib-2.0 \
/usr/lib64/glib-2.0/include \
/usr/include/gio-unix-2.0/
GLIB_INCLUDE := $(shell pkg-config --cflags gio-2.0 glib-2.0 gobject-2.0 gio-unix-2.0)
INCLUDE_FLAGS := $(addprefix -I, $(INCLUDE_DIRS)) $(GLIB_INCLUDE)
CFLAGS := $(INCLUDE_FLAGS) -O2 -ggdb -Wall -Wextra -Wno-unused-parameter -Wunused -fstack-protector -Wl,-z,relro -Wformat -Wformat-security -Werror=format-security
SRC_DIR := src
GEN_DIR := gen
BUILD_DIR := build
BUILD_DIR_GEN := $(BUILD_DIR)/gen
BUILD_DIR_SRC := $(BUILD_DIR)/src
MAIN_SRCS := common.c \
conntrack.c \
conntrack_entry.c \
conntrack_entry_print.c \
conntrack_store.c \
data_template.c \
marshal.c \
unmarshal.c \
dbus_server.c \
log.c \
lmct_config.c \
main.c
DBUS_GENERATED := dbus_vmstate1.c dbus_vmstate1.h
SRCS := $(addprefix $(SRC_DIR)/, $(MAIN_SRCS))
GEN_SRCS := $(addprefix $(GEN_DIR)/, $(DBUS_GENERATED))
GEN_C_SRCS := $(filter %.c, $(GEN_SRCS))
OBJS := $(addprefix $(BUILD_DIR)/,$(SRCS:.c=.o))
GEN_OBJS := $(addprefix $(BUILD_DIR)/,$(GEN_C_SRCS:.c=.o))
CONNTRACK_MIGRATOR := $(BUILD_DIR)/conntrack_migrator
TEST_DIR := tests
MAIN_MOCK_SRCS := mock_log.c \
mock_conntrack_entry_print.c
MAIN_TEST_SRCS := test_common.c \
test_conntrack_entry.c \
test_conntrack_store.c \
test_data_template.c \
test_marshal.c \
test_unmarshal.c \
test_lmct_config.c \
test_conntrack.c \
test_dbus_server.c
MOCK_SRCS := $(addprefix $(TEST_DIR)/, $(MAIN_MOCK_SRCS))
TEST_SRCS := $(addprefix $(TEST_DIR)/, $(MAIN_TEST_SRCS))
TEST_BUILD_DIR := $(BUILD_DIR)/$(TEST_DIR)
TEST_RUNNER_DIR := $(BUILD_DIR)/$(TEST_DIR)/runner
TEST_OBJS := $(addprefix $(TEST_BUILD_DIR)/,$(MAIN_TEST_SRCS:.c=.o))
MOCK_OBJS := $(addprefix $(TEST_BUILD_DIR)/,$(MAIN_MOCK_SRCS:.c=.o))
TEST_RUNNERS := $(addprefix $(TEST_RUNNER_DIR)/,$(MAIN_TEST_SRCS:.c=.out))
LIBCHECK_LIBS := $(shell pkg-config --libs check)
.PHONY: all check clean clean_secondary setup_test_dbus
all: $(GEN_SRCS) $(CONNTRACK_MIGRATOR) ;
$(TEST_BUILD_DIR):
mkdir -p $@
$(TEST_RUNNER_DIR):
mkdir -p $@
$(BUILD_DIR_GEN):
mkdir -p $@
$(BUILD_DIR_SRC):
mkdir -p $@
$(GEN_DIR):
mkdir -p $@
$(GEN_SRCS): dbus-vmstate1.xml | $(GEN_DIR)
gdbus-codegen --interface-prefix org.qemu. --output-directory $(GEN_DIR) --generate-c-code dbus_vmstate1 --c-generate-object-manager $<
$(BUILD_DIR_GEN)/%.o: $(GEN_SRCS) | $(BUILD_DIR_GEN)
$(CC) $(CFLAGS) -c -o $@ $<
$(BUILD_DIR_SRC)/%.o: $(SRC_DIR)/%.c $(GEN_SRCS) | $(BUILD_DIR_SRC)
$(CC) $(CFLAGS) -c -o $@ $<
$(CONNTRACK_MIGRATOR): $(GEN_OBJS) $(OBJS)
$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)
$(TEST_BUILD_DIR)/test_%.o: $(TEST_DIR)/test_%.c | $(TEST_BUILD_DIR)
$(CC) $(CFLAGS) -c -o $@ $^
$(TEST_BUILD_DIR)/mock_%.o: $(TEST_DIR)/mock_%.c | $(TEST_BUILD_DIR)
$(CC) $(CFLAGS) -c -o $@ $^
$(TEST_RUNNER_DIR)/test_%.out: $(GEN_OBJS) $(BUILD_DIR_SRC)/%.o $(MOCK_OBJS) $(TEST_BUILD_DIR)/test_%.o | $(TEST_RUNNER_DIR)
$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS) $(LIBCHECK_LIBS)
@echo "======================= Running Test ========================="
DBUS_SYSTEM_BUS_ADDRESS=unix:path=/tmp/dbus/system_bus_socket ./$@
@echo "=============================================================="
.SECONDARY: $(TEST_OBJS) $(MOCK_OBJS)
setup_test_dbus:
mkdir -p /tmp/dbus
dbus-daemon --config-file ./tests/dbus-test.conf --print-address 1 --print-pid 1
check: clean_secondary setup_test_dbus $(TEST_RUNNERS)
kill -9 `cat /tmp/dbus/messagebus.pid` || true
rm -rf /tmp/dbus
clean_secondary:
rm -rf $(TEST_BUILD_DIR)
rm -rf /tmp/dbus
clean: clean_secondary
rm -rf $(BUILD_DIR) $(GEN_DIR)