blob: 841d486ddbb50f1a3c2f725cffb4ab3843fdcdf7 [file] [log] [blame]
Harald Welte3efb6ea2001-08-06 18:50:21 +00001# uncomment this to get a fully statically linked version
2# NO_SHARED_LIBS = 1
3
Harald Welte2354d922003-03-04 23:15:42 +00004# uncomment this to disable IPv6 support
5# DO_IPV6 = 0
6
Harald Welte3a5026f2001-09-02 16:07:33 +00007######################################################################
8# YOU SHOULD NOT NEED TO TOUCH ANYTHING BELOW THIS LINE
9######################################################################
10
11# Standard part of Makefile for topdir.
12TOPLEVEL_INCLUDED=YES
13
Sven Wegener561e90e2007-07-15 17:13:24 +000014# For recent kernels we only need the source in KERNEL_DIR to build. Older
15# kernels have a bug, where linux/netfilter_ipv4.h includes linux/config.h,
16# which includes linux/autoconf.h, which is placed into KBUILD_OUTPUT.
Marc Bouchere6869a82000-03-20 06:03:29 +000017ifndef KERNEL_DIR
Sven Wegener561e90e2007-07-15 17:13:24 +000018KERNEL_DIR="/lib/modules/$(shell uname -r)/source"
19endif
20ifndef KBUILD_OUTPUT
21KBUILD_OUTPUT="/lib/modules/$(shell uname -r)/build"
Marc Bouchere6869a82000-03-20 06:03:29 +000022endif
Pablo Neira Ayuso556c3d92007-06-25 12:01:12 +000023IPTABLES_VERSION:=1.3.8
24OLD_IPTABLES_VERSION:=1.3.7
Marc Bouchere6869a82000-03-20 06:03:29 +000025
Pablo Neira AyusoMaurice van der Pot44fc5e12007-04-16 17:15:22 +000026PREFIX:=/usr/local
Harald Welteba6d0122002-02-17 19:49:26 +000027LIBDIR:=$(PREFIX)/lib
28BINDIR:=$(PREFIX)/sbin
29MANDIR:=$(PREFIX)/man
30INCDIR:=$(PREFIX)/include
Marc Bouchere6869a82000-03-20 06:03:29 +000031
Harald Welte3a5026f2001-09-02 16:07:33 +000032# directory for new iptables releases
33RELEASE_DIR:=/tmp
34
Rusty Russell209820b2001-01-08 08:14:33 +000035# Need libc6 for this. FIXME: Should covert to autoconf.
Rusty Russell4d2afbf2001-05-01 02:06:08 +000036ifeq ($(shell [ -f /usr/include/netinet/ip6.h ] && echo YES), YES)
Harald Welte2354d922003-03-04 23:15:42 +000037DO_IPV6:=1
Rusty Russell8e07bd72000-12-19 03:11:00 +000038endif
39
James Morrisc81a3f32006-05-24 16:11:58 +000040# Enable linking to libselinux via enviornment 'DO_SELINUX=1'
41ifndef DO_SELINUX
42DO_SELINUX=0
43endif
44
Harald Welte380ba5f2002-02-13 16:19:55 +000045COPT_FLAGS:=-O2
Sven Wegener561e90e2007-07-15 17:13:24 +000046CFLAGS:=$(COPT_FLAGS) -Wall -Wunused -I$(KBUILD_OUTPUT)/include -I$(KERNEL_DIR)/include -Iinclude/ -DIPTABLES_VERSION=\"$(IPTABLES_VERSION)\" #-g -DDEBUG #-pg # -DIPTC_DEBUG
Marc Bouchere6869a82000-03-20 06:03:29 +000047
Harald Welte3efb6ea2001-08-06 18:50:21 +000048ifdef NO_SHARED_LIBS
49CFLAGS += -DNO_SHARED_LIBS=1
50endif
51
Henrik Nordstromc2794132004-01-22 15:04:24 +000052EXTRAS+=iptables iptables.o iptables.8
Rusty Russell01c45202001-01-07 06:50:31 +000053EXTRA_INSTALLS+=$(DESTDIR)$(BINDIR)/iptables $(DESTDIR)$(MANDIR)/man8/iptables.8
54
Harald Welteeba774d2001-10-16 08:22:40 +000055# No longer experimental.
Bastiaan Bakker4e3771f2004-06-25 11:18:57 +000056ifneq ($(DO_MULTI), 1)
Amin Azez8d3eccb2006-11-13 20:23:36 +000057EXTRAS+=iptables-save iptables-restore iptables-xml
Bastiaan Bakker4e3771f2004-06-25 11:18:57 +000058endif
Amin Azez8d3eccb2006-11-13 20:23:36 +000059EXTRA_INSTALLS+=$(DESTDIR)$(BINDIR)/iptables-save $(DESTDIR)$(BINDIR)/iptables-restore $(DESTDIR)$(BINDIR)/iptables-xml $(DESTDIR)$(MANDIR)/man8/iptables-restore.8 $(DESTDIR)$(MANDIR)/man8/iptables-save.8
Rusty Russell8e07bd72000-12-19 03:11:00 +000060
Harald Welte2354d922003-03-04 23:15:42 +000061ifeq ($(DO_IPV6), 1)
Henrik Nordstromc2794132004-01-22 15:04:24 +000062EXTRAS+=ip6tables ip6tables.o ip6tables.8
András Kis-Szabó06129432001-10-14 13:27:03 +000063EXTRA_INSTALLS+=$(DESTDIR)$(BINDIR)/ip6tables $(DESTDIR)$(MANDIR)/man8/ip6tables.8
Harald Welte8a6831a2001-03-15 15:33:56 +000064EXTRAS_EXP+=ip6tables-save ip6tables-restore
Harald Welte46d4d0a2001-03-16 15:48:56 +000065EXTRA_INSTALLS_EXP+=$(DESTDIR)$(BINDIR)/ip6tables-save $(DESTDIR)$(BINDIR)/ip6tables-restore # $(DESTDIR)$(MANDIR)/man8/iptables-restore.8 $(DESTDIR)$(MANDIR)/man8/iptables-save.8 $(DESTDIR)$(MANDIR)/man8/ip6tables-save.8 $(DESTDIR)$(MANDIR)/man8/ip6tables-restore.8
Rusty Russell8e07bd72000-12-19 03:11:00 +000066endif
Marc Bouchere6869a82000-03-20 06:03:29 +000067
68ifndef IPT_LIBDIR
69IPT_LIBDIR:=$(LIBDIR)/iptables
70endif
Yasuyuki KOZAKAIdbda07b2007-07-24 06:08:05 +000071DEST_IPT_LIBDIR:=$(DESTDIR)$(LIBDIR)/iptables
Marc Bouchere6869a82000-03-20 06:03:29 +000072
Martin Josefssondc93fce2004-05-26 15:46:27 +000073ifndef NO_SHARED_LIBS
74DEPFILES = $(SHARED_LIBS:%.so=%.d)
James Morrisc81a3f32006-05-24 16:11:58 +000075DEPFILES += $(SHARED_SE_LIBS:%.so=%.d)
Martin Josefssondc93fce2004-05-26 15:46:27 +000076SH_CFLAGS:=$(CFLAGS) -fPIC
77STATIC_LIBS =
78STATIC6_LIBS =
79LDFLAGS = -rdynamic
Patrick McHardy51d84a12007-04-18 12:41:09 +000080LDLIBS = -ldl
James Morrisc81a3f32006-05-24 16:11:58 +000081ifeq ($(DO_SELINUX), 1)
82LDLIBS += -lselinux
83endif
Martin Josefssondc93fce2004-05-26 15:46:27 +000084else
85DEPFILES = $(EXT_OBJS:%.o=%.d)
86STATIC_LIBS = extensions/libext.a
87STATIC6_LIBS = extensions/libext6.a
88LDFLAGS = -static
James Morrisc81a3f32006-05-24 16:11:58 +000089LDLIBS =
90ifeq ($(DO_SELINUX), 1)
91LDLIBS += -lselinux
92endif
Martin Josefssondc93fce2004-05-26 15:46:27 +000093endif
94
Harald Welte7505d612001-07-31 13:06:17 +000095.PHONY: default
Rusty Russell52451822000-08-27 07:47:46 +000096default: print-extensions all
97
Harald Welte7505d612001-07-31 13:06:17 +000098.PHONY: print-extensions
Rusty Russell52451822000-08-27 07:47:46 +000099print-extensions:
Rusty Russellc8d7d892000-09-19 07:01:00 +0000100 @[ -n "$(OPTIONALS)" ] && echo Extensions found: $(OPTIONALS)
Marc Bouchere6869a82000-03-20 06:03:29 +0000101
102iptables.o: iptables.c
103 $(CC) $(CFLAGS) -DIPT_LIB_DIR=\"$(IPT_LIBDIR)\" -c -o $@ $<
104
Bastiaan Bakker4e3771f2004-06-25 11:18:57 +0000105ifeq ($(DO_MULTI), 1)
Yasuyuki KOZAKAI52088062007-07-24 05:44:11 +0000106iptables: iptables-multi.c iptables-save.c iptables-restore.c iptables-xml.c iptables-standalone.c iptables.o xtables.o $(STATIC_LIBS) libiptc/libiptc.a
Bastiaan Bakker4e3771f2004-06-25 11:18:57 +0000107 $(CC) $(CFLAGS) -DIPTABLES_MULTI -DIPT_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
108else
Yasuyuki KOZAKAI52088062007-07-24 05:44:11 +0000109iptables: iptables-standalone.c iptables.o xtables.o $(STATIC_LIBS) libiptc/libiptc.a
Harald Welte3efb6ea2001-08-06 18:50:21 +0000110 $(CC) $(CFLAGS) -DIPT_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
Bastiaan Bakker4e3771f2004-06-25 11:18:57 +0000111endif
Marc Bouchere6869a82000-03-20 06:03:29 +0000112
113$(DESTDIR)$(BINDIR)/iptables: iptables
114 @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
115 cp $< $@
116
Yasuyuki KOZAKAI52088062007-07-24 05:44:11 +0000117iptables-save: iptables-save.c iptables.o xtables.o $(STATIC_LIBS) libiptc/libiptc.a
Harald Welte3efb6ea2001-08-06 18:50:21 +0000118 $(CC) $(CFLAGS) -DIPT_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
Marc Bouchere6869a82000-03-20 06:03:29 +0000119
Bastiaan Bakker4e3771f2004-06-25 11:18:57 +0000120ifeq ($(DO_MULTI), 1)
121$(DESTDIR)$(BINDIR)/iptables-save: iptables
122 @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
123 ln -sf $< $@
124else
Marc Bouchere6869a82000-03-20 06:03:29 +0000125$(DESTDIR)$(BINDIR)/iptables-save: iptables-save
126 @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
127 cp $< $@
Bastiaan Bakker4e3771f2004-06-25 11:18:57 +0000128endif
Marc Bouchere6869a82000-03-20 06:03:29 +0000129
Yasuyuki KOZAKAI52088062007-07-24 05:44:11 +0000130iptables-restore: iptables-restore.c iptables.o xtables.o $(STATIC_LIBS) libiptc/libiptc.a
Harald Welte3efb6ea2001-08-06 18:50:21 +0000131 $(CC) $(CFLAGS) -DIPT_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
Marc Bouchere6869a82000-03-20 06:03:29 +0000132
Bastiaan Bakker4e3771f2004-06-25 11:18:57 +0000133ifeq ($(DO_MULTI), 1)
134$(DESTDIR)$(BINDIR)/iptables-restore: iptables
135 @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
136 ln -sf $< $@
137else
Marc Bouchere6869a82000-03-20 06:03:29 +0000138$(DESTDIR)$(BINDIR)/iptables-restore: iptables-restore
139 @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
140 cp $< $@
Bastiaan Bakker4e3771f2004-06-25 11:18:57 +0000141endif
Marc Bouchere6869a82000-03-20 06:03:29 +0000142
Amin Azez8d3eccb2006-11-13 20:23:36 +0000143iptables-xml: iptables-xml.c #iptables.o # $(STATIC_LIBS) libiptc/libiptc.a
144 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
145
146ifeq ($(DO_MULTI), 1)
Lutz Jaenickee78c69c2006-12-09 13:06:04 +0000147$(DESTDIR)$(BINDIR)/iptables-xml: iptables
Amin Azez8d3eccb2006-11-13 20:23:36 +0000148 @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
149 ln -sf $< $@
150else
151$(DESTDIR)$(BINDIR)/iptables-xml: iptables-xml
152 @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
153 cp $< $@
154endif
155
Philip Blundell8c700902000-05-15 02:17:52 +0000156ip6tables.o: ip6tables.c
Harald Welte0aefbd32001-05-11 21:41:47 +0000157 $(CC) $(CFLAGS) -DIP6T_LIB_DIR=\"$(IPT_LIBDIR)\" -c -o $@ $<
Philip Blundell8c700902000-05-15 02:17:52 +0000158
Yasuyuki KOZAKAI52088062007-07-24 05:44:11 +0000159ip6tables: ip6tables-standalone.c ip6tables.o xtables.o $(STATIC6_LIBS) libiptc/libiptc.a
Harald Welte2a7116e2002-08-26 13:09:40 +0000160 $(CC) $(CFLAGS) -DIP6T_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
Philip Blundell8c700902000-05-15 02:17:52 +0000161
162$(DESTDIR)$(BINDIR)/ip6tables: ip6tables
163 @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
164 cp $< $@
165
Yasuyuki KOZAKAI52088062007-07-24 05:44:11 +0000166ip6tables-save: ip6tables-save.c ip6tables.o xtables.o $(STATIC6_LIBS) libiptc/libiptc.a
Harald Welte2a7116e2002-08-26 13:09:40 +0000167 $(CC) $(CFLAGS) -DIP6T_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
Philip Blundell8c700902000-05-15 02:17:52 +0000168
169$(DESTDIR)$(BINDIR)/ip6tables-save: ip6tables-save
170 @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
171 cp $< $@
172
Yasuyuki KOZAKAI52088062007-07-24 05:44:11 +0000173ip6tables-restore: ip6tables-restore.c ip6tables.o xtables.o $(STATIC6_LIBS) libiptc/libiptc.a
Harald Welte2a7116e2002-08-26 13:09:40 +0000174 $(CC) $(CFLAGS) -DIP6T_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
Philip Blundell8c700902000-05-15 02:17:52 +0000175
176$(DESTDIR)$(BINDIR)/ip6tables-restore: ip6tables-restore
177 @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
178 cp $< $@
179
Rusty Russell01c45202001-01-07 06:50:31 +0000180$(DESTDIR)$(MANDIR)/man8/%.8: %.8
Marc Bouchere6869a82000-03-20 06:03:29 +0000181 @[ -d $(DESTDIR)$(MANDIR)/man8 ] || mkdir -p $(DESTDIR)$(MANDIR)/man8
182 cp $< $@
183
184EXTRA_DEPENDS+=iptables-standalone.d iptables.d
185
186iptables-standalone.d iptables.d: %.d: %.c
187 @-$(CC) -M -MG $(CFLAGS) $< | sed -e 's@^.*\.o:@$*.d $*.o:@' > $@
188
Henrik Nordstromc2794132004-01-22 15:04:24 +0000189iptables.8: iptables.8.in extensions/libipt_matches.man extensions/libipt_targets.man
190 sed -e '/@MATCH@/ r extensions/libipt_matches.man' -e '/@TARGET@/ r extensions/libipt_targets.man' iptables.8.in >iptables.8
191
192ip6tables.8: ip6tables.8.in extensions/libip6t_matches.man extensions/libip6t_targets.man
Phil Oesterde8ae512004-09-09 09:57:11 +0000193 sed -e '/@MATCH@/ r extensions/libip6t_matches.man' -e '/@TARGET@/ r extensions/libip6t_targets.man' ip6tables.8.in >ip6tables.8
James Morrisc82e9ac2000-11-24 14:34:02 +0000194
195# Development Targets
Harald Welte7505d612001-07-31 13:06:17 +0000196.PHONY: install-devel-man3
James Morrisc82e9ac2000-11-24 14:34:02 +0000197install-devel-man3: $(DEVEL_MAN3)
198 @[ -d $(DESTDIR)$(MANDIR)/man3 ] || mkdir -p $(DESTDIR)$(MANDIR)/man3
199 @cp -v $(DEVEL_MAN3) $(DESTDIR)$(MANDIR)/man3
200
Harald Welte7505d612001-07-31 13:06:17 +0000201.PHONY: install-devel-headers
James Morrisc82e9ac2000-11-24 14:34:02 +0000202install-devel-headers: $(DEVEL_HEADERS)
203 @[ -d $(DESTDIR)$(INCDIR) ] || mkdir -p $(DESTDIR)$(INCDIR)
204 @cp -v $(DEVEL_HEADERS) $(DESTDIR)$(INCDIR)
205
Harald Welte7505d612001-07-31 13:06:17 +0000206.PHONY: install-devel-libs
James Morrisc82e9ac2000-11-24 14:34:02 +0000207install-devel-libs: $(DEVEL_LIBS)
208 @[ -d $(DESTDIR)$(LIBDIR) ] || mkdir -p $(DESTDIR)$(LIBDIR)
209 @cp -v $(DEVEL_LIBS) $(DESTDIR)$(LIBDIR)
210
Harald Welte7505d612001-07-31 13:06:17 +0000211.PHONY: install-devel
James Morrisc82e9ac2000-11-24 14:34:02 +0000212install-devel: all install-devel-man3 install-devel-headers install-devel-libs
213
Harald Welte7505d612001-07-31 13:06:17 +0000214.PHONY: distclean
Rusty Russell905795c2000-04-19 11:22:03 +0000215distclean: clean
Rusty Russella470f332000-11-07 04:08:34 +0000216 @rm -f TAGS `find . -name '*~' -o -name '.*~'` `find . -name '*.rej'` `find . -name '*.d'` .makefirst
Rusty Russell175f6412000-03-24 09:32:20 +0000217
218# Rusty's distro magic.
Harald Welte7505d612001-07-31 13:06:17 +0000219.PHONY: distrib
Harald Welte80fe35d2002-05-29 13:08:15 +0000220distrib: check distclean delrelease $(RELEASE_DIR)/iptables-$(IPTABLES_VERSION).tar.bz2 diff md5sums # nowhitespace
Rusty Russell175f6412000-03-24 09:32:20 +0000221
222# Makefile must not define:
Harald Welte380ba5f2002-02-13 16:19:55 +0000223# -g -pg -DIPTC_DEBUG
Harald Welte7505d612001-07-31 13:06:17 +0000224.PHONY: check
Rusty Russell175f6412000-03-24 09:32:20 +0000225check:
Patrick McHardy83321c02007-01-10 13:56:05 +0000226 @if echo $(CFLAGS) | egrep -e '(^|[[:space:]])(-g|-pg|-DIPTC_DEBUG)([[:space:]]|$)' >/dev/null; then echo Remove debugging flags; exit 1; else exit 0; fi
Rusty Russell175f6412000-03-24 09:32:20 +0000227
Harald Welte7505d612001-07-31 13:06:17 +0000228.PHONY: nowhitespace
Rusty Russell175f6412000-03-24 09:32:20 +0000229nowhitespace:
Rusty Russell2e5f9532001-01-07 09:37:02 +0000230 @if grep -n '[ ]$$' `find . -name 'Makefile' -o -name '*.[ch]'`; then exit 1; else exit 0; fi
Rusty Russell175f6412000-03-24 09:32:20 +0000231
Harald Welte7505d612001-07-31 13:06:17 +0000232.PHONY: delrelease
Rusty Russell175f6412000-03-24 09:32:20 +0000233delrelease:
Harald Welte80fe35d2002-05-29 13:08:15 +0000234 rm -f $(RELEASE_DIR)/iptables-$(IPTABLES_VERSION).tar.bz2
Rusty Russell175f6412000-03-24 09:32:20 +0000235
Harald Welte80fe35d2002-05-29 13:08:15 +0000236$(RELEASE_DIR)/iptables-$(IPTABLES_VERSION).tar.bz2:
Harald Welte59746832005-02-01 16:47:35 +0000237 cd .. && ln -sf iptables iptables-$(IPTABLES_VERSION) && tar cvf - --exclude .svn iptables-$(IPTABLES_VERSION)/. | bzip2 -9 > $@ && rm iptables-$(IPTABLES_VERSION)
Rusty Russell175f6412000-03-24 09:32:20 +0000238
Harald Welte7505d612001-07-31 13:06:17 +0000239.PHONY: diff
Harald Welte80fe35d2002-05-29 13:08:15 +0000240diff: $(RELEASE_DIR)/iptables-$(IPTABLES_VERSION).tar.bz2
Rusty Russell175f6412000-03-24 09:32:20 +0000241 @mkdir /tmp/diffdir
Harald Welte80fe35d2002-05-29 13:08:15 +0000242 @cd /tmp/diffdir && tar -x --bzip2 -f $(RELEASE_DIR)/iptables-$(IPTABLES_VERSION).tar.bz2
243 @set -e; cd /tmp/diffdir; tar -x --bzip2 -f $(RELEASE_DIR)/iptables-$(OLD_IPTABLES_VERSION).tar.bz2; echo Creating patch-iptables-$(OLD_IPTABLES_VERSION)-$(IPTABLES_VERSION).bz2; diff -urN iptables-$(OLD_IPTABLES_VERSION) iptables-$(IPTABLES_VERSION) | bzip2 -9 > $(RELEASE_DIR)/patch-iptables-$(OLD_IPTABLES_VERSION)-$(IPTABLES_VERSION).bz2
Rusty Russell175f6412000-03-24 09:32:20 +0000244 @rm -rf /tmp/diffdir
245
Harald Welte7505d612001-07-31 13:06:17 +0000246.PHONY: md5sums
Rusty Russell175f6412000-03-24 09:32:20 +0000247md5sums:
Harald Welte80fe35d2002-05-29 13:08:15 +0000248 cd $(RELEASE_DIR)/ && md5sum patch-iptables-*-$(IPTABLES_VERSION).bz2 iptables-$(IPTABLES_VERSION).tar.bz2
Rusty Russell175f6412000-03-24 09:32:20 +0000249
Marc Bouchere6869a82000-03-20 06:03:29 +0000250# $(wildcard) fails wierdly with make v.3.78.1.
251include $(shell echo */Makefile)
252include Rules.make