1 # -*- Makefile -*- 2 3 top_builddir = @top_builddir@ 4 builddir = @builddir@ 5 top_srcdir = @top_srcdir@ 6 srcdir = @srcdir@ 7 ksourcedir = @ksourcedir@ 8 prefix = @prefix@ 9 exec_prefix = @exec_prefix@ 10 libdir = @libdir@ 11 libexecdir = @libexecdir@ 12 xtlibdir = @xtlibdir@ 13 14 CC = @CC@ 15 CCLD = ${CC} 16 CFLAGS = @CFLAGS@ 17 CPPFLAGS = @CPPFLAGS@ 18 LDFLAGS = @LDFLAGS@ 19 regular_CFLAGS = @regular_CFLAGS@ 20 regular_CPPFLAGS = @regular_CPPFLAGS@ 21 kinclude_CPPFLAGS = @kinclude_CPPFLAGS@ 22 23 AM_CFLAGS = ${regular_CFLAGS} 24 AM_CPPFLAGS = ${regular_CPPFLAGS} -I${top_builddir}/include -I${top_builddir} -I${top_srcdir}/include ${kinclude_CPPFLAGS} @libnetfilter_conntrack_CFLAGS@ 25 AM_DEPFLAGS = -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@ 26 AM_LDFLAGS = @noundef_LDFLAGS@ 27 28 ifeq (${V},) 29 AM_LIBTOOL_SILENT = --silent 30 AM_VERBOSE_CC = @echo " CC " $@; 31 AM_VERBOSE_CCLD = @echo " CCLD " $@; 32 AM_VERBOSE_CXX = @echo " CXX " $@; 33 AM_VERBOSE_CXXLD = @echo " CXXLD " $@; 34 AM_VERBOSE_AR = @echo " AR " $@; 35 AM_VERBOSE_GEN = @echo " GEN " $@; 36 endif 37 38 # 39 # Wildcard module list 40 # 41 pfx_build_mod := $(patsubst ${srcdir}/libxt_%.c,%,$(sort $(wildcard ${srcdir}/libxt_*.c))) 42 pfx_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))) 45 pfx_build_mod := $(filter-out @blacklist_modules@,${pfx_build_mod}) 46 pf4_build_mod := $(filter-out @blacklist_modules@,${pf4_build_mod}) 47 pf6_build_mod := $(filter-out @blacklist_modules@,${pf6_build_mod}) 48 pfx_objs := $(patsubst %,libxt_%.o,${pfx_build_mod}) 49 pf4_objs := $(patsubst %,libipt_%.o,${pf4_build_mod}) 50 pf6_objs := $(patsubst %,libip6t_%.o,${pf6_build_mod}) 51 pfx_solibs := $(patsubst %,libxt_%.so,${pfx_build_mod} ${pfx_symlinks}) 52 pf4_solibs := $(patsubst %,libipt_%.so,${pf4_build_mod}) 53 pf6_solibs := $(patsubst %,libip6t_%.so,${pf6_build_mod}) 54 55 56 # 57 # Building blocks 58 # 59 targets := libext.a libext4.a libext6.a matches.man targets.man 60 targets_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 71 all: ${targets} 72 73 install: ${targets_install} 74 @mkdir -p "${DESTDIR}${xtlibdir}"; 75 if test -n "${targets_install}"; then install -pm0755 $^ "${DESTDIR}${xtlibdir}/"; fi; 76 77 clean: 78 rm -f *.o *.oo *.so *.a {matches,targets}.man initext.c initext4.c initext6.c; 79 rm -f .*.d .*.dd; 80 81 distclean: clean 82 83 init%.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 # 92 lib%.so: lib%.oo 93 ${AM_VERBOSE_CCLD} ${CCLD} ${AM_LDFLAGS} -shared ${LDFLAGS} -o $@ $< -L../libxtables/.libs -lxtables ${$*_LIBADD}; 94 95 lib%.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 98 libxt_NOTRACK.so: libxt_CT.so 99 ln -fs $< $@ 100 libxt_state.so: libxt_conntrack.so 101 ln -fs $< $@ 102 103 # Need the LIBADDs in iptables/Makefile.am too for libxtables_la_LIBADD 104 xt_RATEEST_LIBADD = -lm 105 xt_statistic_LIBADD = -lm 106 xt_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 # 115 lib%.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 118 libext.a: initext.o ${libext_objs} 119 ${AM_VERBOSE_AR} ${AR} crs $@ $^; 120 121 libext4.a: initext4.o ${libext4_objs} 122 ${AM_VERBOSE_AR} ${AR} crs $@ $^; 123 124 libext6.a: initext6.o ${libext6_objs} 125 ${AM_VERBOSE_AR} ${AR} crs $@ $^; 126 127 initext_func := $(addprefix xt_,${pfx_build_mod}) 128 initext4_func := $(addprefix ipt_,${pf4_build_mod}) 129 initext6_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 146 initext.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 162 initext4.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 178 initext6.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 # 197 ex_matches = $(shell echo ${1} | LC_ALL=POSIX grep -Eo '\b[[:lower:][:digit:]_]+\b') 198 ex_targets = $(shell echo ${1} | LC_ALL=POSIX grep -Eo '\b[[:upper:][:digit:]_]+\b') 199 man_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 222 matches.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 225 targets.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