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 14CC = @CC@ 15CCLD = ${CC} 16CFLAGS = @CFLAGS@ 17CPPFLAGS = @CPPFLAGS@ 18LDFLAGS = @LDFLAGS@ 19regular_CFLAGS = @regular_CFLAGS@ 20regular_CPPFLAGS = @regular_CPPFLAGS@ 21kinclude_CPPFLAGS = @kinclude_CPPFLAGS@ 22 23AM_CFLAGS = ${regular_CFLAGS} 24AM_CPPFLAGS = ${regular_CPPFLAGS} -I${top_builddir}/include -I${top_builddir} -I${top_srcdir}/include ${kinclude_CPPFLAGS} @libnetfilter_conntrack_CFLAGS@ 25AM_DEPFLAGS = -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@ 26AM_LDFLAGS = @noundef_LDFLAGS@ 27 28ifeq (${V},) 29AM_LIBTOOL_SILENT = --silent 30AM_VERBOSE_CC = @echo " CC " $@; 31AM_VERBOSE_CCLD = @echo " CCLD " $@; 32AM_VERBOSE_CXX = @echo " CXX " $@; 33AM_VERBOSE_CXXLD = @echo " CXXLD " $@; 34AM_VERBOSE_AR = @echo " AR " $@; 35AM_VERBOSE_GEN = @echo " GEN " $@; 36endif 37 38# 39# Wildcard module list 40# 41pfx_build_mod := $(patsubst ${srcdir}/libxt_%.c,%,$(sort $(wildcard ${srcdir}/libxt_*.c))) 42pfx_symlinks := NOTRACK state 43@ENABLE_IPV4_TRUE@ pf4_build_mod := $(patsubst ${srcdir}/libipt_%.c,%,$(sort $(wildcard ${srcdir}/libipt_*.c))) 44@ENABLE_IPV6_TRUE@ pf6_build_mod := $(patsubst ${srcdir}/libip6t_%.c,%,$(sort $(wildcard ${srcdir}/libip6t_*.c))) 45pfx_build_mod := $(filter-out @blacklist_modules@,${pfx_build_mod}) 46pf4_build_mod := $(filter-out @blacklist_modules@,${pf4_build_mod}) 47pf6_build_mod := $(filter-out @blacklist_modules@,${pf6_build_mod}) 48pfx_objs := $(patsubst %,libxt_%.o,${pfx_build_mod}) 49pf4_objs := $(patsubst %,libipt_%.o,${pf4_build_mod}) 50pf6_objs := $(patsubst %,libip6t_%.o,${pf6_build_mod}) 51pfx_solibs := $(patsubst %,libxt_%.so,${pfx_build_mod} ${pfx_symlinks}) 52pf4_solibs := $(patsubst %,libipt_%.so,${pf4_build_mod}) 53pf6_solibs := $(patsubst %,libip6t_%.so,${pf6_build_mod}) 54 55 56# 57# Building blocks 58# 59targets := libext.a libext4.a libext6.a matches.man targets.man 60targets_install := 61@ENABLE_STATIC_TRUE@ libext_objs := ${pfx_objs} 62@ENABLE_STATIC_TRUE@ libext4_objs := ${pf4_objs} 63@ENABLE_STATIC_TRUE@ libext6_objs := ${pf6_objs} 64@ENABLE_STATIC_FALSE@ targets += ${pfx_solibs} ${pf4_solibs} ${pf6_solibs} 65@ENABLE_STATIC_FALSE@ targets_install += ${pfx_solibs} ${pf4_solibs} ${pf6_solibs} 66 67.SECONDARY: 68 69.PHONY: all install clean distclean FORCE 70 71all: ${targets} 72 73install: ${targets_install} 74 @mkdir -p "${DESTDIR}${xtlibdir}"; 75 if test -n "${targets_install}"; then install -pm0755 $^ "${DESTDIR}${xtlibdir}/"; fi; 76 77clean: 78 rm -f *.o *.oo *.so *.a {matches,targets}.man initext.c initext4.c initext6.c; 79 rm -f .*.d .*.dd; 80 81distclean: clean 82 83init%.o: init%.c 84 ${AM_VERBOSE_CC} ${CC} ${AM_CPPFLAGS} ${AM_DEPFLAGS} ${AM_CFLAGS} -D_INIT=$*_init ${CFLAGS} -o $@ -c $<; 85 86-include .*.d 87 88 89# 90# Shared libraries 91# 92lib%.so: lib%.oo 93 ${AM_VERBOSE_CCLD} ${CCLD} ${AM_LDFLAGS} -shared ${LDFLAGS} -o $@ $< -L../libxtables/.libs -lxtables ${$*_LIBADD}; 94 95lib%.oo: ${srcdir}/lib%.c 96 ${AM_VERBOSE_CC} ${CC} ${AM_CPPFLAGS} ${AM_DEPFLAGS} ${AM_CFLAGS} -D_INIT=lib$*_init -DPIC -fPIC ${CFLAGS} -o $@ -c $<; 97 98libxt_NOTRACK.so: libxt_CT.so 99 ln -fs $< $@ 100libxt_state.so: libxt_conntrack.so 101 ln -fs $< $@ 102 103# Need the LIBADDs in iptables/Makefile.am too for libxtables_la_LIBADD 104xt_RATEEST_LIBADD = -lm 105xt_statistic_LIBADD = -lm 106xt_connlabel_LIBADD = @libnetfilter_conntrack_LIBS@ 107 108# 109# Static bits 110# 111# If static building is disabled, libext*.a will still be generated, 112# but will be empty. This is good since we can do with less case 113# handling code in the Makefiles. 114# 115lib%.o: ${srcdir}/lib%.c 116 ${AM_VERBOSE_CC} ${CC} ${AM_CPPFLAGS} ${AM_DEPFLAGS} ${AM_CFLAGS} -DNO_SHARED_LIBS=1 -D_INIT=lib$*_init ${CFLAGS} -o $@ -c $<; 117 118libext.a: initext.o ${libext_objs} 119 ${AM_VERBOSE_AR} ${AR} crs $@ $^; 120 121libext4.a: initext4.o ${libext4_objs} 122 ${AM_VERBOSE_AR} ${AR} crs $@ $^; 123 124libext6.a: initext6.o ${libext6_objs} 125 ${AM_VERBOSE_AR} ${AR} crs $@ $^; 126 127initext_func := $(addprefix xt_,${pfx_build_mod}) 128initext4_func := $(addprefix ipt_,${pf4_build_mod}) 129initext6_func := $(addprefix ip6t_,${pf6_build_mod}) 130 131.initext.dd: FORCE 132 @echo "${initext_func}" >$@.tmp; \ 133 cmp -s $@ $@.tmp || mv $@.tmp $@; \ 134 rm -f $@.tmp; 135 136.initext4.dd: FORCE 137 @echo "${initext4_func}" >$@.tmp; \ 138 cmp -s $@ $@.tmp || mv $@.tmp $@; \ 139 rm -f $@.tmp; 140 141.initext6.dd: FORCE 142 @echo "${initext6_func}" >$@.tmp; \ 143 cmp -s $@ $@.tmp || mv $@.tmp $@; \ 144 rm -f $@.tmp; 145 146initext.c: .initext.dd 147 ${AM_VERBOSE_GEN} 148 @( \ 149 echo "" >$@; \ 150 for i in ${initext_func}; do \ 151 echo "extern void lib$${i}_init(void);" >>$@; \ 152 done; \ 153 echo "void init_extensions(void);" >>$@; \ 154 echo "void init_extensions(void)" >>$@; \ 155 echo "{" >>$@; \ 156 for i in ${initext_func}; do \ 157 echo " ""lib$${i}_init();" >>$@; \ 158 done; \ 159 echo "}" >>$@; \ 160 ); 161 162initext4.c: .initext4.dd 163 ${AM_VERBOSE_GEN} 164 @( \ 165 echo "" >$@; \ 166 for i in ${initext4_func}; do \ 167 echo "extern void lib$${i}_init(void);" >>$@; \ 168 done; \ 169 echo "void init_extensions4(void);" >>$@; \ 170 echo "void init_extensions4(void)" >>$@; \ 171 echo "{" >>$@; \ 172 for i in ${initext4_func}; do \ 173 echo " ""lib$${i}_init();" >>$@; \ 174 done; \ 175 echo "}" >>$@; \ 176 ); 177 178initext6.c: .initext6.dd 179 ${AM_VERBOSE_GEN} 180 @( \ 181 echo "" >$@; \ 182 for i in ${initext6_func}; do \ 183 echo "extern void lib$${i}_init(void);" >>$@; \ 184 done; \ 185 echo "void init_extensions6(void);" >>$@; \ 186 echo "void init_extensions6(void)" >>$@; \ 187 echo "{" >>$@; \ 188 for i in ${initext6_func}; do \ 189 echo " ""lib$${i}_init();" >>$@; \ 190 done; \ 191 echo "}" >>$@; \ 192 ); 193 194# 195# Manual pages 196# 197ex_matches = $(shell echo ${1} | LC_ALL=POSIX grep -Eo '\b[[:lower:][:digit:]_]+\b') 198ex_targets = $(shell echo ${1} | LC_ALL=POSIX grep -Eo '\b[[:upper:][:digit:]_]+\b') 199man_run = \ 200 ${AM_VERBOSE_GEN} \ 201 for ext in $(sort ${1}); do \ 202 f="${srcdir}/libxt_$$ext.man"; \ 203 if [ -f "$$f" ]; then \ 204 echo -e "\t+ $$f" >&2; \ 205 echo ".SS $$ext"; \ 206 cat "$$f" || exit $$?; \ 207 fi; \ 208 f="${srcdir}/libip6t_$$ext.man"; \ 209 if [ -f "$$f" ]; then \ 210 echo -e "\t+ $$f" >&2; \ 211 echo ".SS $$ext (IPv6-specific)"; \ 212 cat "$$f" || exit $$?; \ 213 fi; \ 214 f="${srcdir}/libipt_$$ext.man"; \ 215 if [ -f "$$f" ]; then \ 216 echo -e "\t+ $$f" >&2; \ 217 echo ".SS $$ext (IPv4-specific)"; \ 218 cat "$$f" || exit $$?; \ 219 fi; \ 220 done >$@; 221 222matches.man: .initext.dd .initext4.dd .initext6.dd $(wildcard ${srcdir}/lib*.man) 223 $(call man_run,$(call ex_matches,${pfx_build_mod} ${pf4_build_mod} ${pf6_build_mod} ${pfx_symlinks})) 224 225targets.man: .initext.dd .initext4.dd .initext6.dd $(wildcard ${srcdir}/lib*.man) 226 $(call man_run,$(call ex_targets,${pfx_build_mod} ${pf4_build_mod} ${pf6_build_mod} ${pfx_symlinks})) 227