(no commit message)
[iptables.git] / extensions / GNUmakefile.in
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 pf4_build_mod := $(patsubst ${srcdir}/libipt_%.c,%,$(wildcard ${srcdir}/libipt_*.c))
39 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 pfx_objs      := $(patsubst %,libxt_%.o,${pfx_build_mod})
44 pf4_objs      := $(patsubst %,libipt_%.o,${pf4_build_mod})
45 pf6_objs      := $(patsubst %,libip6t_%.o,${pf6_build_mod})
46 pfx_solibs    := $(patsubst %,libxt_%.so,${pfx_build_mod})
47 pf4_solibs    := $(patsubst %,libipt_%.so,${pf4_build_mod})
48 pf6_solibs    := $(patsubst %,libip6t_%.so,${pf6_build_mod})
49
50
51 #
52 # Building blocks
53 #
54 targets := libext4.a libext6.a matches4.man matches6.man \
55            targets4.man targets6.man
56 targets_install :=
57 @ENABLE_STATIC_TRUE@ libext4_objs := ${pfx_objs} ${pf4_objs}
58 @ENABLE_STATIC_TRUE@ libext6_objs := ${pfx_objs} ${pf6_objs}
59 @ENABLE_SHARED_TRUE@ targets += ${pfx_solibs} ${pf4_solibs} ${pf6_solibs}
60 @ENABLE_SHARED_TRUE@ targets_install += ${pfx_solibs} ${pf4_solibs} ${pf6_solibs}
61
62 .SECONDARY:
63
64 .PHONY: all install clean distclean FORCE
65
66 all: ${targets}
67
68 install: ${targets_install}
69         @mkdir -p "${DESTDIR}${xtlibdir}";
70         if test -n "${targets_install}"; then install -pm0755 $^ "${DESTDIR}${xtlibdir}/"; fi;
71
72 clean:
73         rm -f *.o *.oo *.so *.a {matches,targets}[46].man initext4.c initext6.c;
74
75 distclean: clean
76         rm -f .*.d .*.dd;
77
78 init%.o: ${srcdir}/init%.c
79         ${AM_VERBOSE_CC} ${CC} ${AM_DEPFLAGS} ${AM_CFLAGS} -D_INIT=$*_init ${CFLAGS} -o $@ -c $<;
80
81 -include .*.d
82
83
84 #
85 #       Shared libraries
86 #
87 lib%.so: lib%.oo
88         ${AM_VERBOSE_CCLD} ${CCLD} ${AM_LDFLAGS} -shared ${LDFLAGS} -o $@ $<;
89
90 lib%.oo: ${srcdir}/lib%.c
91         ${AM_VERBOSE_CC} ${CC} ${AM_DEPFLAGS} ${AM_CFLAGS} -D_INIT=lib$*_init -DPIC -fPIC ${CFLAGS} -o $@ -c $<;
92
93
94 #
95 #       Static bits
96 #
97 #       If static building is disabled, libext*.a will still be generated,
98 #       but will be empty. This is good since we can do with less case
99 #       handling code in the Makefiles.
100 #
101 lib%.o: ${srcdir}/lib%.c
102         ${AM_VERBOSE_CC} ${CC} ${AM_DEPFLAGS} ${AM_CFLAGS} -DNO_SHARED_LIBS=1 -D_INIT=lib$*_init ${CFLAGS} -o $@ -c $<;
103
104 libext4.a: initext4.o ${libext4_objs}
105         ${AM_VERBOSE_AR} ${AR} crs $@ $^;
106
107 libext6.a: initext6.o ${libext6_objs}
108         ${AM_VERBOSE_AR} ${AR} crs $@ $^;
109
110 initext_func  := $(addprefix xt_,${pfx_build_mod}) $(addprefix ipt_,${pf4_build_mod})
111 initext6_func := $(addprefix xt_,${pfx_build_mod}) $(addprefix ip6t_,${pf6_build_mod})
112
113 .initext4.dd: FORCE
114         @echo "${initext_func}" >$@.tmp; \
115         cmp -s $@ $@.tmp || mv $@.tmp $@; \
116         rm -f $@.tmp;
117
118 .initext6.dd: FORCE
119         @echo "${initext6_func}" >$@.tmp; \
120         cmp -s $@ $@.tmp || mv $@.tmp $@; \
121         rm -f $@.tmp;
122
123 initext4.c: .initext4.dd
124         ${AM_VERBOSE_GEN}
125         @( \
126         echo "" >$@; \
127         for i in ${initext_func}; do \
128                 echo "extern void lib$${i}_init(void);" >>$@; \
129         done; \
130         echo "void init_extensions(void);" >>$@; \
131         echo "void init_extensions(void)" >>$@; \
132         echo "{" >>$@; \
133         for i in ${initext_func}; do \
134                 echo  " ""lib$${i}_init();" >>$@; \
135         done; \
136         echo "}" >>$@; \
137         );
138
139 initext6.c: .initext6.dd
140         ${AM_VERBOSE_GEN}
141         @( \
142         echo "" >$@; \
143         for i in ${initext6_func}; do \
144                 echo "extern void lib$${i}_init(void);" >>$@; \
145         done; \
146         echo "void init_extensions(void);" >>$@; \
147         echo "void init_extensions(void)" >>$@; \
148         echo "{" >>$@; \
149         for i in ${initext6_func}; do \
150                 echo " ""lib$${i}_init();" >>$@; \
151         done; \
152         echo "}" >>$@; \
153         );
154
155 #
156 #       Manual pages
157 #
158 ex_matches = $(sort $(shell echo $(1) | grep -Eo '\b[a-z0-9]+\b'))
159 ex_targets = $(sort $(shell echo $(1) | grep -Eo '\b[A-Z0-9]+\b'))
160 man_run    = \
161         ${AM_VERBOSE_GEN} \
162         for ext in $(1); do \
163                 f="${srcdir}/libxt_$$ext.man"; \
164                 if [ -f "$$f" ]; then \
165                         echo ".SS $$ext"; \
166                         cat "$$f"; \
167                         continue; \
168                 fi; \
169                 f="${srcdir}/libipt_$$ext.man"; \
170                 if [ -f "$$f" ]; then \
171                         echo ".SS $$ext"; \
172                         cat "$$f"; \
173                         continue; \
174                 fi; \
175                 f="${srcdir}/libip6t_$$ext.man"; \
176                 if [ -f "$$f" ]; then \
177                         echo ".SS $$ext"; \
178                         cat "$$f"; \
179                         continue; \
180                 fi; \
181         done >$@;
182
183 matches4.man: .initext4.dd $(wildcard ${srcdir}/lib*.man)
184         $(call man_run,$(call ex_matches,${pfx_build_mod} ${pf4_build_mod}))
185
186 matches6.man: .initext6.dd $(wildcard ${srcdir}/lib*.man)
187         $(call man_run,$(call ex_matches,${pfx_build_mod} ${pf6_build_mod}))
188
189 targets4.man: .initext4.dd $(wildcard ${srcdir}/lib*.man)
190         $(call man_run,$(call ex_targets,${pfx_build_mod} ${pf4_build_mod}))
191
192 targets6.man: .initext6.dd $(wildcard ${srcdir}/lib*.man)
193         $(call man_run,$(call ex_targets,${pfx_build_mod} ${pf6_build_mod}))