-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
140 lines (108 loc) · 4.33 KB
/
Copy pathMakefile
File metadata and controls
140 lines (108 loc) · 4.33 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Written by Andreas Jaggi <andreas.jaggi@waterwave.ch> in December 2015
# Written by Antti Kultanen <antti.kultanen@molukki.com> since August 2025
#
# nflog_dns is licensed under GNU GPL v2 or later; see LICENSE file
PREFIX ?= /usr/local
ETCDIR ?= /etc
SBINDIR ?= $(PREFIX)/sbin
RPMBUILDDIR ?= $(HOME)/rpmbuild
CXX ?= c++
CXXFLAGS ?= -O2 -std=c++11 -Wall -Wextra -Werror -pedantic
CXXFLAGS += $(shell pkg-config --cflags libnetfilter_log libtins fmt spdlog)
CXXEXTRAFLAGS ?=
LDFLAGS ?=
LIBS ?= $(shell pkg-config --libs libnetfilter_log libtins fmt spdlog)
INSTALL_SYSVINIT ?= 1
INSTALL_SYSTEMD ?= 1
SOURCES = config.cpp utils.cpp nflog_dns.cpp
HEADERS = config.h utils.h version.h
TEST_SOURCES = test/unit_test.cpp config.cpp utils.cpp
all: nflog_dns
nflog_dns: $(SOURCES) $(HEADERS)
$(CXX) $(CXXFLAGS) $(CXXEXTRAFLAGS) $(LDFLAGS) $(SOURCES) $(LIBS) -o $@
deb:
dpkg-buildpackage -us -uc -b
rpm: nflog_dns.spec
$(eval VERSION := $(shell awk -F'"' '/PROGRAM_VERSION/ {print $$2}' version.h))
mkdir -p "$(RPMBUILDDIR)"/SOURCES "$(RPMBUILDDIR)"/SPECS
tar czf "$(RPMBUILDDIR)"/SOURCES/nflog_dns-$(VERSION).tar.gz \
--exclude=.git --exclude=debian --exclude='*.deb' --exclude='*.rpm' \
--transform 's,^\.,nflog_dns-$(VERSION),' .
sed 's/^Version:.*/Version: $(VERSION)/' nflog_dns.spec > "$(RPMBUILDDIR)"/SPECS/nflog_dns.spec
rpmbuild -ba --define "_topdir $(RPMBUILDDIR)" "$(RPMBUILDDIR)"/SPECS/nflog_dns.spec
debug: CXXFLAGS = -g -O0 -std=c++11 -Wall -Wextra -Werror -pedantic -fsanitize=address -fsanitize=undefined
debug: CXXFLAGS += $(shell pkg-config --cflags libnetfilter_log libtins fmt spdlog)
debug: LDFLAGS += -fsanitize=address -fsanitize=undefined
debug: nflog_dns
clean-bin:
rm -f nflog_dns unit_test
clean-deb:
@if [ -f debian/debhelper-build-stamp ]; then dh_clean; fi
clean-rpm:
rm -rf "$(RPMBUILDDIR)"/BUILD/nflog_dns-*
rm -f "$(RPMBUILDDIR)"/SOURCES/nflog_dns-*.tar.gz
rm -f "$(RPMBUILDDIR)"/SPECS/nflog_dns.spec
rm -f "$(RPMBUILDDIR)"/RPMS/*/nflog_dns-*.rpm
rm -f "$(RPMBUILDDIR)"/SRPMS/nflog_dns-*.src.rpm
clean: clean-bin clean-deb clean-rpm
distclean: clean
test-unit: $(TEST_SOURCES) $(HEADERS)
$(CXX) $(CXXFLAGS) $(CXXEXTRAFLAGS) $(LDFLAGS) $(TEST_SOURCES) $(LIBS) -o unit_test
./unit_test
rm -f unit_test
test-integration:
bash ./test/integration_test.sh
test: test-unit test-integration
check: test
install-bin:
install -Dm755 "nflog_dns" "$(DESTDIR)$(SBINDIR)/nflog_dns"
install-bin-strip:
install -s -Dm755 "nflog_dns" "$(DESTDIR)$(SBINDIR)/nflog_dns"
install-man:
install -Dm644 "man8/nflog_dns.8" "$(DESTDIR)$(PREFIX)/share/man/man8/nflog_dns.8"
gzip -f "$(DESTDIR)$(PREFIX)/share/man/man8/nflog_dns.8"
install-init:
ifeq ($(INSTALL_SYSVINIT),1)
install -Dm755 "init.d/nflog_dns" "$(DESTDIR)$(ETCDIR)/init.d/nflog_dns"
sed -i 's#^DAEMON=.*#DAEMON="$(SBINDIR)/nflog_dns"#' "$(DESTDIR)$(ETCDIR)/init.d/nflog_dns"
endif
install-systemd:
ifeq ($(INSTALL_SYSTEMD),1)
install -Dm644 "systemd/nflog_dns.service" "$(DESTDIR)$(PREFIX)/lib/systemd/system/nflog_dns.service"
sed -i 's#^ExecStart=.*#ExecStart=$(SBINDIR)/nflog_dns $$OPTIONS#' "$(DESTDIR)$(PREFIX)/lib/systemd/system/nflog_dns.service"
endif
CONFIG_FILES := default/nflog_dns
install-config:
$(foreach file, $(CONFIG_FILES), \
test -e "$(DESTDIR)$(ETCDIR)/$(file)" || install -v -Dm644 "$(file)" "$(DESTDIR)$(ETCDIR)/$(file)" || exit 1;)
install-files: install-init install-systemd install-config
install: install-bin install-man install-files
install-strip: install-bin-strip install-files
uninstall-bin:
rm -f "$(DESTDIR)$(SBINDIR)/nflog_dns"
uninstall-man:
rm -f "$(DESTDIR)$(PREFIX)/share/man/man8/nflog_dns.8.gz"
uninstall-init:
ifeq ($(INSTALL_SYSVINIT),1)
rm -f "$(DESTDIR)$(ETCDIR)/init.d/nflog_dns"
endif
uninstall-systemd:
ifeq ($(INSTALL_SYSTEMD),1)
rm -f "$(DESTDIR)$(PREFIX)/lib/systemd/system/nflog_dns.service"
endif
uninstall-config:
$(foreach file, $(CONFIG_FILES), \
rm -f "$(DESTDIR)$(ETCDIR)/$(file)";)
uninstall-files: uninstall-init uninstall-systemd uninstall-config
uninstall: uninstall-bin uninstall-man uninstall-files
.PHONY: all deb rpm \
clean distclean \
test-unit test-integration test check \
install-bin install-bin-strip \
install-man \
install-init install-systemd install-config install-files \
install install-strip \
uninstall-bin \
uninstall-man \
uninstall-init uninstall-systemd uninstall-config uninstall-files \
uninstall