1# -*- 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
14AR                 = @AR@
15CC                 = @CC@
16CCLD               = ${CC}
17CFLAGS             = @CFLAGS@
18CPPFLAGS           = @CPPFLAGS@
19LDFLAGS            = @LDFLAGS@
20regular_CFLAGS     = @regular_CFLAGS@
21regular_CPPFLAGS   = @regular_CPPFLAGS@
22kinclude_CPPFLAGS  = @kinclude_CPPFLAGS@
23
24AM_CFLAGS       = ${regular_CFLAGS}
25AM_CPPFLAGS     = ${regular_CPPFLAGS} -I${top_builddir}/include -I${top_builddir} -I${top_srcdir}/include -I${top_srcdir} ${kinclude_CPPFLAGS} ${CPPFLAGS} @libnetfilter_conntrack_CFLAGS@ @libnftnl_CFLAGS@
26AM_DEPFLAGS     = -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@
27AM_LDFLAGS      = @noundef_LDFLAGS@
28
29ifeq (${V},)
30AM_LIBTOOL_SILENT = --silent
31AM_VERBOSE_CC     = @echo "  CC      " $@;
32AM_VERBOSE_CCLD   = @echo "  CCLD    " $@;
33AM_VERBOSE_CXX    = @echo "  CXX     " $@;
34AM_VERBOSE_CXXLD  = @echo "  CXXLD   " $@;
35AM_VERBOSE_AR     = @echo "  AR      " $@;
36AM_VERBOSE_GEN    = @echo "  GEN     " $@;
37endif
38
39#
40#	Wildcard module list
41#
42pfx_build_mod := $(patsubst ${srcdir}/libxt_%.c,%,$(sort $(wildcard ${srcdir}/libxt_*.c)))
43@ENABLE_NFTABLES_TRUE@ pfb_build_mod := $(patsubst ${srcdir}/libebt_%.c,%,$(sort $(wildcard ${srcdir}/libebt_*.c)))
44@ENABLE_NFTABLES_TRUE@ pfa_build_mod := $(patsubst ${srcdir}/libarpt_%.c,%,$(sort $(wildcard ${srcdir}/libarpt_*.c)))
45pfx_symlinks  := NOTRACK state
46@ENABLE_IPV4_TRUE@ pf4_build_mod := $(patsubst ${srcdir}/libipt_%.c,%,$(sort $(wildcard ${srcdir}/libipt_*.c)))
47@ENABLE_IPV6_TRUE@ pf6_build_mod := $(patsubst ${srcdir}/libip6t_%.c,%,$(sort $(wildcard ${srcdir}/libip6t_*.c)))
48pfx_build_mod := $(filter-out @blacklist_modules@ @blacklist_x_modules@,${pfx_build_mod})
49pfb_build_mod := $(filter-out @blacklist_modules@ @blacklist_b_modules@,${pfb_build_mod})
50pfa_build_mod := $(filter-out @blacklist_modules@ @blacklist_a_modules@,${pfa_build_mod})
51pf4_build_mod := $(filter-out @blacklist_modules@ @blacklist_4_modules@,${pf4_build_mod})
52pf6_build_mod := $(filter-out @blacklist_modules@ @blacklist_6_modules@,${pf6_build_mod})
53pfx_objs      := $(patsubst %,libxt_%.o,${pfx_build_mod})
54pfb_objs      := $(patsubst %,libebt_%.o,${pfb_build_mod})
55pfa_objs      := $(patsubst %,libarpt_%.o,${pfa_build_mod})
56pf4_objs      := $(patsubst %,libipt_%.o,${pf4_build_mod})
57pf6_objs      := $(patsubst %,libip6t_%.o,${pf6_build_mod})
58pfx_solibs    := $(patsubst %,libxt_%.so,${pfx_build_mod})
59pfb_solibs    := $(patsubst %,libebt_%.so,${pfb_build_mod})
60pfa_solibs    := $(patsubst %,libarpt_%.so,${pfa_build_mod})
61pf4_solibs    := $(patsubst %,libipt_%.so,${pf4_build_mod})
62pf6_solibs    := $(patsubst %,libip6t_%.so,${pf6_build_mod})
63pfx_symlink_files := $(patsubst %,libxt_%.so,${pfx_symlinks})
64
65
66#
67# Building blocks
68#
69targets := libext.a libext4.a libext6.a libext_ebt.a libext_arpt.a matches.man targets.man
70targets_install :=
71@ENABLE_STATIC_TRUE@ libext_objs := ${pfx_objs}
72@ENABLE_STATIC_TRUE@ libext_ebt_objs := ${pfb_objs}
73@ENABLE_STATIC_TRUE@ libext_arpt_objs := ${pfa_objs}
74@ENABLE_STATIC_TRUE@ libext4_objs := ${pf4_objs}
75@ENABLE_STATIC_TRUE@ libext6_objs := ${pf6_objs}
76@ENABLE_STATIC_FALSE@ targets += ${pfx_solibs} ${pfb_solibs} ${pf4_solibs} ${pf6_solibs} ${pfa_solibs} ${pfx_symlink_files}
77@ENABLE_STATIC_FALSE@ targets_install += ${pfx_solibs} ${pfb_solibs} ${pf4_solibs} ${pf6_solibs} ${pfa_solibs}
78@ENABLE_STATIC_FALSE@ symlinks_install := ${pfx_symlink_files}
79
80.SECONDARY:
81
82.PHONY: all install uninstall clean distclean FORCE
83
84all: ${targets}
85
86install: ${targets_install} ${symlinks_install}
87	@mkdir -p "${DESTDIR}${xtlibdir}";
88	if test -n "${targets_install}"; then \
89		install -pm0755 ${targets_install} "${DESTDIR}${xtlibdir}/"; \
90	fi;
91	if test -n "${symlinks_install}"; then \
92		cp -P ${symlinks_install} "${DESTDIR}${xtlibdir}/"; \
93	fi;
94
95uninstall:
96	dir=${DESTDIR}${xtlibdir}; { \
97		test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; \
98	} || { \
99		test -z "${targets_install}" || ( \
100			cd "$$dir" && rm -f ${targets_install} \
101		); \
102		test -z "${symlinks_install}" || ( \
103			cd "$$dir" && rm -f ${symlinks_install} \
104		); \
105		rmdir -p --ignore-fail-on-non-empty "$$dir"; \
106	}
107
108clean:
109	rm -f *.o *.oo *.so *.a {matches,targets}.man initext.c initext4.c initext6.c initextb.c initexta.c;
110	rm -f .*.d .*.dd;
111
112distclean: clean
113
114init%.o: init%.c
115	${AM_VERBOSE_CC} ${CC} ${AM_CPPFLAGS} ${AM_DEPFLAGS} ${AM_CFLAGS} -D_INIT=$*_init ${CFLAGS} -o $@ -c $<;
116
117-include .*.d
118
119
120#
121#	Shared libraries
122#
123lib%.so: lib%.oo
124	${AM_VERBOSE_CCLD} ${CCLD} ${AM_LDFLAGS} ${LDFLAGS} -shared -o $@ $< -L../libxtables/.libs -lxtables ${$*_LIBADD};
125
126lib%.oo: ${srcdir}/lib%.c
127	${AM_VERBOSE_CC} ${CC} ${AM_CPPFLAGS} ${AM_DEPFLAGS} ${AM_CFLAGS} -D_INIT=lib$*_init -DPIC -fPIC ${CFLAGS} -o $@ -c $<;
128
129libxt_NOTRACK.so: libxt_CT.so
130	ln -fs $< $@
131libxt_state.so: libxt_conntrack.so
132	ln -fs $< $@
133
134# Need the LIBADDs in iptables/Makefile.am too for libxtables_la_LIBADD
135xt_RATEEST_LIBADD   = -lm
136xt_statistic_LIBADD = -lm
137xt_connlabel_LIBADD = @libnetfilter_conntrack_LIBS@
138
139#
140#	Static bits
141#
142#	If static building is disabled, libext*.a will still be generated,
143#	but will be empty. This is good since we can do with less case
144#	handling code in the Makefiles.
145#
146lib%.o: ${srcdir}/lib%.c
147	${AM_VERBOSE_CC} ${CC} ${AM_CPPFLAGS} ${AM_DEPFLAGS} ${AM_CFLAGS} -DNO_SHARED_LIBS=1 -D_INIT=lib$*_init ${CFLAGS} -o $@ -c $<;
148
149libext.a: initext.o ${libext_objs}
150	${AM_VERBOSE_AR} ${AR} crs $@ $^;
151
152libext_ebt.a: initextb.o ${libext_ebt_objs}
153	${AM_VERBOSE_AR} ${AR} crs $@ $^;
154
155libext_arpt.a: initexta.o ${libext_arpt_objs}
156	${AM_VERBOSE_AR} ${AR} crs $@ $^;
157
158libext4.a: initext4.o ${libext4_objs}
159	${AM_VERBOSE_AR} ${AR} crs $@ $^;
160
161libext6.a: initext6.o ${libext6_objs}
162	${AM_VERBOSE_AR} ${AR} crs $@ $^;
163
164initext_func  := $(addprefix xt_,${pfx_build_mod})
165initextb_func := $(addprefix ebt_,${pfb_build_mod})
166initexta_func := $(addprefix arpt_,${pfa_build_mod})
167initext4_func := $(addprefix ipt_,${pf4_build_mod})
168initext6_func := $(addprefix ip6t_,${pf6_build_mod})
169
170.initext.dd: FORCE
171	@echo "${initext_func}" >$@.tmp; \
172	cmp -s $@ $@.tmp || mv $@.tmp $@; \
173	rm -f $@.tmp;
174
175.initextb.dd: FORCE
176	@echo "${initextb_func}" >$@.tmp; \
177	cmp -s $@ $@.tmp || mv $@.tmp $@; \
178	rm -f $@.tmp;
179
180.initexta.dd: FORCE
181	@echo "${initexta_func}" >$@.tmp; \
182	cmp -s $@ $@.tmp || mv $@.tmp $@; \
183	rm -f $@.tmp;
184
185.initext4.dd: FORCE
186	@echo "${initext4_func}" >$@.tmp; \
187	cmp -s $@ $@.tmp || mv $@.tmp $@; \
188	rm -f $@.tmp;
189
190.initext6.dd: FORCE
191	@echo "${initext6_func}" >$@.tmp; \
192	cmp -s $@ $@.tmp || mv $@.tmp $@; \
193	rm -f $@.tmp;
194
195initext.c: .initext.dd
196	${AM_VERBOSE_GEN}
197	@( \
198	echo "" >$@; \
199	for i in ${initext_func}; do \
200		echo "extern void lib$${i}_init(void);" >>$@; \
201	done; \
202	echo "void init_extensions(void);" >>$@; \
203	echo "void init_extensions(void)" >>$@; \
204	echo "{" >>$@; \
205	for i in ${initext_func}; do \
206		echo  " ""lib$${i}_init();" >>$@; \
207	done; \
208	echo "}" >>$@; \
209	);
210
211initextb.c: .initextb.dd
212	${AM_VERBOSE_GEN}
213	@( \
214	echo "" >$@; \
215	for i in ${initextb_func}; do \
216		echo "extern void lib$${i}_init(void);" >>$@; \
217	done; \
218	echo "void init_extensionsb(void);" >>$@; \
219	echo "void init_extensionsb(void)" >>$@; \
220	echo "{" >>$@; \
221	for i in ${initextb_func}; do \
222		echo  " ""lib$${i}_init();" >>$@; \
223	done; \
224	echo "}" >>$@; \
225	);
226
227initexta.c: .initexta.dd
228	${AM_VERBOSE_GEN}
229	@( \
230	echo "" >$@; \
231	for i in ${initexta_func}; do \
232		echo "extern void lib$${i}_init(void);" >>$@; \
233	done; \
234	echo "void init_extensionsa(void);" >>$@; \
235	echo "void init_extensionsa(void)" >>$@; \
236	echo "{" >>$@; \
237	for i in ${initexta_func}; do \
238		echo  " ""lib$${i}_init();" >>$@; \
239	done; \
240	echo "}" >>$@; \
241	);
242
243initext4.c: .initext4.dd
244	${AM_VERBOSE_GEN}
245	@( \
246	echo "" >$@; \
247	for i in ${initext4_func}; do \
248		echo "extern void lib$${i}_init(void);" >>$@; \
249	done; \
250	echo "void init_extensions4(void);" >>$@; \
251	echo "void init_extensions4(void)" >>$@; \
252	echo "{" >>$@; \
253	for i in ${initext4_func}; do \
254		echo  " ""lib$${i}_init();" >>$@; \
255	done; \
256	echo "}" >>$@; \
257	);
258
259initext6.c: .initext6.dd
260	${AM_VERBOSE_GEN}
261	@( \
262	echo "" >$@; \
263	for i in ${initext6_func}; do \
264		echo "extern void lib$${i}_init(void);" >>$@; \
265	done; \
266	echo "void init_extensions6(void);" >>$@; \
267	echo "void init_extensions6(void)" >>$@; \
268	echo "{" >>$@; \
269	for i in ${initext6_func}; do \
270		echo " ""lib$${i}_init();" >>$@; \
271	done; \
272	echo "}" >>$@; \
273	);
274
275#
276#	Manual pages
277#
278ex_matches = $(shell echo ${1} | LC_ALL=POSIX grep -Eo '\b[[:lower:][:digit:]_]+\b')
279ex_targets = $(shell echo ${1} | LC_ALL=POSIX grep -Eo '\b[[:upper:][:digit:]_]+\b')
280man_run    = \
281	${AM_VERBOSE_GEN} \
282	for ext in $(sort ${1}); do \
283		f="${srcdir}/libxt_$$ext.man"; \
284		if [ -f "$$f" ]; then \
285			echo -e "\t+ $$f" >&2; \
286			echo ".SS $$ext"; \
287			cat "$$f" || exit $$?; \
288		fi; \
289		f="${srcdir}/libip6t_$$ext.man"; \
290		if [ -f "$$f" ]; then \
291			echo -e "\t+ $$f" >&2; \
292			echo ".SS $$ext (IPv6-specific)"; \
293			cat "$$f" || exit $$?; \
294		fi; \
295		f="${srcdir}/libipt_$$ext.man"; \
296		if [ -f "$$f" ]; then \
297			echo -e "\t+ $$f" >&2; \
298			echo ".SS $$ext (IPv4-specific)"; \
299			cat "$$f" || exit $$?; \
300		fi; \
301	done >$@;
302
303matches.man: .initext.dd .initextb.dd .initexta.dd .initext4.dd .initext6.dd $(wildcard ${srcdir}/lib*.man)
304	$(call man_run,$(call ex_matches,${pfx_build_mod} ${pfb_build_mod} ${pfa_build_mod} ${pf4_build_mod} ${pf6_build_mod} ${pfx_symlinks}))
305
306targets.man: .initext.dd .initextb.dd .initexta.dd .initext4.dd .initext6.dd $(wildcard ${srcdir}/lib*.man)
307	$(call man_run,$(call ex_targets,${pfx_build_mod} ${pfb_build_mod} ${pfa_build_mod} ${pf4_build_mod} ${pf6_build_mod} ${pfx_symlinks}))
308