lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 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 | LDFLAGS := @LDFLAGS@ |
| 18 | regular_CFLAGS := @regular_CFLAGS@ |
| 19 | kinclude_CFLAGS := @kinclude_CFLAGS@ |
| 20 | |
| 21 | AM_CFLAGS := ${regular_CFLAGS} -I${top_builddir}/include -I${top_srcdir}/include ${kinclude_CFLAGS} |
| 22 | AM_DEPFLAGS = -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@ |
| 23 | |
| 24 | ifeq (${V},) |
| 25 | AM_LIBTOOL_SILENT = --silent |
| 26 | AM_VERBOSE_CC = @echo " CC " $@; |
| 27 | AM_VERBOSE_CCLD = @echo " CCLD " $@; |
| 28 | AM_VERBOSE_CXX = @echo " CXX " $@; |
| 29 | AM_VERBOSE_CXXLD = @echo " CXXLD " $@; |
| 30 | AM_VERBOSE_AR = @echo " AR " $@; |
| 31 | AM_VERBOSE_GEN = @echo " GEN " $@; |
| 32 | endif |
| 33 | |
| 34 | # |
| 35 | # Wildcard module list |
| 36 | # |
| 37 | pfx_build_mod := $(patsubst ${srcdir}/libxt_%.c,%,$(wildcard ${srcdir}/libxt_*.c)) |
| 38 | @ENABLE_IPV4_TRUE@ pf4_build_mod := $(patsubst ${srcdir}/libipt_%.c,%,$(wildcard ${srcdir}/libipt_*.c)) |
| 39 | @ENABLE_IPV6_TRUE@ pf6_build_mod := $(patsubst ${srcdir}/libip6t_%.c,%,$(wildcard ${srcdir}/libip6t_*.c)) |
| 40 | pfx_build_mod := $(filter-out @blacklist_modules@,${pfx_build_mod}) |
| 41 | pf4_build_mod := $(filter-out @blacklist_modules@,${pf4_build_mod}) |
| 42 | pf6_build_mod := $(filter-out @blacklist_modules@,${pf6_build_mod}) |
| 43 | |
| 44 | # Only build matches/targets for the current kernel config |
| 45 | -include $(LINUX_DIR)/.config |
| 46 | lower=$(shell echo $(1) | tr [:upper:] [:lower:]) |
| 47 | upper=$(shell echo $(1) | tr [:lower:] [:upper:]) |
| 48 | keeplower=$(filter-out $(call upper,$(1)),$(1)) |
| 49 | keepupper=$(filter-out $(call lower,$(1)),$(1)) |
| 50 | TEST_CONFIG_VAL=$(patsubst $(3)_%,%,$(filter $(3)_%,$(foreach i,$(1),$(CONFIG_$(2)_$(i))_$(i)))) |
| 51 | TEST_CONFIG_TYPE=$(call TEST_CONFIG_VAL,$(1),$(2),y) $(call TEST_CONFIG_VAL,$(1),$(2),m) |
| 52 | TEST_CONFIG=$(call TEST_CONFIG_TYPE,$(1),$(2)_$(3)) $(call TEST_CONFIG_TYPE,$(1),NETFILTER_XT_$(3)) |
| 53 | |
| 54 | PF_EXT_SLIB_BASE:=icmp |
| 55 | PF_EXT_SLIB_OPT:=$(filter-out $(PF_EXT_SLIB_BASE),$(pf4_build_mod)) |
| 56 | PF_EXT_SLIB_MATCH:=$(sort $(call upper,$(call keeplower,$(PF_EXT_SLIB_OPT)))) |
| 57 | PF_EXT_SLIB_TARGET:=$(sort $(call keepupper,$(PF_EXT_SLIB_OPT))) |
| 58 | pf4_build_mod:=$(PF_EXT_SLIB_BASE) |
| 59 | pf4_build_mod+=$(call lower,$(call TEST_CONFIG,$(PF_EXT_SLIB_MATCH),IP_NF,MATCH)) |
| 60 | pf4_build_mod+=$(call TEST_CONFIG,$(PF_EXT_SLIB_TARGET),IP_NF,TARGET) |
| 61 | |
| 62 | PF6_EXT_SLIB_BASE:=icmp6 |
| 63 | PF6_EXT_SLIB_OPT:=$(filter-out $(PF6_EXT_SLIB_BASE),$(pf6_build_mod)) |
| 64 | PF6_EXT_SLIB_MATCH:=$(sort $(call upper,$(call keeplower,$(PF6_EXT_SLIB_OPT)))) |
| 65 | PF6_EXT_SLIB_TARGET:=$(sort $(call keepupper,$(PF6_EXT_SLIB_OPT))) |
| 66 | pf6_build_mod:=$(PF6_EXT_SLIB_BASE) |
| 67 | pf6_build_mod+=$(call lower,$(call TEST_CONFIG,$(PF6_EXT_SLIB_MATCH),IP6_NF,MATCH)) |
| 68 | pf6_build_mod+=$(call TEST_CONFIG,$(PF6_EXT_SLIB_TARGET),IP6_NF,TARGET) |
| 69 | |
| 70 | PFX_EXT_SLIB_BASE:=tcp udp standard |
| 71 | PFX_EXT_SLIB_OPT:=$(filter-out $(PFX_EXT_SLIB_BASE),$(pfx_build_mod)) |
| 72 | PFX_EXT_SLIB_MATCH:=$(sort $(call upper,$(call keeplower,$(PFX_EXT_SLIB_OPT)))) |
| 73 | PFX_EXT_SLIB_TARGET:=$(sort $(call keepupper,$(PFX_EXT_SLIB_OPT))) |
| 74 | pfx_build_mod:=$(PFX_EXT_SLIB_BASE) |
| 75 | pfx_build_mod+=$(call lower,$(call TEST_CONFIG,$(PFX_EXT_SLIB_MATCH),IP_NF,MATCH)) |
| 76 | pfx_build_mod+=$(call TEST_CONFIG,$(PFX_EXT_SLIB_TARGET),IP_NF,TARGET) |
| 77 | ifeq ($(DO_IPV6), 1) |
| 78 | pfx_build_mod+=$(call lower,$(call TEST_CONFIG,$(PFX_EXT_SLIB_MATCH),IP6_NF,MATCH)) |
| 79 | pfx_build_mod+=$(call TEST_CONFIG,$(PFX_EXT_SLIB_TARGET),IP6_NF,TARGET) |
| 80 | endif |
| 81 | pfx_build_mod:=$(sort $(pfx_build_mod)) |
| 82 | |
| 83 | ifneq ($(CONFIG_NETFILTER_XT_TARGET_DSCP),) |
| 84 | pfx_build_mod+=TOS |
| 85 | endif |
| 86 | ifneq ($(CONFIG_IP_NF_NAT)$(CONFIG_NF_NAT),) |
| 87 | pf4_build_mod+=SNAT DNAT |
| 88 | endif |
| 89 | ifneq ($(CONFIG_IP_NF_MATCH_AH_ESP),) |
| 90 | pf4_build_mod+=ah |
| 91 | pfx_build_mod+=esp |
| 92 | endif |
| 93 | pfx_build_mod+=webstr |
| 94 | |
| 95 | pfx_objs := $(patsubst %,libxt_%.o,${pfx_build_mod}) |
| 96 | pf4_objs := $(patsubst %,libipt_%.o,${pf4_build_mod}) |
| 97 | pf6_objs := $(patsubst %,libip6t_%.o,${pf6_build_mod}) |
| 98 | pfx_solibs := $(patsubst %,libxt_%.so,${pfx_build_mod}) |
| 99 | pf4_solibs := $(patsubst %,libipt_%.so,${pf4_build_mod}) |
| 100 | pf6_solibs := $(patsubst %,libip6t_%.so,${pf6_build_mod}) |
| 101 | |
| 102 | |
| 103 | # |
| 104 | # Building blocks |
| 105 | # |
| 106 | targets := libext4.a libext6.a matches4.man matches6.man \ |
| 107 | targets4.man targets6.man |
| 108 | targets_install := |
| 109 | @ENABLE_STATIC_TRUE@ libext4_objs := ${pfx_objs} ${pf4_objs} |
| 110 | @ENABLE_STATIC_TRUE@ libext6_objs := ${pfx_objs} ${pf6_objs} |
| 111 | @ENABLE_SHARED_TRUE@ targets += ${pfx_solibs} ${pf4_solibs} ${pf6_solibs} |
| 112 | @ENABLE_SHARED_TRUE@ targets_install += ${pfx_solibs} ${pf4_solibs} ${pf6_solibs} |
| 113 | |
| 114 | .SECONDARY: |
| 115 | |
| 116 | .PHONY: all install clean distclean FORCE |
| 117 | |
| 118 | all: ${targets} |
| 119 | |
| 120 | install: ${targets_install} |
| 121 | @mkdir -p "${DESTDIR}${xtlibdir}"; |
| 122 | if test -n "${targets_install}"; then install -pm0755 $^ "${DESTDIR}${xtlibdir}/"; fi; |
| 123 | |
| 124 | clean: |
| 125 | rm -f *.o *.oo *.so *.a {matches,targets}[46].man initext4.c initext6.c; |
| 126 | rm -f libipt_LED_def.c |
| 127 | |
| 128 | distclean: clean |
| 129 | rm -f .*.d .*.dd; |
| 130 | |
| 131 | init%.o: init%.c |
| 132 | ${AM_VERBOSE_CC} ${CC} ${AM_DEPFLAGS} ${AM_CFLAGS} -D_INIT=$*_init ${CFLAGS} -o $@ -c $<; |
| 133 | |
| 134 | -include .*.d |
| 135 | |
| 136 | |
| 137 | # |
| 138 | # Shared libraries |
| 139 | # |
| 140 | lib%.so: lib%.oo |
| 141 | ${AM_VERBOSE_CCLD} ${CCLD} ${AM_LDFLAGS} -shared ${LDFLAGS} -o $@ $<; |
| 142 | |
| 143 | lib%.oo: ${srcdir}/lib%.c |
| 144 | ${AM_VERBOSE_CC} ${CC} ${AM_DEPFLAGS} ${AM_CFLAGS} -D_INIT=lib$*_init -DPIC -fPIC ${CFLAGS} -o $@ -c $<; |
| 145 | |
| 146 | |
| 147 | # |
| 148 | # Static bits |
| 149 | # |
| 150 | # If static building is disabled, libext*.a will still be generated, |
| 151 | # but will be empty. This is good since we can do with less case |
| 152 | # handling code in the Makefiles. |
| 153 | # |
| 154 | lib%.o: ${srcdir}/lib%.c |
| 155 | ${AM_VERBOSE_CC} ${CC} ${AM_DEPFLAGS} ${AM_CFLAGS} -DNO_SHARED_LIBS=1 -D_INIT=lib$*_init ${CFLAGS} -o $@ -c $<; |
| 156 | |
| 157 | libext4.a: initext4.o ${libext4_objs} |
| 158 | ${AM_VERBOSE_AR} ${AR} crs $@ $^; |
| 159 | |
| 160 | libext6.a: initext6.o ${libext6_objs} |
| 161 | ${AM_VERBOSE_AR} ${AR} crs $@ $^; |
| 162 | |
| 163 | initext_func := $(sort $(addprefix xt_,${pfx_build_mod})) $(sort $(addprefix ipt_,${pf4_build_mod})) |
| 164 | initext6_func := $(sort $(addprefix xt_,${pfx_build_mod})) $(sort $(addprefix ip6t_,${pf6_build_mod})) |
| 165 | |
| 166 | .initext4.dd: FORCE |
| 167 | @echo "${initext_func}" >$@.tmp; \ |
| 168 | cmp -s $@ $@.tmp || mv $@.tmp $@; \ |
| 169 | rm -f $@.tmp; |
| 170 | |
| 171 | .initext6.dd: FORCE |
| 172 | @echo "${initext6_func}" >$@.tmp; \ |
| 173 | cmp -s $@ $@.tmp || mv $@.tmp $@; \ |
| 174 | rm -f $@.tmp; |
| 175 | |
| 176 | initext4.c: .initext4.dd |
| 177 | ${AM_VERBOSE_GEN} |
| 178 | @( \ |
| 179 | echo "" >$@; \ |
| 180 | for i in ${initext_func}; do \ |
| 181 | echo "extern void lib$${i}_init(void);" >>$@; \ |
| 182 | done; \ |
| 183 | echo "void init_extensions(void);" >>$@; \ |
| 184 | echo "void init_extensions(void)" >>$@; \ |
| 185 | echo "{" >>$@; \ |
| 186 | for i in ${initext_func}; do \ |
| 187 | echo " ""lib$${i}_init();" >>$@; \ |
| 188 | done; \ |
| 189 | echo "}" >>$@; \ |
| 190 | ); |
| 191 | |
| 192 | initext6.c: .initext6.dd |
| 193 | ${AM_VERBOSE_GEN} |
| 194 | @( \ |
| 195 | echo "" >$@; \ |
| 196 | for i in ${initext6_func}; do \ |
| 197 | echo "extern void lib$${i}_init(void);" >>$@; \ |
| 198 | done; \ |
| 199 | echo "void init_extensions(void);" >>$@; \ |
| 200 | echo "void init_extensions(void)" >>$@; \ |
| 201 | echo "{" >>$@; \ |
| 202 | for i in ${initext6_func}; do \ |
| 203 | echo " ""lib$${i}_init();" >>$@; \ |
| 204 | done; \ |
| 205 | echo "}" >>$@; \ |
| 206 | ); |
| 207 | |
| 208 | libipt_LED.o: libipt_LED_def.c |
| 209 | |
| 210 | LEDMAN = $(LINUX_DIR)/include/linux/ledman.h |
| 211 | libipt_LED_def.c: libipt_LED_def.pl $(LEDMAN) |
| 212 | perl $< <$(LEDMAN) >$@ |
| 213 | |
| 214 | # |
| 215 | # Manual pages |
| 216 | # |
| 217 | ex_matches = $(sort $(shell echo $(1) | grep -Eo '\b[a-z0-9]+\b')) |
| 218 | ex_targets = $(sort $(shell echo $(1) | grep -Eo '\b[A-Z0-9]+\b')) |
| 219 | man_run = \ |
| 220 | ${AM_VERBOSE_GEN} \ |
| 221 | for ext in $(1); do \ |
| 222 | f="${srcdir}/libxt_$$ext.man"; \ |
| 223 | if [ -f "$$f" ]; then \ |
| 224 | echo ".SS $$ext"; \ |
| 225 | cat "$$f"; \ |
| 226 | continue; \ |
| 227 | fi; \ |
| 228 | f="${srcdir}/lib$(2)t_$$ext.man"; \ |
| 229 | if [ -f "$$f" ]; then \ |
| 230 | echo ".SS $$ext"; \ |
| 231 | cat "$$f"; \ |
| 232 | continue; \ |
| 233 | fi; \ |
| 234 | done >$@; |
| 235 | |
| 236 | matches4.man: .initext4.dd $(wildcard ${srcdir}/lib*.man) |
| 237 | $(call man_run,$(call ex_matches,${pfx_build_mod} ${pf4_build_mod}),ip) |
| 238 | |
| 239 | matches6.man: .initext6.dd $(wildcard ${srcdir}/lib*.man) |
| 240 | $(call man_run,$(call ex_matches,${pfx_build_mod} ${pf6_build_mod}),ip6) |
| 241 | |
| 242 | targets4.man: .initext4.dd $(wildcard ${srcdir}/lib*.man) |
| 243 | $(call man_run,$(call ex_targets,${pfx_build_mod} ${pf4_build_mod}),ip) |
| 244 | |
| 245 | targets6.man: .initext6.dd $(wildcard ${srcdir}/lib*.man) |
| 246 | $(call man_run,$(call ex_targets,${pfx_build_mod} ${pf6_build_mod}),ip6) |