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