-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
123 lines (98 loc) · 3.49 KB
/
Copy pathMakefile
File metadata and controls
123 lines (98 loc) · 3.49 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
# sonic-firewall Makefile
#
# Build targets for the SONiC stateful firewall container components.
#
# Prerequisites (from SONiC build environment):
# - sonic-swss-common (libswsscommon, headers)
# - libnl-3, libnl-genl-3, libnl-nf-3, libnl-route-3
# - libnetfilter_conntrack
# - hiredis
#
# Usage:
# make - build all C++ daemons
# make fwsyncd - build flow sync daemon
# make fworch - build firewall orchestrator
# make test - run Python unit tests
# make clean - remove build artifacts
# make install - install all components
.PHONY: all clean install test fwsyncd fworch lint
# Compiler settings
CXX ?= g++
CXXFLAGS = -std=c++17 -Wall -Wextra -O2 -g
LDFLAGS =
# SONiC swss-common include/lib paths (adjust for build env)
SWSS_COMMON_INC ?= /usr/include/swss
SWSS_COMMON_LIB ?= /usr/lib
# Include paths
INCLUDES = \
-I$(SWSS_COMMON_INC) \
-Isrc/schema \
-I/usr/include/libnl3
# Library flags
LIBS_COMMON = \
-L$(SWSS_COMMON_LIB) \
-lswsscommon \
-lhiredis \
-lpthread
LIBS_FWSYNCD = $(LIBS_COMMON) \
-lnl-3 -lnl-genl-3 -lnl-nf-3 -lnl-route-3 \
-lnetfilter_conntrack
LIBS_FWORCH = $(LIBS_COMMON)
# Source files
FWSYNCD_SRCS = src/fwsyncd/fwsyncd.cpp src/fwsyncd/fwsync.cpp
FWORCH_SRCS = src/fworch/fworchmain.cpp src/fworch/fworch.cpp
# Object files
FWSYNCD_OBJS = $(FWSYNCD_SRCS:.cpp=.o)
FWORCH_OBJS = $(FWORCH_SRCS:.cpp=.o)
# Build directory
BUILD_DIR = build
# Install paths
INSTALL_BIN = /usr/bin
INSTALL_LIB = /usr/lib/python3/dist-packages
# ===== Targets =====
all: fwsyncd fworch
fwsyncd: $(BUILD_DIR)/fwsyncd
fworch: $(BUILD_DIR)/fworch
$(BUILD_DIR)/fwsyncd: $(FWSYNCD_SRCS)
@mkdir -p $(BUILD_DIR)
$(CXX) $(CXXFLAGS) $(INCLUDES) -o $@ $(FWSYNCD_SRCS) $(LDFLAGS) $(LIBS_FWSYNCD)
$(BUILD_DIR)/fworch: $(FWORCH_SRCS)
@mkdir -p $(BUILD_DIR)
$(CXX) $(CXXFLAGS) $(INCLUDES) -o $@ $(FWORCH_SRCS) $(LDFLAGS) $(LIBS_FWORCH)
# Pattern rule for object files (for incremental builds)
%.o: %.cpp
$(CXX) $(CXXFLAGS) $(INCLUDES) -c -o $@ $<
# ===== Install =====
install: all
# C++ daemons
install -m 755 $(BUILD_DIR)/fwsyncd $(DESTDIR)$(INSTALL_BIN)/fwsyncd
install -m 755 $(BUILD_DIR)/fworch $(DESTDIR)$(INSTALL_BIN)/fworch
# Python daemons
install -m 755 src/fwzonemgrd/fwzonemgrd.py $(DESTDIR)$(INSTALL_BIN)/fwzonemgrd.py
install -m 755 src/fwpolicyd/fwpolicyd.py $(DESTDIR)$(INSTALL_BIN)/fwpolicyd.py
# Warm restart script
install -m 755 scripts/restore_fw_state.py $(DESTDIR)$(INSTALL_BIN)/restore_fw_state.py
# Docker files
install -m 755 docker/start.sh $(DESTDIR)$(INSTALL_BIN)/start.sh
# CLI plugins (installed into SONiC CLI plugin directory)
install -d $(DESTDIR)/cli/config/plugins
install -d $(DESTDIR)/cli/show/plugins
install -d $(DESTDIR)/cli/clear/plugins
install -m 644 cli/config/plugins/firewall.py $(DESTDIR)/cli/config/plugins/
install -m 644 cli/show/plugins/show_firewall.py $(DESTDIR)/cli/show/plugins/
install -m 644 cli/clear/plugins/clear_firewall.py $(DESTDIR)/cli/clear/plugins/
# ===== Test =====
test:
python3 -m pytest tests/ -v --tb=short
lint:
# Python linting
python3 -m flake8 src/fwzonemgrd/ src/fwpolicyd/ cli/ tests/ \
--max-line-length=100 --ignore=E501,W503
# C++ linting (if cppcheck available)
-cppcheck --enable=warning,style src/fwsyncd/ src/fworch/ 2>/dev/null
# ===== Clean =====
clean:
rm -rf $(BUILD_DIR)
rm -f src/fwsyncd/*.o src/fworch/*.o
find . -name '__pycache__' -type d -exec rm -rf {} + 2>/dev/null || true
find . -name '*.pyc' -delete 2>/dev/null || true