blob: 82e554674ab19167eb07f63d69e4f494d9eac838 [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
Marc Bouchere6869a82000-03-20 06:03:29 +000014ifndef KERNEL_DIR
15KERNEL_DIR=/usr/src/linux
16endif
Harald Weltef1528c82004-06-17 12:21:11 +000017IPTABLES_VERSION:=1.2.11
18OLD_IPTABLES_VERSION:=1.2.10
Marc Bouchere6869a82000-03-20 06:03:29 +000019
Harald Welteba6d0122002-02-17 19:49:26 +000020PREFIX:=/usr/local
21LIBDIR:=$(PREFIX)/lib
22BINDIR:=$(PREFIX)/sbin
23MANDIR:=$(PREFIX)/man
24INCDIR:=$(PREFIX)/include
Marc Bouchere6869a82000-03-20 06:03:29 +000025
Harald Welte3a5026f2001-09-02 16:07:33 +000026# directory for new iptables releases
27RELEASE_DIR:=/tmp
28
Rusty Russell209820b2001-01-08 08:14:33 +000029# Need libc6 for this. FIXME: Should covert to autoconf.
Rusty Russell4d2afbf2001-05-01 02:06:08 +000030ifeq ($(shell [ -f /usr/include/netinet/ip6.h ] && echo YES), YES)
Harald Welte2354d922003-03-04 23:15:42 +000031DO_IPV6:=1
Rusty Russell8e07bd72000-12-19 03:11:00 +000032endif
33
Harald Welte380ba5f2002-02-13 16:19:55 +000034COPT_FLAGS:=-O2
Harald Welte80fe35d2002-05-29 13:08:15 +000035CFLAGS:=$(COPT_FLAGS) -Wall -Wunused -I$(KERNEL_DIR)/include -Iinclude/ -DIPTABLES_VERSION=\"$(IPTABLES_VERSION)\" #-g -DDEBUG #-pg # -DIPTC_DEBUG
Marc Bouchere6869a82000-03-20 06:03:29 +000036
Harald Welte3efb6ea2001-08-06 18:50:21 +000037ifdef NO_SHARED_LIBS
38CFLAGS += -DNO_SHARED_LIBS=1
39endif
40
Henrik Nordstromc2794132004-01-22 15:04:24 +000041EXTRAS+=iptables iptables.o iptables.8
Rusty Russell01c45202001-01-07 06:50:31 +000042EXTRA_INSTALLS+=$(DESTDIR)$(BINDIR)/iptables $(DESTDIR)$(MANDIR)/man8/iptables.8
43
Harald Welteeba774d2001-10-16 08:22:40 +000044# No longer experimental.
Bastiaan Bakker4e3771f2004-06-25 11:18:57 +000045ifneq ($(DO_MULTI), 1)
Harald Welteeba774d2001-10-16 08:22:40 +000046EXTRAS+=iptables-save iptables-restore
Bastiaan Bakker4e3771f2004-06-25 11:18:57 +000047endif
Harald Welteeba774d2001-10-16 08:22:40 +000048EXTRA_INSTALLS+=$(DESTDIR)$(BINDIR)/iptables-save $(DESTDIR)$(BINDIR)/iptables-restore $(DESTDIR)$(MANDIR)/man8/iptables-restore.8 $(DESTDIR)$(MANDIR)/man8/iptables-save.8
Rusty Russell8e07bd72000-12-19 03:11:00 +000049
Harald Welte2354d922003-03-04 23:15:42 +000050ifeq ($(DO_IPV6), 1)
Henrik Nordstromc2794132004-01-22 15:04:24 +000051EXTRAS+=ip6tables ip6tables.o ip6tables.8
András Kis-Szabó06129432001-10-14 13:27:03 +000052EXTRA_INSTALLS+=$(DESTDIR)$(BINDIR)/ip6tables $(DESTDIR)$(MANDIR)/man8/ip6tables.8
Harald Welte8a6831a2001-03-15 15:33:56 +000053EXTRAS_EXP+=ip6tables-save ip6tables-restore
Harald Welte46d4d0a2001-03-16 15:48:56 +000054EXTRA_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 +000055endif
Marc Bouchere6869a82000-03-20 06:03:29 +000056
Rusty Russell09b9a412000-04-27 10:16:47 +000057# Sparc64 hack
58ifeq ($(shell uname -m),sparc64)
Martin Josefssondc93fce2004-05-26 15:46:27 +000059 POINTERTEST:=1
60 32bituser := $(shell echo -e "\#include <stdio.h>\n\#if !defined(__sparcv9) && !defined(__arch64__) && !defined(_LP64)\nuserspace_is_32bit\n\#endif" | $(CC) $(CFLAGS) -E - | grep userspace_is_32bit)
61 ifdef 32bituser
62 # The kernel is 64-bit, even though userspace is 32.
63 CFLAGS+=-DIPT_MIN_ALIGN=8 -DKERNEL_64_USERSPACE_32
64 else
65 EXT_LDFLAGS=-m elf64_sparc
66 endif
Rusty Russell09b9a412000-04-27 10:16:47 +000067endif
68
Martin Josefssondc93fce2004-05-26 15:46:27 +000069# Alpha only has 64bit userspace and fails the test below
70ifeq ($(shell uname -m), alpha)
71 POINTERTEST:=1
72endif
73
74# Generic test if arch wasn't found above
75ifneq ($(POINTERTEST),1)
76 # Try to determine if kernel is 64bit and we are compiling for 32bit
77 ifeq ($(shell [ -a $(KERNEL_DIR)/include/asm ] && echo YES), YES)
78 64bitkernel := $(shell echo -e "\#include <asm/types.h>\n\#if BITS_PER_LONG == 64\nkernel_is_64bits\n\#endif" | $(CC) $(CFLAGS) -D__KERNEL__ -E - | grep kernel_is_64bits)
79 ifdef 64bitkernel
80 32bituser := $(shell echo -e "\#include <stdio.h>\n\#if !defined(__arch64__) && !defined(_LP64)\nuserspace_is_32bit\n\#endif" | $(CC) $(CFLAGS) -E - | grep userspace_is_32bit)
81 ifdef 32bituser
82 CFLAGS+=-DIPT_MIN_ALIGN=8 -DKERNEL_64_USERSPACE_32
83 endif
84 endif
85 else
86 CFLAGS+=-D_UNKNOWN_KERNEL_POINTER_SIZE
87 endif
Rusty Russellda707152001-04-21 04:25:09 +000088endif
89
Marc Bouchere6869a82000-03-20 06:03:29 +000090ifndef IPT_LIBDIR
91IPT_LIBDIR:=$(LIBDIR)/iptables
92endif
93
Martin Josefssondc93fce2004-05-26 15:46:27 +000094ifndef NO_SHARED_LIBS
95DEPFILES = $(SHARED_LIBS:%.so=%.d)
96SH_CFLAGS:=$(CFLAGS) -fPIC
97STATIC_LIBS =
98STATIC6_LIBS =
99LDFLAGS = -rdynamic
100LDLIBS = -ldl -lnsl
101else
102DEPFILES = $(EXT_OBJS:%.o=%.d)
103STATIC_LIBS = extensions/libext.a
104STATIC6_LIBS = extensions/libext6.a
105LDFLAGS = -static
106LDLIBS =
107endif
108
Harald Welte7505d612001-07-31 13:06:17 +0000109.PHONY: default
Rusty Russell52451822000-08-27 07:47:46 +0000110default: print-extensions all
111
Harald Welte7505d612001-07-31 13:06:17 +0000112.PHONY: print-extensions
Rusty Russell52451822000-08-27 07:47:46 +0000113print-extensions:
Rusty Russellc8d7d892000-09-19 07:01:00 +0000114 @[ -n "$(OPTIONALS)" ] && echo Extensions found: $(OPTIONALS)
Marc Bouchere6869a82000-03-20 06:03:29 +0000115
116iptables.o: iptables.c
117 $(CC) $(CFLAGS) -DIPT_LIB_DIR=\"$(IPT_LIBDIR)\" -c -o $@ $<
118
Bastiaan Bakker4e3771f2004-06-25 11:18:57 +0000119ifeq ($(DO_MULTI), 1)
120iptables: iptables-multi.c iptables-save.c iptables-restore.c iptables-standalone.c iptables.o $(STATIC_LIBS) libiptc/libiptc.a
121 $(CC) $(CFLAGS) -DIPTABLES_MULTI -DIPT_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
122else
Harald Welte3efb6ea2001-08-06 18:50:21 +0000123iptables: iptables-standalone.c iptables.o $(STATIC_LIBS) libiptc/libiptc.a
124 $(CC) $(CFLAGS) -DIPT_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
Bastiaan Bakker4e3771f2004-06-25 11:18:57 +0000125endif
Marc Bouchere6869a82000-03-20 06:03:29 +0000126
127$(DESTDIR)$(BINDIR)/iptables: iptables
128 @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
129 cp $< $@
130
Harald Welte3efb6ea2001-08-06 18:50:21 +0000131iptables-save: iptables-save.c iptables.o $(STATIC_LIBS) libiptc/libiptc.a
132 $(CC) $(CFLAGS) -DIPT_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
Marc Bouchere6869a82000-03-20 06:03:29 +0000133
Bastiaan Bakker4e3771f2004-06-25 11:18:57 +0000134ifeq ($(DO_MULTI), 1)
135$(DESTDIR)$(BINDIR)/iptables-save: iptables
136 @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
137 ln -sf $< $@
138else
Marc Bouchere6869a82000-03-20 06:03:29 +0000139$(DESTDIR)$(BINDIR)/iptables-save: iptables-save
140 @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
141 cp $< $@
Bastiaan Bakker4e3771f2004-06-25 11:18:57 +0000142endif
Marc Bouchere6869a82000-03-20 06:03:29 +0000143
Harald Welte3efb6ea2001-08-06 18:50:21 +0000144iptables-restore: iptables-restore.c iptables.o $(STATIC_LIBS) libiptc/libiptc.a
145 $(CC) $(CFLAGS) -DIPT_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
Marc Bouchere6869a82000-03-20 06:03:29 +0000146
Bastiaan Bakker4e3771f2004-06-25 11:18:57 +0000147ifeq ($(DO_MULTI), 1)
148$(DESTDIR)$(BINDIR)/iptables-restore: iptables
149 @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
150 ln -sf $< $@
151else
Marc Bouchere6869a82000-03-20 06:03:29 +0000152$(DESTDIR)$(BINDIR)/iptables-restore: iptables-restore
153 @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
154 cp $< $@
Bastiaan Bakker4e3771f2004-06-25 11:18:57 +0000155endif
Marc Bouchere6869a82000-03-20 06:03:29 +0000156
Philip Blundell8c700902000-05-15 02:17:52 +0000157ip6tables.o: ip6tables.c
Harald Welte0aefbd32001-05-11 21:41:47 +0000158 $(CC) $(CFLAGS) -DIP6T_LIB_DIR=\"$(IPT_LIBDIR)\" -c -o $@ $<
Philip Blundell8c700902000-05-15 02:17:52 +0000159
Harald Welte3efb6ea2001-08-06 18:50:21 +0000160ip6tables: ip6tables-standalone.c ip6tables.o $(STATIC6_LIBS) libiptc/libiptc.a
Harald Welte2a7116e2002-08-26 13:09:40 +0000161 $(CC) $(CFLAGS) -DIP6T_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
Philip Blundell8c700902000-05-15 02:17:52 +0000162
163$(DESTDIR)$(BINDIR)/ip6tables: ip6tables
164 @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
165 cp $< $@
166
Harald Welte3efb6ea2001-08-06 18:50:21 +0000167ip6tables-save: ip6tables-save.c ip6tables.o $(STATIC6_LIBS) libiptc/libiptc.a
Harald Welte2a7116e2002-08-26 13:09:40 +0000168 $(CC) $(CFLAGS) -DIP6T_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
Philip Blundell8c700902000-05-15 02:17:52 +0000169
170$(DESTDIR)$(BINDIR)/ip6tables-save: ip6tables-save
171 @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
172 cp $< $@
173
Harald Welte3efb6ea2001-08-06 18:50:21 +0000174ip6tables-restore: ip6tables-restore.c ip6tables.o $(STATIC6_LIBS) libiptc/libiptc.a
Harald Welte2a7116e2002-08-26 13:09:40 +0000175 $(CC) $(CFLAGS) -DIP6T_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
Philip Blundell8c700902000-05-15 02:17:52 +0000176
177$(DESTDIR)$(BINDIR)/ip6tables-restore: ip6tables-restore
178 @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
179 cp $< $@
180
Rusty Russell01c45202001-01-07 06:50:31 +0000181$(DESTDIR)$(MANDIR)/man8/%.8: %.8
Marc Bouchere6869a82000-03-20 06:03:29 +0000182 @[ -d $(DESTDIR)$(MANDIR)/man8 ] || mkdir -p $(DESTDIR)$(MANDIR)/man8
183 cp $< $@
184
185EXTRA_DEPENDS+=iptables-standalone.d iptables.d
186
187iptables-standalone.d iptables.d: %.d: %.c
188 @-$(CC) -M -MG $(CFLAGS) $< | sed -e 's@^.*\.o:@$*.d $*.o:@' > $@
189
Henrik Nordstromc2794132004-01-22 15:04:24 +0000190iptables.8: iptables.8.in extensions/libipt_matches.man extensions/libipt_targets.man
191 sed -e '/@MATCH@/ r extensions/libipt_matches.man' -e '/@TARGET@/ r extensions/libipt_targets.man' iptables.8.in >iptables.8
192
193ip6tables.8: ip6tables.8.in extensions/libip6t_matches.man extensions/libip6t_targets.man
194 sed -e '/@MATCH@/ r extensions/libip6t_matches.man' -e '/@TARGET@/ r extensions/libiptt_targets.man' ip6tables.8.in >ip6tables.8
James Morrisc82e9ac2000-11-24 14:34:02 +0000195
196# Development Targets
Harald Welte7505d612001-07-31 13:06:17 +0000197.PHONY: install-devel-man3
James Morrisc82e9ac2000-11-24 14:34:02 +0000198install-devel-man3: $(DEVEL_MAN3)
199 @[ -d $(DESTDIR)$(MANDIR)/man3 ] || mkdir -p $(DESTDIR)$(MANDIR)/man3
200 @cp -v $(DEVEL_MAN3) $(DESTDIR)$(MANDIR)/man3
201
Harald Welte7505d612001-07-31 13:06:17 +0000202.PHONY: install-devel-headers
James Morrisc82e9ac2000-11-24 14:34:02 +0000203install-devel-headers: $(DEVEL_HEADERS)
204 @[ -d $(DESTDIR)$(INCDIR) ] || mkdir -p $(DESTDIR)$(INCDIR)
205 @cp -v $(DEVEL_HEADERS) $(DESTDIR)$(INCDIR)
206
Harald Welte7505d612001-07-31 13:06:17 +0000207.PHONY: install-devel-libs
James Morrisc82e9ac2000-11-24 14:34:02 +0000208install-devel-libs: $(DEVEL_LIBS)
209 @[ -d $(DESTDIR)$(LIBDIR) ] || mkdir -p $(DESTDIR)$(LIBDIR)
210 @cp -v $(DEVEL_LIBS) $(DESTDIR)$(LIBDIR)
211
Harald Welte7505d612001-07-31 13:06:17 +0000212.PHONY: install-devel
James Morrisc82e9ac2000-11-24 14:34:02 +0000213install-devel: all install-devel-man3 install-devel-headers install-devel-libs
214
Harald Welte7505d612001-07-31 13:06:17 +0000215.PHONY: distclean
Rusty Russell905795c2000-04-19 11:22:03 +0000216distclean: clean
Rusty Russella470f332000-11-07 04:08:34 +0000217 @rm -f TAGS `find . -name '*~' -o -name '.*~'` `find . -name '*.rej'` `find . -name '*.d'` .makefirst
Rusty Russell175f6412000-03-24 09:32:20 +0000218
219# Rusty's distro magic.
Harald Welte7505d612001-07-31 13:06:17 +0000220.PHONY: distrib
Harald Welte80fe35d2002-05-29 13:08:15 +0000221distrib: check distclean delrelease $(RELEASE_DIR)/iptables-$(IPTABLES_VERSION).tar.bz2 diff md5sums # nowhitespace
Rusty Russell175f6412000-03-24 09:32:20 +0000222
223# Makefile must not define:
Harald Welte380ba5f2002-02-13 16:19:55 +0000224# -g -pg -DIPTC_DEBUG
Harald Welte7505d612001-07-31 13:06:17 +0000225.PHONY: check
Rusty Russell175f6412000-03-24 09:32:20 +0000226check:
Harald Welte380ba5f2002-02-13 16:19:55 +0000227 @if echo $(CFLAGS) | egrep -e '-g|-pg|IPTC_DEBUG' >/dev/null; then echo Remove debugging flags; exit 1; else exit 0; fi
Rusty Russell175f6412000-03-24 09:32:20 +0000228
Harald Welte7505d612001-07-31 13:06:17 +0000229.PHONY: nowhitespace
Rusty Russell175f6412000-03-24 09:32:20 +0000230nowhitespace:
Rusty Russell2e5f9532001-01-07 09:37:02 +0000231 @if grep -n '[ ]$$' `find . -name 'Makefile' -o -name '*.[ch]'`; then exit 1; else exit 0; fi
Rusty Russell175f6412000-03-24 09:32:20 +0000232
Harald Welte7505d612001-07-31 13:06:17 +0000233.PHONY: delrelease
Rusty Russell175f6412000-03-24 09:32:20 +0000234delrelease:
Harald Welte80fe35d2002-05-29 13:08:15 +0000235 rm -f $(RELEASE_DIR)/iptables-$(IPTABLES_VERSION).tar.bz2
Rusty Russell175f6412000-03-24 09:32:20 +0000236
Harald Welte80fe35d2002-05-29 13:08:15 +0000237$(RELEASE_DIR)/iptables-$(IPTABLES_VERSION).tar.bz2:
Harald Welteea4ab1c2004-06-14 22:07:06 +0000238 cd .. && ln -sf iptables iptables-$(IPTABLES_VERSION) && tar cvf - --exclude CVS iptables-$(IPTABLES_VERSION)/. | bzip2 -9 > $@ && rm iptables-$(IPTABLES_VERSION)
Rusty Russell175f6412000-03-24 09:32:20 +0000239
Harald Welte7505d612001-07-31 13:06:17 +0000240.PHONY: diff
Harald Welte80fe35d2002-05-29 13:08:15 +0000241diff: $(RELEASE_DIR)/iptables-$(IPTABLES_VERSION).tar.bz2
Rusty Russell175f6412000-03-24 09:32:20 +0000242 @mkdir /tmp/diffdir
Harald Welte80fe35d2002-05-29 13:08:15 +0000243 @cd /tmp/diffdir && tar -x --bzip2 -f $(RELEASE_DIR)/iptables-$(IPTABLES_VERSION).tar.bz2
244 @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 +0000245 @rm -rf /tmp/diffdir
246
Harald Welte7505d612001-07-31 13:06:17 +0000247.PHONY: md5sums
Rusty Russell175f6412000-03-24 09:32:20 +0000248md5sums:
Harald Welte80fe35d2002-05-29 13:08:15 +0000249 cd $(RELEASE_DIR)/ && md5sum patch-iptables-*-$(IPTABLES_VERSION).bz2 iptables-$(IPTABLES_VERSION).tar.bz2
Rusty Russell175f6412000-03-24 09:32:20 +0000250
Marc Bouchere6869a82000-03-20 06:03:29 +0000251# $(wildcard) fails wierdly with make v.3.78.1.
252include $(shell echo */Makefile)
253include Rules.make