forked from MaxKellermann/ferm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
186 lines (138 loc) · 5.49 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#
# Makefile for ferm
#
TOPDIR = .
include $(TOPDIR)/config.mk
VERSION := $(shell $(PERL) src/ferm --version | awk '{print $$2}' | head -1 | tr -d ',')
DISTDIR = build/ferm-$(VERSION)
.PHONY: all clean
all: doc/ferm.txt doc/ferm.html doc/ferm.1 doc/import-ferm.1 ferm.service
clean:
rm -rf build
rm -f doc/ferm.txt doc/ferm.html doc/ferm.1 doc/import-ferm.1 *.tmp
rm -f ferm.service
ferm.service: ferm.service.in
sed 's|@prefix@|$(PREFIX)|g' $< > $@
#
# documentation
#
doc/ferm.txt: doc/ferm.pod
pod2text $< > $@
doc/ferm.html: doc/ferm.pod
pod2html $< --title="ferm - Firewall rules made easy" --flush > $@
doc/ferm.1: doc/ferm.pod
pod2man --section=1 --release="ferm $(VERSION)" \
--center="FIREWALL RULES MADE EASY" \
--official $< > $@
doc/import-ferm.1: src/import-ferm
pod2man --section=1 --release="ferm $(VERSION)" \
--center="FIREWALL RULES MADE EASY" \
--official $< > $@
#
# test suite
#
STAMPDIR = $(TOPDIR)/build/test
STAMPDIR_20 = $(TOPDIR)/build/test2
# a list of all ferm scripts which should be tested with iptables
FERM_SCRIPTS =
FERM_SCRIPTS += $(wildcard test/modules/*.ferm) $(wildcard test/targets/*.ferm)
FERM_SCRIPTS += $(wildcard test/protocols/*.ferm) $(wildcard test/misc/*.ferm)
FERM_SCRIPTS += $(wildcard test/glob/*.ferm)
FERM_SCRIPTS += $(wildcard test/ipv6/*.ferm)
FERM_SCRIPTS += $(wildcard test/resolve/*.ferm)
FERM_SCRIPTS += $(wildcard test/arptables/*.ferm) $(wildcard test/ebtables/*.ferm)
EXCLUDE_IMPORT =
IMPORT_SCRIPTS = $(filter-out $(EXCLUDE_IMPORT) test/arptables/% test/ebtables/%,$(FERM_SCRIPTS))
PRESERVE_SCRIPTS += $(wildcard test/preserve/*.ferm)
# just a hack
RESULT_SED += -e 's,--protocol,-p,g'
RESULT_SED += -e 's,--in-interface,-i,g'
RESULT_SED += -e 's,--out-interface,-o,g'
RESULT_SED += -e 's,--destination ,-d ,g'
RESULT_SED += -e 's,--source ,-s ,g'
RESULT_SED += -e 's,--match ,-m ,g'
RESULT_SED += -e 's,--jump,-j,g'
RESULT_SED += -e 's,--goto,-g,g'
RESULT_SED += -e 's,--fragment,-f,g'
RESULT_SED += -e '/^\#/d'
EB_ARP_RESULT_SED = -e 's,--jump,-j,g'
$(STAMPDIR)/test/arptables/%.result: test/arptables/%.ferm src/ferm
@mkdir -p $(dir $@)
$(PERL) src/ferm --test --slow $< |sed $(EB_ARP_RESULT_SED) >$@
$(STAMPDIR)/test/ebtables/%.result: test/ebtables/%.ferm src/ferm
@mkdir -p $(dir $@)
$(PERL) src/ferm --test --slow $< |$(PERL) test/ebtables_tempfile_rename.pl |sed $(EB_ARP_RESULT_SED) >$@
$(STAMPDIR)/%.result: %.ferm src/ferm test/sort.pl
@mkdir -p $(dir $@)
$(PERL) src/ferm --test --slow --noflush $< |$(PERL) test/sort.pl |sed $(RESULT_SED) >$@
$(STAMPDIR)/%.SAVE: %.ferm src/ferm test/sort.pl
@mkdir -p $(dir $@)
$(PERL) src/ferm --test $< |$(PERL) test/sort.pl >$@
$(STAMPDIR)/%.IMPORT: $(STAMPDIR)/%.SAVE src/import-ferm
$(PERL) src/import-ferm $< >$@
$(STAMPDIR)/%.SAVE2: $(STAMPDIR)/%.IMPORT src/ferm test/sort.pl
$(PERL) src/ferm --test --fast $< |$(PERL) test/sort.pl >$@
$(STAMPDIR)/%.sort: %.result test/sort.pl
@mkdir -p $(dir $@)
$(PERL) test/sort.pl <$< >$@
$(STAMPDIR)/%.check: $(STAMPDIR)/%.sort $(STAMPDIR)/%.result
diff -u $^
@touch $@
$(STAMPDIR)/%.check-import: $(STAMPDIR)/%.SAVE $(STAMPDIR)/%.SAVE2
diff -u $^
@touch $@
$(STAMPDIR)/test/preserve/%.preserved: test/preserve/%.ferm src/ferm test/sort.pl $(STAMPDIR)/test/mock/preserve.SAVE2
@mkdir -p $(dir $@)
$(PERL) src/ferm --test --test-mock-previous=ip=$(STAMPDIR)/test/mock/preserve.SAVE2 $< |$(PERL) test/sort.pl |sed $(RESULT_SED) >$@
$(STAMPDIR)/test/preserve/%.expected: test/preserve/%.result
@mkdir -p $(dir $@)
sed $(RESULT_SED) $< >$@
$(STAMPDIR)/test/preserve/%.check-preserve: $(STAMPDIR)/test/preserve/%.preserved $(STAMPDIR)/test/preserve/%.expected
diff -u $^
@touch $@
.PHONY : check-ferm check-import check
check-ferm: $(patsubst %.ferm,$(STAMPDIR)/%.check,$(FERM_SCRIPTS))
check-import: $(patsubst %.ferm,$(STAMPDIR)/%.check-import,$(IMPORT_SCRIPTS))
check-preserve: $(patsubst %.ferm,$(STAMPDIR)/%.check-preserve,$(PRESERVE_SCRIPTS))
check: check-ferm check-import check-preserve
@echo "All ferm unit tests finished successfully."
#
# distribution
#
.PHONY: dist
build/ferm-$(VERSION).tar.gz: all
rm -rf $(DISTDIR)
install -d -m 755 $(DISTDIR) $(DISTDIR)/src $(DISTDIR)/doc $(DISTDIR)/examples
install -m 755 src/ferm src/import-ferm $(DISTDIR)/src
install -m 644 ferm.service $(DISTDIR)
install -m 644 doc/ferm.pod doc/ferm.txt doc/ferm.html doc/ferm.1 doc/import-ferm.1 $(DISTDIR)/doc
install -m 644 config.mk Makefile AUTHORS COPYING NEWS README.rst TODO $(DISTDIR)
install -m 644 $(wildcard examples/*.ferm) $(DISTDIR)/examples
cd build && tar czf ferm-$(VERSION).tar.gz ferm-$(VERSION)
dist: build/ferm-$(VERSION).tar.gz
#
# installation
#
.PHONY: install uninstall
install: all
install -d -m 755 $(DOCDIR)/examples $(PREFIX)/sbin $(SERVICEDIR)
install -m 644 AUTHORS COPYING NEWS README.rst TODO $(DOCDIR)
install -m 644 examples/*.ferm $(DOCDIR)/examples
install -m 755 src/ferm src/import-ferm $(PREFIX)/sbin/
install -m 644 ferm.service $(SERVICEDIR)
install -d -m 755 $(DOCDIR) $(MANDIR)
install -m 644 doc/ferm.txt doc/ferm.html $(DOCDIR)
install -m 644 doc/ferm.1 doc/import-ferm.1 $(MANDIR)
gzip -f9 $(MANDIR)/ferm.1 $(MANDIR)/import-ferm.1
uninstall:
rm -rf $(DOCDIR)
rm -f $(MANDIR)/ferm.1 $(MANDIR)/import-ferm.1
rm -f $(SERVICEDIR)/ferm.service
rm -f $(PREFIX)/sbin/ferm $(PREFIX)/sbin/import-ferm
#
# misc targets
#
.PHONY: upload
upload: doc/ferm.html
scp NEWS doc/ferm.html foo-projects.org:/var/www/ferm.foo-projects.org/download/2.5/
scp examples/*.ferm foo-projects.org:/var/www/ferm.foo-projects.org/download/examples/