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_srcdir}/include ${kinclude_CPPFLAGS} 25 AM_DEPFLAGS = -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@ 26 27 ifeq (${V},) 28 AM_LIBTOOL_SILENT = --silent 29 AM_VERBOSE_CC = @echo " CC " $@; 30 AM_VERBOSE_CCLD = @echo " CCLD " $@; 31 AM_VERBOSE_CXX = @echo " CXX " $@; 32 AM_VERBOSE_CXXLD = @echo " CXXLD " $@; 33 AM_VERBOSE_AR = @echo " AR " $@; 34 AM_VERBOSE_GEN = @echo " GEN " $@; 35 endif 36 37 # 38 # Wildcard module list 39 # 40 pfx_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)) 43 pfx_build_mod := $(filter-out @blacklist_modules@,${pfx_build_mod}) 44 pf4_build_mod := $(filter-out @blacklist_modules@,${pf4_build_mod}) 45 pf6_build_mod := $(filter-out @blacklist_modules@,${pf6_build_mod}) 46 pfx_objs := $(patsubst %,libxt_%.o,${pfx_build_mod}) 47 pf4_objs := $(patsubst %,libipt_%.o,${pf4_build_mod}) 48 pf6_objs := $(patsubst %,libip6t_%.o,${pf6_build_mod}) 49 pfx_solibs := $(patsubst %,libxt_%.so,${pfx_build_mod}) 50 pf4_solibs := $(patsubst %,libipt_%.so,${pf4_build_mod}) 51 pf6_solibs := $(patsubst %,libip6t_%.so,${pf6_build_mod}) 52 53 54 # 55 # Building blocks 56 # 57 targets := libext.a libext4.a libext6.a \ 58 matches4.man matches6.man \ 59 targets4.man targets6.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}[46].man initext.c initext4.c initext6.c; 79 80 distclean: clean 81 rm -f .*.d .*.dd; 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 $@ $<; 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 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 # 106 lib%.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 109 libext.a: initext.o ${libext_objs} 110 ${AM_VERBOSE_AR} ${AR} crs $@ $^; 111 112 libext4.a: initext4.o ${libext4_objs} 113 ${AM_VERBOSE_AR} ${AR} crs $@ $^; 114 115 libext6.a: initext6.o ${libext6_objs} 116 ${AM_VERBOSE_AR} ${AR} crs $@ $^; 117 118 initext_func := $(addprefix xt_,${pfx_build_mod}) 119 initext4_func := $(addprefix ipt_,${pf4_build_mod}) 120 initext6_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 137 initext.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 153 initext4.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 169 initext6.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 # 188 ex_matches = $(sort $(shell echo $(1) | LC_ALL=POSIX grep -Eo '\b[[:lower:][:digit:]_]+\b')) 189 ex_targets = $(sort $(shell echo $(1) | LC_ALL=POSIX grep -Eo '\b[[:upper:][:digit:]_]+\b')) 190 man_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 210 matches4.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 213 matches6.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 216 targets4.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 219 targets6.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