Merge to iptables-1.3.5
[iptables.git] / Makefile
1 # uncomment this to get a fully statically linked version
2 # NO_SHARED_LIBS = 1
3
4 # uncomment this to disable IPv6 support
5 # DO_IPV6 = 0
6
7 ######################################################################
8 # YOU SHOULD NOT NEED TO TOUCH ANYTHING BELOW THIS LINE
9 ######################################################################
10
11 # Standard part of Makefile for topdir.
12 TOPLEVEL_INCLUDED=YES
13
14 ifndef KERNEL_DIR
15 KERNEL_DIR=/usr/src/linux
16 endif
17 IPTABLES_VERSION:=1.3.5
18 OLD_IPTABLES_VERSION:=1.3.4
19
20 PREFIX:=/usr/local
21 LIBDIR:=$(PREFIX)/lib
22 BINDIR:=$(PREFIX)/sbin
23 MANDIR:=$(PREFIX)/man
24 INCDIR:=$(PREFIX)/include
25
26 # directory for new iptables releases
27 RELEASE_DIR:=/tmp
28
29 # Need libc6 for this.  FIXME: Should covert to autoconf.
30 ifeq ($(shell [ -f /usr/include/netinet/ip6.h ] && echo YES), YES)
31 DO_IPV6:=1
32 endif
33
34 COPT_FLAGS:=-O2
35 CFLAGS:=$(COPT_FLAGS) -Wall -Wunused -I$(KERNEL_DIR)/include -D__KERNGLUE__ -Iinclude/ -DIPTABLES_VERSION=\"$(IPTABLES_VERSION)\" #-g -DDEBUG #-pg # -DIPTC_DEBUG
36
37 ifdef NO_SHARED_LIBS
38 CFLAGS += -DNO_SHARED_LIBS=1
39 endif
40
41 EXTRAS+=iptables iptables.o iptables.8
42 EXTRA_INSTALLS+=$(DESTDIR)$(BINDIR)/iptables $(DESTDIR)$(MANDIR)/man8/iptables.8
43
44 # No longer experimental.
45 ifneq ($(DO_MULTI), 1)
46 EXTRAS+=iptables-save iptables-restore
47 endif
48 EXTRA_INSTALLS+=$(DESTDIR)$(BINDIR)/iptables-save $(DESTDIR)$(BINDIR)/iptables-restore $(DESTDIR)$(MANDIR)/man8/iptables-restore.8 $(DESTDIR)$(MANDIR)/man8/iptables-save.8
49
50 ifeq ($(DO_IPV6), 1)
51 EXTRAS+=ip6tables ip6tables.o ip6tables.8
52 EXTRA_INSTALLS+=$(DESTDIR)$(BINDIR)/ip6tables $(DESTDIR)$(MANDIR)/man8/ip6tables.8
53 EXTRAS_EXP+=ip6tables-save ip6tables-restore
54 EXTRA_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
55 endif
56
57 # Sparc64 hack
58 ifeq ($(shell uname -m),sparc64)
59         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
67 endif
68
69 # Alpha only has 64bit userspace and fails the test below
70 ifeq ($(shell uname -m), alpha)
71         POINTERTEST:=1
72 endif
73
74 # Generic test if arch wasn't found above
75 ifneq ($(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
88 endif
89
90 ifndef IPT_LIBDIR
91 IPT_LIBDIR:=$(LIBDIR)/iptables
92 endif
93
94 ifndef NO_SHARED_LIBS
95 DEPFILES = $(SHARED_LIBS:%.so=%.d)
96 SH_CFLAGS:=$(CFLAGS) -fPIC
97 STATIC_LIBS  =
98 STATIC6_LIBS =
99 LDFLAGS      = -rdynamic
100 LDLIBS       = -ldl -lnsl
101 else
102 DEPFILES = $(EXT_OBJS:%.o=%.d)
103 STATIC_LIBS  = extensions/libext.a
104 STATIC6_LIBS = extensions/libext6.a
105 LDFLAGS      = -static
106 LDLIBS       =
107 endif
108
109 .PHONY: default
110 default: print-extensions all
111
112 .PHONY: print-extensions
113 print-extensions:
114         @[ -n "$(OPTIONALS)" ] && echo Extensions found: $(OPTIONALS)
115
116 iptables.o: iptables.c
117         $(CC) $(CFLAGS) -DIPT_LIB_DIR=\"$(IPT_LIBDIR)\" -c -o $@ $<
118
119 ifeq ($(DO_MULTI), 1)
120 iptables: 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)
122 else
123 iptables: iptables-standalone.c iptables.o $(STATIC_LIBS) libiptc/libiptc.a
124         $(CC) $(CFLAGS) -DIPT_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
125 endif
126
127 $(DESTDIR)$(BINDIR)/iptables: iptables
128         @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
129         cp $< $@
130
131 iptables-save: iptables-save.c iptables.o $(STATIC_LIBS) libiptc/libiptc.a
132         $(CC) $(CFLAGS) -DIPT_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
133
134 ifeq ($(DO_MULTI), 1)
135 $(DESTDIR)$(BINDIR)/iptables-save: iptables
136         @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
137         ln -sf $< $@
138 else
139 $(DESTDIR)$(BINDIR)/iptables-save: iptables-save
140         @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
141         cp $< $@
142 endif
143
144 iptables-restore: iptables-restore.c iptables.o $(STATIC_LIBS) libiptc/libiptc.a
145         $(CC) $(CFLAGS) -DIPT_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
146
147 ifeq ($(DO_MULTI), 1)
148 $(DESTDIR)$(BINDIR)/iptables-restore: iptables
149         @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
150         ln -sf $< $@
151 else
152 $(DESTDIR)$(BINDIR)/iptables-restore: iptables-restore
153         @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
154         cp $< $@
155 endif
156
157 ip6tables.o: ip6tables.c
158         $(CC) $(CFLAGS) -DIP6T_LIB_DIR=\"$(IPT_LIBDIR)\" -c -o $@ $<
159
160 ip6tables: ip6tables-standalone.c ip6tables.o $(STATIC6_LIBS) libiptc/libiptc.a
161         $(CC) $(CFLAGS) -DIP6T_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
162
163 $(DESTDIR)$(BINDIR)/ip6tables: ip6tables
164         @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
165         cp $< $@
166
167 ip6tables-save: ip6tables-save.c ip6tables.o $(STATIC6_LIBS) libiptc/libiptc.a
168         $(CC) $(CFLAGS) -DIP6T_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
169
170 $(DESTDIR)$(BINDIR)/ip6tables-save: ip6tables-save
171         @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
172         cp $< $@
173
174 ip6tables-restore: ip6tables-restore.c ip6tables.o $(STATIC6_LIBS) libiptc/libiptc.a
175         $(CC) $(CFLAGS) -DIP6T_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
176
177 $(DESTDIR)$(BINDIR)/ip6tables-restore: ip6tables-restore
178         @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
179         cp $< $@
180
181 $(DESTDIR)$(MANDIR)/man8/%.8: %.8
182         @[ -d $(DESTDIR)$(MANDIR)/man8 ] || mkdir -p $(DESTDIR)$(MANDIR)/man8
183         cp $< $@
184
185 EXTRA_DEPENDS+=iptables-standalone.d iptables.d
186
187 iptables-standalone.d iptables.d: %.d: %.c
188         @-$(CC) -M -MG $(CFLAGS) $< | sed -e 's@^.*\.o:@$*.d $*.o:@' > $@
189
190 iptables.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
193 ip6tables.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/libip6t_targets.man' ip6tables.8.in >ip6tables.8
195
196 # Development Targets
197 .PHONY: install-devel-man3
198 install-devel-man3: $(DEVEL_MAN3)
199         @[ -d $(DESTDIR)$(MANDIR)/man3 ] || mkdir -p $(DESTDIR)$(MANDIR)/man3
200         @cp -v $(DEVEL_MAN3) $(DESTDIR)$(MANDIR)/man3
201
202 .PHONY: install-devel-headers
203 install-devel-headers: $(DEVEL_HEADERS)
204         @[ -d $(DESTDIR)$(INCDIR) ] || mkdir -p $(DESTDIR)$(INCDIR)
205         @cp -v $(DEVEL_HEADERS) $(DESTDIR)$(INCDIR)
206
207 .PHONY: install-devel-libs
208 install-devel-libs: $(DEVEL_LIBS)
209         @[ -d $(DESTDIR)$(LIBDIR) ] || mkdir -p $(DESTDIR)$(LIBDIR)
210         @cp -v $(DEVEL_LIBS) $(DESTDIR)$(LIBDIR)
211
212 .PHONY: install-devel
213 install-devel: all install-devel-man3 install-devel-headers install-devel-libs
214
215 .PHONY: distclean
216 distclean: clean
217         @rm -f TAGS `find . -name '*~' -o -name '.*~'` `find . -name '*.rej'` `find . -name '*.d'` .makefirst
218
219 # Rusty's distro magic.
220 .PHONY: distrib
221 distrib: check distclean delrelease $(RELEASE_DIR)/iptables-$(IPTABLES_VERSION).tar.bz2 diff md5sums # nowhitespace
222
223 # Makefile must not define:
224 # -g -pg -DIPTC_DEBUG
225 .PHONY: check
226 check:
227         @if echo $(CFLAGS) | egrep -e '-g|-pg|IPTC_DEBUG' >/dev/null; then echo Remove debugging flags; exit 1; else exit 0; fi
228
229 .PHONY: nowhitespace
230 nowhitespace:
231         @if grep -n '[  ]$$' `find . -name 'Makefile' -o -name '*.[ch]'`; then exit 1; else exit 0; fi
232
233 .PHONY: delrelease
234 delrelease:
235         rm -f $(RELEASE_DIR)/iptables-$(IPTABLES_VERSION).tar.bz2
236
237 $(RELEASE_DIR)/iptables-$(IPTABLES_VERSION).tar.bz2:
238         cd .. && ln -sf iptables iptables-$(IPTABLES_VERSION) && tar cvf - --exclude .svn iptables-$(IPTABLES_VERSION)/. | bzip2 -9 > $@ && rm iptables-$(IPTABLES_VERSION)
239
240 .PHONY: diff
241 diff: $(RELEASE_DIR)/iptables-$(IPTABLES_VERSION).tar.bz2
242         @mkdir /tmp/diffdir
243         @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
245         @rm -rf /tmp/diffdir
246
247 .PHONY: md5sums
248 md5sums:
249         cd $(RELEASE_DIR)/ && md5sum patch-iptables-*-$(IPTABLES_VERSION).bz2 iptables-$(IPTABLES_VERSION).tar.bz2
250
251 # $(wildcard) fails wierdly with make v.3.78.1.
252 include $(shell echo */Makefile)
253 include Rules.make