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_srcdir}/include ${kinclude_CPPFLAGS} 25AM_DEPFLAGS = -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@ 26 27ifeq (${V},) 28AM_LIBTOOL_SILENT = --silent 29AM_VERBOSE_CC = @echo " CC " $@; 30AM_VERBOSE_CCLD = @echo " CCLD " $@; 31AM_VERBOSE_CXX = @echo " CXX " $@; 32AM_VERBOSE_CXXLD = @echo " CXXLD " $@; 33AM_VERBOSE_AR = @echo " AR " $@; 34AM_VERBOSE_GEN = @echo " GEN " $@; 35endif 36 37# 38# Wildcard module list 39# 40pfx_build_mod := $(patsubst ${srcdir}/libxt_%.c,%,$(wildcard ${srcdir}/libxt_*.c)) 41@ENABLE_IPV4_TRUE@ pf4_build_mod := $(patsubst ${srcdir}/libipt_%.c,%,$(wildcard ${srcdir}/libipt_*.c)) 42@ENABLE_IPV6_TRUE@ pf6_build_mod := $(patsubst ${srcdir}/libip6t_%.c,%,$(wildcard ${srcdir}/libip6t_*.c)) 43pfx_build_mod := $(filter-out @blacklist_modules@,${pfx_build_mod}) 44pf4_build_mod := $(filter-out @blacklist_modules@,${pf4_build_mod}) 45pf6_build_mod := $(filter-out @blacklist_modules@,${pf6_build_mod}) 46pfx_objs := $(patsubst %,libxt_%.o,${pfx_build_mod}) 47pf4_objs := $(patsubst %,libipt_%.o,${pf4_build_mod}) 48pf6_objs := $(patsubst %,libip6t_%.o,${pf6_build_mod}) 49pfx_solibs := $(patsubst %,libxt_%.so,${pfx_build_mod}) 50pf4_solibs := $(patsubst %,libipt_%.so,${pf4_build_mod}) 51pf6_solibs := $(patsubst %,libip6t_%.so,${pf6_build_mod}) 52 53 54# 55# Building blocks 56# 57targets := libext.a libext4.a libext6.a \ 58 matches4.man matches6.man \ 59 targets4.man targets6.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}[46].man initext.c initext4.c initext6.c; 79 80distclean: clean 81 rm -f .*.d .*.dd; 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 $@ $<; 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 98 99# 100# Static bits 101# 102# If static building is disabled, libext*.a will still be generated, 103# but will be empty. This is good since we can do with less case 104# handling code in the Makefiles. 105# 106lib%.o: ${srcdir}/lib%.c 107 ${AM_VERBOSE_CC} ${CC} ${AM_CPPFLAGS} ${AM_DEPFLAGS} ${AM_CFLAGS} -DNO_SHARED_LIBS=1 -D_INIT=lib$*_init ${CFLAGS} -o $@ -c $<; 108 109libext.a: initext.o ${libext_objs} 110 ${AM_VERBOSE_AR} ${AR} crs $@ $^; 111 112libext4.a: initext4.o ${libext4_objs} 113 ${AM_VERBOSE_AR} ${AR} crs $@ $^; 114 115libext6.a: initext6.o ${libext6_objs} 116 ${AM_VERBOSE_AR} ${AR} crs $@ $^; 117 118initext_func := $(addprefix xt_,${pfx_build_mod}) 119initext4_func := $(addprefix ipt_,${pf4_build_mod}) 120initext6_func := $(addprefix ip6t_,${pf6_build_mod}) 121 122.initext.dd: FORCE 123 @echo "${initext_func}" >$@.tmp; \ 124 cmp -s $@ $@.tmp || mv $@.tmp $@; \ 125 rm -f $@.tmp; 126 127.initext4.dd: FORCE 128 @echo "${initext4_func}" >$@.tmp; \ 129 cmp -s $@ $@.tmp || mv $@.tmp $@; \ 130 rm -f $@.tmp; 131 132.initext6.dd: FORCE 133 @echo "${initext6_func}" >$@.tmp; \ 134 cmp -s $@ $@.tmp || mv $@.tmp $@; \ 135 rm -f $@.tmp; 136 137initext.c: .initext.dd 138 ${AM_VERBOSE_GEN} 139 @( \ 140 echo "" >$@; \ 141 for i in ${initext_func}; do \ 142 echo "extern void lib$${i}_init(void);" >>$@; \ 143 done; \ 144 echo "void init_extensions(void);" >>$@; \ 145 echo "void init_extensions(void)" >>$@; \ 146 echo "{" >>$@; \ 147 for i in ${initext_func}; do \ 148 echo " ""lib$${i}_init();" >>$@; \ 149 done; \ 150 echo "}" >>$@; \ 151 ); 152 153initext4.c: .initext4.dd 154 ${AM_VERBOSE_GEN} 155 @( \ 156 echo "" >$@; \ 157 for i in ${initext4_func}; do \ 158 echo "extern void lib$${i}_init(void);" >>$@; \ 159 done; \ 160 echo "void init_extensions4(void);" >>$@; \ 161 echo "void init_extensions4(void)" >>$@; \ 162 echo "{" >>$@; \ 163 for i in ${initext4_func}; do \ 164 echo " ""lib$${i}_init();" >>$@; \ 165 done; \ 166 echo "}" >>$@; \ 167 ); 168 169initext6.c: .initext6.dd 170 ${AM_VERBOSE_GEN} 171 @( \ 172 echo "" >$@; \ 173 for i in ${initext6_func}; do \ 174 echo "extern void lib$${i}_init(void);" >>$@; \ 175 done; \ 176 echo "void init_extensions6(void);" >>$@; \ 177 echo "void init_extensions6(void)" >>$@; \ 178 echo "{" >>$@; \ 179 for i in ${initext6_func}; do \ 180 echo " ""lib$${i}_init();" >>$@; \ 181 done; \ 182 echo "}" >>$@; \ 183 ); 184 185# 186# Manual pages 187# 188ex_matches = $(sort $(shell echo $(1) | LC_ALL=POSIX grep -Eo '\b[[:lower:][:digit:]_]+\b')) 189ex_targets = $(sort $(shell echo $(1) | LC_ALL=POSIX grep -Eo '\b[[:upper:][:digit:]_]+\b')) 190man_run = \ 191 ${AM_VERBOSE_GEN} \ 192 for ext in $(1); do \ 193 f="${srcdir}/libxt_$$ext.man"; \ 194 cf="${srcdir}/libxt_$$ext.c"; \ 195 if [ -f "$$f" ] && grep -Eq "$(3)|NFPROTO_UNSPEC" "$$cf"; then \ 196 echo -e "\t+ $$f" >&2; \ 197 echo ".SS $$ext"; \ 198 cat "$$f" || exit $$?; \ 199 continue; \ 200 fi; \ 201 f="${srcdir}/lib$(2)t_$$ext.man"; \ 202 if [ -f "$$f" ]; then \ 203 echo -e "\t+ $$f" >&2; \ 204 echo ".SS $$ext"; \ 205 cat "$$f" || exit $$?; \ 206 continue; \ 207 fi; \ 208 done >$@; 209 210matches4.man: .initext.dd .initext4.dd $(wildcard ${srcdir}/lib*.man) 211 $(call man_run,$(call ex_matches,${pfx_build_mod} ${pf4_build_mod}),ip,NFPROTO_IPV4) 212 213matches6.man: .initext.dd .initext6.dd $(wildcard ${srcdir}/lib*.man) 214 $(call man_run,$(call ex_matches,${pfx_build_mod} ${pf6_build_mod}),ip6,NFPROTO_IPV6) 215 216targets4.man: .initext.dd .initext4.dd $(wildcard ${srcdir}/lib*.man) 217 $(call man_run,$(call ex_targets,${pfx_build_mod} ${pf4_build_mod}),ip,NFPROTO_IPV4) 218 219targets6.man: .initext.dd .initext6.dd $(wildcard ${srcdir}/lib*.man) 220 $(call man_run,$(call ex_targets,${pfx_build_mod} ${pf6_build_mod}),ip6,NFPROTO_IPV6) 221