blob: 1f063c8c7d092b4fbf28382e6f51fe2eeabaa16a [file] [log] [blame]
Jan Engelhardtf82070f2008-01-20 13:14:00 +00001# -*- Makefile -*-
2
Jan Engelhardtac21a5c2008-05-12 10:28:34 +02003top_builddir := @top_builddir@
4builddir := @builddir@
Jan Engelhardtf82070f2008-01-20 13:14:00 +00005top_srcdir := @top_srcdir@
6srcdir := @srcdir@
7ksourcedir := @ksourcedir@
8prefix := @prefix@
9exec_prefix := @exec_prefix@
10libdir := @libdir@
11libexecdir := @libexecdir@
Jan Engelhardt21b41ee2008-02-11 01:02:00 +010012xtlibdir := @xtlibdir@
Jan Engelhardtf82070f2008-01-20 13:14:00 +000013
14CC := @CC@
15CCLD := ${CC}
16CFLAGS := @CFLAGS@
17LDFLAGS := @LDFLAGS@
18regular_CFLAGS := @regular_CFLAGS@
Jan Engelhardtfb6209a2008-01-29 13:32:07 +000019kinclude_CFLAGS := @kinclude_CFLAGS@
Jan Engelhardtf82070f2008-01-20 13:14:00 +000020
Jan Engelhardtac21a5c2008-05-12 10:28:34 +020021AM_CFLAGS := ${regular_CFLAGS} -I${top_builddir}/include -I${top_srcdir}/include ${kinclude_CFLAGS}
Jan Engelhardtf82070f2008-01-20 13:14:00 +000022AM_DEPFLAGS = -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@
23
24ifeq (${V},)
25AM_LIBTOOL_SILENT = --silent
26AM_VERBOSE_CC = @echo " CC " $@;
27AM_VERBOSE_CCLD = @echo " CCLD " $@;
28AM_VERBOSE_CXX = @echo " CXX " $@;
29AM_VERBOSE_CXXLD = @echo " CXXLD " $@;
30AM_VERBOSE_AR = @echo " AR " $@;
31AM_VERBOSE_GEN = @echo " GEN " $@;
32endif
33
34#
35# Wildcard module list
36#
Jan Engelhardted342ed2008-02-13 21:35:59 +010037pfx_build_mod := $(patsubst ${srcdir}/libxt_%.c,%,$(wildcard ${srcdir}/libxt_*.c))
38pf4_build_mod := $(patsubst ${srcdir}/libipt_%.c,%,$(wildcard ${srcdir}/libipt_*.c))
39pf6_build_mod := $(patsubst ${srcdir}/libip6t_%.c,%,$(wildcard ${srcdir}/libip6t_*.c))
Jan Engelhardt2c570e72008-06-05 19:54:48 +020040pfx_build_mod := $(filter-out @blacklist_modules@,${pfx_build_mod})
41pf4_build_mod := $(filter-out @blacklist_modules@,${pf4_build_mod})
42pf6_build_mod := $(filter-out @blacklist_modules@,${pf6_build_mod})
Jan Engelhardtf82070f2008-01-20 13:14:00 +000043pfx_objs := $(patsubst %,libxt_%.o,${pfx_build_mod})
44pf4_objs := $(patsubst %,libipt_%.o,${pf4_build_mod})
45pf6_objs := $(patsubst %,libip6t_%.o,${pf6_build_mod})
46pfx_solibs := $(patsubst %,libxt_%.so,${pfx_build_mod})
47pf4_solibs := $(patsubst %,libipt_%.so,${pf4_build_mod})
48pf6_solibs := $(patsubst %,libip6t_%.so,${pf6_build_mod})
49
50
51#
52# Building blocks
53#
54targets := libext4.a libext6.a matches4.man matches6.man \
55 targets4.man targets6.man
56targets_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
66all: ${targets}
67
68install: ${targets_install}
Jan Engelhardt21b41ee2008-02-11 01:02:00 +010069 @mkdir -p "${DESTDIR}${xtlibdir}";
Jan Engelhardte1456212008-06-12 12:10:47 +020070 if test -n "${targets_install}"; then install -pm0755 $^ "${DESTDIR}${xtlibdir}/"; fi;
Jan Engelhardtf82070f2008-01-20 13:14:00 +000071
72clean:
73 rm -f *.o *.oo *.so *.a {matches,targets}[46].man initext4.c initext6.c;
74
75distclean: clean
Jan Engelhardtfb6209a2008-01-29 13:32:07 +000076 rm -f .*.d .*.dd;
Jan Engelhardtf82070f2008-01-20 13:14:00 +000077
Jan Engelhardt79638452008-08-13 14:43:56 +020078init%.o: init%.c
Jan Engelhardtf82070f2008-01-20 13:14:00 +000079 ${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#
87lib%.so: lib%.oo
88 ${AM_VERBOSE_CCLD} ${CCLD} ${AM_LDFLAGS} -shared ${LDFLAGS} -o $@ $<;
89
90lib%.oo: ${srcdir}/lib%.c
Jan Engelhardtc9246212008-02-11 00:29:36 +010091 ${AM_VERBOSE_CC} ${CC} ${AM_DEPFLAGS} ${AM_CFLAGS} -D_INIT=lib$*_init -DPIC -fPIC ${CFLAGS} -o $@ -c $<;
Jan Engelhardtf82070f2008-01-20 13:14:00 +000092
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#
101lib%.o: ${srcdir}/lib%.c
Jan Engelhardtc9246212008-02-11 00:29:36 +0100102 ${AM_VERBOSE_CC} ${CC} ${AM_DEPFLAGS} ${AM_CFLAGS} -DNO_SHARED_LIBS=1 -D_INIT=lib$*_init ${CFLAGS} -o $@ -c $<;
Jan Engelhardtf82070f2008-01-20 13:14:00 +0000103
104libext4.a: initext4.o ${libext4_objs}
105 ${AM_VERBOSE_AR} ${AR} crs $@ $^;
106
107libext6.a: initext6.o ${libext6_objs}
108 ${AM_VERBOSE_AR} ${AR} crs $@ $^;
109
110initext_func := $(addprefix xt_,${pfx_build_mod}) $(addprefix ipt_,${pf4_build_mod})
111initext6_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
123initext4.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; \
Thomas Jacobf858d372008-05-20 17:17:02 +0200130 echo "void init_extensions(void);" >>$@; \
131 echo "void init_extensions(void)" >>$@; \
132 echo "{" >>$@; \
Jan Engelhardtf82070f2008-01-20 13:14:00 +0000133 for i in ${initext_func}; do \
Thomas Jacobf858d372008-05-20 17:17:02 +0200134 echo " ""lib$${i}_init();" >>$@; \
Jan Engelhardtf82070f2008-01-20 13:14:00 +0000135 done; \
136 echo "}" >>$@; \
137 );
138
139initext6.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; \
Thomas Jacobf858d372008-05-20 17:17:02 +0200146 echo "void init_extensions(void);" >>$@; \
147 echo "void init_extensions(void)" >>$@; \
148 echo "{" >>$@; \
Jan Engelhardtf82070f2008-01-20 13:14:00 +0000149 for i in ${initext6_func}; do \
Thomas Jacobf858d372008-05-20 17:17:02 +0200150 echo " ""lib$${i}_init();" >>$@; \
Jan Engelhardtf82070f2008-01-20 13:14:00 +0000151 done; \
152 echo "}" >>$@; \
153 );
154
155#
156# Manual pages
157#
158ex_matches = $(sort $(shell echo $(1) | grep -Eo '\b[a-z0-9]+\b'))
159ex_targets = $(sort $(shell echo $(1) | grep -Eo '\b[A-Z0-9]+\b'))
160man_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
Jan Engelhardta99cb442008-01-29 13:33:23 +0000183matches4.man: .initext4.dd $(wildcard ${srcdir}/lib*.man)
Jan Engelhardtf82070f2008-01-20 13:14:00 +0000184 $(call man_run,$(call ex_matches,${pfx_build_mod} ${pf4_build_mod}))
185
Jan Engelhardta99cb442008-01-29 13:33:23 +0000186matches6.man: .initext6.dd $(wildcard ${srcdir}/lib*.man)
Jan Engelhardtf82070f2008-01-20 13:14:00 +0000187 $(call man_run,$(call ex_matches,${pfx_build_mod} ${pf6_build_mod}))
188
Jan Engelhardta99cb442008-01-29 13:33:23 +0000189targets4.man: .initext4.dd $(wildcard ${srcdir}/lib*.man)
Jan Engelhardtf82070f2008-01-20 13:14:00 +0000190 $(call man_run,$(call ex_targets,${pfx_build_mod} ${pf4_build_mod}))
191
Jan Engelhardta99cb442008-01-29 13:33:23 +0000192targets6.man: .initext6.dd $(wildcard ${srcdir}/lib*.man)
Jan Engelhardtf82070f2008-01-20 13:14:00 +0000193 $(call man_run,$(call ex_targets,${pfx_build_mod} ${pf6_build_mod}))