Move common parts of libext{4,6}.a into libext.a

Signed-off-by: Maciej Zenczykowski <maze@google.com>
diff --git a/.gitignore b/.gitignore
index e5d3099..9b59e6a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,6 +13,7 @@
 Makefile.in
 
 /extensions/GNUmakefile
+/extensions/initext.c
 /extensions/initext?.c
 /extensions/matches?.man
 /extensions/targets?.man
diff --git a/Makefile.am b/Makefile.am
index fbed41f..6affcac 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -45,7 +45,9 @@
 iptables_multi_CFLAGS    += -DALL_INCLUSIVE
 endif
 iptables_multi_LDFLAGS    = -rdynamic
-iptables_multi_LDADD      = libiptc/libip4tc.la extensions/libext4.a libxtables.la -lm
+iptables_multi_LDADD      = libiptc/libip4tc.la \
+                            extensions/libext.a extensions/libext4.a \
+                            libxtables.la -lm
 
 ip6tables_multi_SOURCES   = ip6tables-multi.c ip6tables-save.c \
                             ip6tables-restore.c ip6tables-standalone.c \
@@ -55,7 +57,9 @@
 ip6tables_multi_CFLAGS   += -DALL_INCLUSIVE
 endif
 ip6tables_multi_LDFLAGS   = -rdynamic
-ip6tables_multi_LDADD     = libiptc/libip6tc.la extensions/libext6.a libxtables.la -lm
+ip6tables_multi_LDADD     = libiptc/libip6tc.la \
+                            extensions/libext.a extensions/libext6.a \
+                            libxtables.la -lm
 
 sbin_PROGRAMS    =
 man_MANS         = iptables.8 iptables-restore.8 iptables-save.8 \
diff --git a/extensions/GNUmakefile.in b/extensions/GNUmakefile.in
index 0e562fb..a511a39 100644
--- a/extensions/GNUmakefile.in
+++ b/extensions/GNUmakefile.in
@@ -51,11 +51,13 @@
 #
 # Building blocks
 #
-targets := libext4.a libext6.a matches4.man matches6.man \
+targets := libext.a libext4.a libext6.a \
+           matches4.man matches6.man \
            targets4.man targets6.man
 targets_install :=
-@ENABLE_STATIC_TRUE@ libext4_objs := ${pfx_objs} ${pf4_objs}
-@ENABLE_STATIC_TRUE@ libext6_objs := ${pfx_objs} ${pf6_objs}
+@ENABLE_STATIC_TRUE@ libext_objs := ${pfx_objs}
+@ENABLE_STATIC_TRUE@ libext4_objs := ${pf4_objs}
+@ENABLE_STATIC_TRUE@ libext6_objs := ${pf6_objs}
 @ENABLE_STATIC_FALSE@ targets += ${pfx_solibs} ${pf4_solibs} ${pf6_solibs}
 @ENABLE_STATIC_FALSE@ targets_install += ${pfx_solibs} ${pf4_solibs} ${pf6_solibs}
 
@@ -70,7 +72,7 @@
 	if test -n "${targets_install}"; then install -pm0755 $^ "${DESTDIR}${xtlibdir}/"; fi;
 
 clean:
-	rm -f *.o *.oo *.so *.a {matches,targets}[46].man initext4.c initext6.c;
+	rm -f *.o *.oo *.so *.a {matches,targets}[46].man initext.c initext4.c initext6.c;
 
 distclean: clean
 	rm -f .*.d .*.dd;
@@ -101,17 +103,26 @@
 lib%.o: ${srcdir}/lib%.c
 	${AM_VERBOSE_CC} ${CC} ${AM_DEPFLAGS} ${AM_CFLAGS} -DNO_SHARED_LIBS=1 -D_INIT=lib$*_init ${CFLAGS} -o $@ -c $<;
 
+libext.a: initext.o ${libext_objs}
+	${AM_VERBOSE_AR} ${AR} crs $@ $^;
+
 libext4.a: initext4.o ${libext4_objs}
 	${AM_VERBOSE_AR} ${AR} crs $@ $^;
 
 libext6.a: initext6.o ${libext6_objs}
 	${AM_VERBOSE_AR} ${AR} crs $@ $^;
 
-initext_func  := $(addprefix xt_,${pfx_build_mod}) $(addprefix ipt_,${pf4_build_mod})
-initext6_func := $(addprefix xt_,${pfx_build_mod}) $(addprefix ip6t_,${pf6_build_mod})
+initext_func  := $(addprefix xt_,${pfx_build_mod})
+initext4_func := $(addprefix ipt_,${pf4_build_mod})
+initext6_func := $(addprefix ip6t_,${pf6_build_mod})
+
+.initext.dd: FORCE
+	@echo "${initext_func}" >$@.tmp; \
+	cmp -s $@ $@.tmp || mv $@.tmp $@; \
+	rm -f $@.tmp;
 
 .initext4.dd: FORCE
-	@echo "${initext_func}" >$@.tmp; \
+	@echo "${initext4_func}" >$@.tmp; \
 	cmp -s $@ $@.tmp || mv $@.tmp $@; \
 	rm -f $@.tmp;
 
@@ -120,17 +131,33 @@
 	cmp -s $@ $@.tmp || mv $@.tmp $@; \
 	rm -f $@.tmp;
 
