blob: add40211335a458e532296a07016c80a2aa04656 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001# -*- Makefile -*-
2
3top_builddir := @top_builddir@
4builddir := @builddir@
5top_srcdir := @top_srcdir@
6srcdir := @srcdir@
7ksourcedir := @ksourcedir@
8prefix := @prefix@
9exec_prefix := @exec_prefix@
10libdir := @libdir@
11libexecdir := @libexecdir@
12xtlibdir := @xtlibdir@
13
14CC := @CC@
15CCLD := ${CC}
16CFLAGS := @CFLAGS@
17LDFLAGS := @LDFLAGS@
18regular_CFLAGS := @regular_CFLAGS@
19kinclude_CFLAGS := @kinclude_CFLAGS@
20
21AM_CFLAGS := ${regular_CFLAGS} -I${top_builddir}/include -I${top_srcdir}/include ${kinclude_CFLAGS}
22AM_DEPFLAGS = -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@
23
24ifeq (${V},)
25AM_LIBTOOL_SILENT = --silent
26AM_VERBOSE_CC = @echo " CC " $@;
27AM_VERBOSE_CCLD = @echo " CCLD " $@;
28AM_VERBOSE_CXX = @echo " CXX " $@;
29AM_VERBOSE_CXXLD = @echo " CXXLD " $@;
30AM_VERBOSE_AR = @echo " AR " $@;
31AM_VERBOSE_GEN = @echo " GEN " $@;
32endif
33
34#
35# Wildcard module list
36#
37pfx_build_mod := $(patsubst ${srcdir}/libxt_%.c,%,$(wildcard ${srcdir}/libxt_*.c))
38@ENABLE_IPV4_TRUE@ pf4_build_mod := $(patsubst ${srcdir}/libipt_%.c,%,$(wildcard ${srcdir}/libipt_*.c))
39@ENABLE_IPV6_TRUE@ pf6_build_mod := $(patsubst ${srcdir}/libip6t_%.c,%,$(wildcard ${srcdir}/libip6t_*.c))
40pfx_build_mod := $(filter-out @blacklist_modules@,${pfx_build_mod})
41pf4_build_mod := $(filter-out @blacklist_modules@,${pf4_build_mod})
42pf6_build_mod := $(filter-out @blacklist_modules@,${pf6_build_mod})
43
44# Only build matches/targets for the current kernel config
45-include $(LINUX_DIR)/.config
46lower=$(shell echo $(1) | tr [:upper:] [:lower:])
47upper=$(shell echo $(1) | tr [:lower:] [:upper:])
48keeplower=$(filter-out $(call upper,$(1)),$(1))
49keepupper=$(filter-out $(call lower,$(1)),$(1))
50TEST_CONFIG_VAL=$(patsubst $(3)_%,%,$(filter $(3)_%,$(foreach i,$(1),$(CONFIG_$(2)_$(i))_$(i))))
51TEST_CONFIG_TYPE=$(call TEST_CONFIG_VAL,$(1),$(2),y) $(call TEST_CONFIG_VAL,$(1),$(2),m)
52TEST_CONFIG=$(call TEST_CONFIG_TYPE,$(1),$(2)_$(3)) $(call TEST_CONFIG_TYPE,$(1),NETFILTER_XT_$(3))
53
54PF_EXT_SLIB_BASE:=icmp
55PF_EXT_SLIB_OPT:=$(filter-out $(PF_EXT_SLIB_BASE),$(pf4_build_mod))
56PF_EXT_SLIB_MATCH:=$(sort $(call upper,$(call keeplower,$(PF_EXT_SLIB_OPT))))
57PF_EXT_SLIB_TARGET:=$(sort $(call keepupper,$(PF_EXT_SLIB_OPT)))
58pf4_build_mod:=$(PF_EXT_SLIB_BASE)
59pf4_build_mod+=$(call lower,$(call TEST_CONFIG,$(PF_EXT_SLIB_MATCH),IP_NF,MATCH))
60pf4_build_mod+=$(call TEST_CONFIG,$(PF_EXT_SLIB_TARGET),IP_NF,TARGET)
61
62PF6_EXT_SLIB_BASE:=icmp6
63PF6_EXT_SLIB_OPT:=$(filter-out $(PF6_EXT_SLIB_BASE),$(pf6_build_mod))
64PF6_EXT_SLIB_MATCH:=$(sort $(call upper,$(call keeplower,$(PF6_EXT_SLIB_OPT))))
65PF6_EXT_SLIB_TARGET:=$(sort $(call keepupper,$(PF6_EXT_SLIB_OPT)))
66pf6_build_mod:=$(PF6_EXT_SLIB_BASE)
67pf6_build_mod+=$(call lower,$(call TEST_CONFIG,$(PF6_EXT_SLIB_MATCH),IP6_NF,MATCH))
68pf6_build_mod+=$(call TEST_CONFIG,$(PF6_EXT_SLIB_TARGET),IP6_NF,TARGET)
69
70PFX_EXT_SLIB_BASE:=tcp udp standard
71PFX_EXT_SLIB_OPT:=$(filter-out $(PFX_EXT_SLIB_BASE),$(pfx_build_mod))
72PFX_EXT_SLIB_MATCH:=$(sort $(call upper,$(call keeplower,$(PFX_EXT_SLIB_OPT))))
73PFX_EXT_SLIB_TARGET:=$(sort $(call keepupper,$(PFX_EXT_SLIB_OPT)))
74pfx_build_mod:=$(PFX_EXT_SLIB_BASE)
75pfx_build_mod+=$(call lower,$(call TEST_CONFIG,$(PFX_EXT_SLIB_MATCH),IP_NF,MATCH))
76pfx_build_mod+=$(call TEST_CONFIG,$(PFX_EXT_SLIB_TARGET),IP_NF,TARGET)
77ifeq ($(DO_IPV6), 1)
78pfx_build_mod+=$(call lower,$(call TEST_CONFIG,$(PFX_EXT_SLIB_MATCH),IP6_NF,MATCH))
79pfx_build_mod+=$(call TEST_CONFIG,$(PFX_EXT_SLIB_TARGET),IP6_NF,TARGET)
80endif
81pfx_build_mod:=$(sort $(pfx_build_mod))
82
83ifneq ($(CONFIG_NETFILTER_XT_TARGET_DSCP),)
84pfx_build_mod+=TOS
85endif
86ifneq ($(CONFIG_IP_NF_NAT)$(CONFIG_NF_NAT),)
87pf4_build_mod+=SNAT DNAT
88endif
89ifneq ($(CONFIG_IP_NF_MATCH_AH_ESP),)
90pf4_build_mod+=ah
91pfx_build_mod+=esp
92endif
93pfx_build_mod+=webstr
94
95pfx_objs := $(patsubst %,libxt_%.o,${pfx_build_mod})
96pf4_objs := $(patsubst %,libipt_%.o,${pf4_build_mod})
97pf6_objs := $(patsubst %,libip6t_%.o,${pf6_build_mod})
98pfx_solibs := $(patsubst %,libxt_%.so,${pfx_build_mod})
99pf4_solibs := $(patsubst %,libipt_%.so,${pf4_build_mod})
100pf6_solibs := $(patsubst %,libip6t_%.so,${pf6_build_mod})
101
102
103#
104# Building blocks
105#
106targets := libext4.a libext6.a matches4.man matches6.man \
107 targets4.man targets6.man
108targets_install :=
109@ENABLE_STATIC_TRUE@ libext4_objs := ${pfx_objs} ${pf4_objs}
110@ENABLE_STATIC_TRUE@ libext6_objs := ${pfx_objs} ${pf6_objs}
111@ENABLE_SHARED_TRUE@ targets += ${pfx_solibs} ${pf4_solibs} ${pf6_solibs}
112@ENABLE_SHARED_TRUE@ targets_install += ${pfx_solibs} ${pf4_solibs} ${pf6_solibs}
113
114.SECONDARY:
115
116.PHONY: all install clean distclean FORCE
117
118all: ${targets}
119
120install: ${targets_install}
121 @mkdir -p "${DESTDIR}${xtlibdir}";
122 if test -n "${targets_install}"; then install -pm0755 $^ "${DESTDIR}${xtlibdir}/"; fi;
123
124clean:
125 rm -f *.o *.oo *.so *.a {matches,targets}[46].man initext4.c initext6.c;
126 rm -f libipt_LED_def.c
127
128distclean: clean
129 rm -f .*.d .*.dd;
130
131init%.o: init%.c
132 ${AM_VERBOSE_CC} ${CC} ${AM_DEPFLAGS} ${AM_CFLAGS} -D_INIT=$*_init ${CFLAGS} -o $@ -c $<;
133
134-include .*.d
135
136
137#
138# Shared libraries
139#
140lib%.so: lib%.oo
141 ${AM_VERBOSE_CCLD} ${CCLD} ${AM_LDFLAGS} -shared ${LDFLAGS} -o $@ $<;
142
143lib%.oo: ${srcdir}/lib%.c
144 ${AM_VERBOSE_CC} ${CC} ${AM_DEPFLAGS} ${AM_CFLAGS} -D_INIT=lib$*_init -DPIC -fPIC ${CFLAGS} -o $@ -c $<;
145
146
147#
148# Static bits
149#
150# If static building is disabled, libext*.a will still be generated,
151# but will be empty. This is good since we can do with less case
152# handling code in the Makefiles.
153#
154lib%.o: ${srcdir}/lib%.c
155 ${AM_VERBOSE_CC} ${CC} ${AM_DEPFLAGS} ${AM_CFLAGS} -DNO_SHARED_LIBS=1 -D_INIT=lib$*_init ${CFLAGS} -o $@ -c $<;
156
157libext4.a: initext4.o ${libext4_objs}
158 ${AM_VERBOSE_AR} ${AR} crs $@ $^;
159
160libext6.a: initext6.o ${libext6_objs}
161 ${AM_VERBOSE_AR} ${AR} crs $@ $^;
162
163initext_func := $(sort $(addprefix xt_,${pfx_build_mod})) $(sort $(addprefix ipt_,${pf4_build_mod}))
164initext6_func := $(sort $(addprefix xt_,${pfx_build_mod})) $(sort $(addprefix ip6t_,${pf6_build_mod}))
165
166.initext4.dd: FORCE
167 @echo "${initext_func}" >$@.tmp; \
168 cmp -s $@ $@.tmp || mv $@.tmp $@; \
169 rm -f $@.tmp;
170
171.initext6.dd: FORCE
172 @echo "${initext6_func}" >$@.tmp; \
173 cmp -s $@ $@.tmp || mv $@.tmp $@; \
174 rm -f $@.tmp;
175
176initext4.c: .initext4.dd
177 ${AM_VERBOSE_GEN}
178 @( \
179 echo "" >$@; \
180 for i in ${initext_func}; do \
181 echo "extern void lib$${i}_init(void);" >>$@; \
182 done; \
183 echo "void init_extensions(void);" >>$@; \
184 echo "void init_extensions(void)" >>$@; \
185 echo "{" >>$@; \
186 for i in ${initext_func}; do \
187 echo " ""lib$${i}_init();" >>$@; \
188 done; \
189 echo "}" >>$@; \
190 );
191
192initext6.c: .initext6.dd
193 ${AM_VERBOSE_GEN}
194 @( \
195 echo "" >$@; \
196 for i in ${initext6_func}; do \
197 echo "extern void lib$${i}_init(void);" >>$@; \
198 done; \
199 echo "void init_extensions(void);" >>$@; \
200 echo "void init_extensions(void)" >>$@; \
201 echo "{" >>$@; \
202 for i in ${initext6_func}; do \
203 echo " ""lib$${i}_init();" >>$@; \
204 done; \
205 echo "}" >>$@; \
206 );
207
208libipt_LED.o: libipt_LED_def.c
209
210LEDMAN = $(LINUX_DIR)/include/linux/ledman.h
211libipt_LED_def.c: libipt_LED_def.pl $(LEDMAN)
212 perl $< <$(LEDMAN) >$@
213
214#
215# Manual pages
216#
217ex_matches = $(sort $(shell echo $(1) | grep -Eo '\b[a-z0-9]+\b'))
218ex_targets = $(sort $(shell echo $(1) | grep -Eo '\b[A-Z0-9]+\b'))
219man_run = \
220 ${AM_VERBOSE_GEN} \
221 for ext in $(1); do \
222 f="${srcdir}/libxt_$$ext.man"; \
223 if [ -f "$$f" ]; then \
224 echo ".SS $$ext"; \
225 cat "$$f"; \
226 continue; \
227 fi; \
228 f="${srcdir}/lib$(2)t_$$ext.man"; \
229 if [ -f "$$f" ]; then \
230 echo ".SS $$ext"; \
231 cat "$$f"; \
232 continue; \
233 fi; \
234 done >$@;
235
236matches4.man: .initext4.dd $(wildcard ${srcdir}/lib*.man)
237 $(call man_run,$(call ex_matches,${pfx_build_mod} ${pf4_build_mod}),ip)
238
239matches6.man: .initext6.dd $(wildcard ${srcdir}/lib*.man)
240 $(call man_run,$(call ex_matches,${pfx_build_mod} ${pf6_build_mod}),ip6)
241
242targets4.man: .initext4.dd $(wildcard ${srcdir}/lib*.man)
243 $(call man_run,$(call ex_targets,${pfx_build_mod} ${pf4_build_mod}),ip)
244
245targets6.man: .initext6.dd $(wildcard ${srcdir}/lib*.man)
246 $(call man_run,$(call ex_targets,${pfx_build_mod} ${pf6_build_mod}),ip6)