-initext4.c: .initext4.dd
+initext.c: .initext.dd
 	${AM_VERBOSE_GEN}
 	@( \
 	echo "" >$@; \
 	for i in ${initext_func}; do \
 		echo "extern void lib$${i}_init(void);" >>$@; \
 	done; \
+	echo "void init_extensions(void);" >>$@; \
+	echo "void init_extensions(void)" >>$@; \
+	echo "{" >>$@; \
+	for i in ${initext_func}; do \
+		echo  " ""lib$${i}_init();" >>$@; \
+	done; \
+	echo "}" >>$@; \
+	);
+
+initext4.c: .initext4.dd
+	${AM_VERBOSE_GEN}
+	@( \
+	echo "" >$@; \
+	for i in ${initext4_func}; do \
+		echo "extern void lib$${i}_init(void);" >>$@; \
+	done; \
 	echo "void init_extensions4(void);" >>$@; \
 	echo "void init_extensions4(void)" >>$@; \
 	echo "{" >>$@; \
-	for i in ${initext_func}; do \
+	for i in ${initext4_func}; do \
 		echo  " ""lib$${i}_init();" >>$@; \
 	done; \
 	echo "}" >>$@; \
@@ -177,14 +204,14 @@
 		fi; \
 	done >$@;
 
-matches4.man: .initext4.dd $(wildcard ${srcdir}/lib*.man)
+matches4.man: .initext.dd .initext4.dd $(wildcard ${srcdir}/lib*.man)
 	$(call man_run,$(call ex_matches,${pfx_build_mod} ${pf4_build_mod}),ip,NFPROTO_IPV4)
 
-matches6.man: .initext6.dd $(wildcard ${srcdir}/lib*.man)
+matches6.man: .initext.dd .initext6.dd $(wildcard ${srcdir}/lib*.man)
 	$(call man_run,$(call ex_matches,${pfx_build_mod} ${pf6_build_mod}),ip6,NFPROTO_IPV6)
 
-targets4.man: .initext4.dd $(wildcard ${srcdir}/lib*.man)
+targets4.man: .initext.dd .initext4.dd $(wildcard ${srcdir}/lib*.man)
 	$(call man_run,$(call ex_targets,${pfx_build_mod} ${pf4_build_mod}),ip,NFPROTO_IPV4)
 
-targets6.man: .initext6.dd $(wildcard ${srcdir}/lib*.man)
+targets6.man: .initext.dd .initext6.dd $(wildcard ${srcdir}/lib*.man)
 	$(call man_run,$(call ex_targets,${pfx_build_mod} ${pf6_build_mod}),ip6,NFPROTO_IPV6)
diff --git a/include/xtables.h.in b/include/xtables.h.in
index b080285..1d91d4d 100644
--- a/include/xtables.h.in
+++ b/include/xtables.h.in
@@ -422,6 +422,7 @@
 #		undef _init
 #		define _init _INIT
 #	endif
+	extern void init_extensions(void);
 	extern void init_extensions4(void);
 	extern void init_extensions6(void);
 #else
diff --git a/ip6tables-restore.c b/ip6tables-restore.c
index 5531d6e..420bc52 100644
--- a/ip6tables-restore.c
+++ b/ip6tables-restore.c
@@ -137,6 +137,7 @@
 		exit(1);
 	}
 #if defined(ALL_INCLUSIVE) || defined(NO_SHARED_LIBS)
+	init_extensions();
 	init_extensions6();
 #endif
 
diff --git a/ip6tables-save.c b/ip6tables-save.c
index d9ecc62..39a3325 100644
--- a/ip6tables-save.c
+++ b/ip6tables-save.c
@@ -149,6 +149,7 @@
 		exit(1);
 	}
 #if defined(ALL_INCLUSIVE) || defined(NO_SHARED_LIBS)
+	init_extensions();
 	init_extensions6();
 #endif
 
diff --git a/ip6tables-standalone.c b/ip6tables-standalone.c
index 7d34684..9d8d5a0 100644
--- a/ip6tables-standalone.c
+++ b/ip6tables-standalone.c
@@ -59,6 +59,7 @@
 	}
 
 #if defined(ALL_INCLUSIVE) || defined(NO_SHARED_LIBS)
+	init_extensions();
 	init_extensions6();
 #endif
 
diff --git a/iptables-restore.c b/iptables-restore.c
index e4f0604..2624599 100644
--- a/iptables-restore.c
+++ b/iptables-restore.c
@@ -140,6 +140,7 @@
 		exit(1);
 	}
 #if defined(ALL_INCLUSIVE) || defined(NO_SHARED_LIBS)
+	init_extensions();
 	init_extensions4();
 #endif
 
diff --git a/iptables-save.c b/iptables-save.c
index dee1752..7542bdc 100644
--- a/iptables-save.c
+++ b/iptables-save.c
@@ -149,6 +149,7 @@
 		exit(1);
 	}
 #if defined(ALL_INCLUSIVE) || defined(NO_SHARED_LIBS)
+	init_extensions();
 	init_extensions4();
 #endif
 
diff --git a/iptables-standalone.c b/iptables-standalone.c
index b085946..87f1d31 100644
--- a/iptables-standalone.c
+++ b/iptables-standalone.c
@@ -59,6 +59,7 @@
 				exit(1);
 	}
 #if defined(ALL_INCLUSIVE) || defined(NO_SHARED_LIBS)
+	init_extensions();
 	init_extensions4();
 #endif