Setting tag iptables-1.3.8-12
[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="/lib/modules/$(shell uname -r)/build"
16 endif
17 IPTABLES_VERSION:=1.3.8
18 OLD_IPTABLES_VERSION:=1.3.7
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 # Enable linking to libselinux via enviornment 'DO_SELINUX=1'
35 ifndef DO_SELINUX
36 DO_SELINUX=0
37 endif
38
39 COPT_FLAGS:=-O2
40 CFLAGS:=$(COPT_FLAGS) -Wall -Wunused -I$(KERNEL_DIR)/include -D__KERNGLUE__ -Iinclude/ -DIPTABLES_VERSION=\"$(IPTABLES_VERSION)\" #-g -DDEBUG #-pg # -DIPTC_DEBUG
41
42 ifdef NO_SHARED_LIBS
43 CFLAGS += -DNO_SHARED_LIBS=1
44 endif
45
46 EXTRAS+=iptables iptables.o iptables.8
47 EXTRA_INSTALLS+=$(DESTDIR)$(BINDIR)/iptables $(DESTDIR)$(MANDIR)/man8/iptables.8
48
49 # No longer experimental.
50 ifneq ($(DO_MULTI), 1)
51 EXTRAS+=iptables-save iptables-restore iptables-xml
52 endif
53 EXTRA_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
54
55 ifeq ($(DO_IPV6), 1)
56 EXTRAS+=ip6tables ip6tables.o ip6tables.8
57 EXTRA_INSTALLS+=$(DESTDIR)$(BINDIR)/ip6tables $(DESTDIR)$(MANDIR)/man8/ip6tables.8
58 EXTRAS_EXP+=ip6tables-save ip6tables-restore
59 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
60 endif
61
62 # Sparc64 hack
63 ifeq ($(shell uname -m),sparc64)
64         POINTERTEST:=1
65         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)
66         ifdef 32bituser
67                 # The kernel is 64-bit, even though userspace is 32.
68                 CFLAGS+=-DIPT_MIN_ALIGN=8 -DKERNEL_64_USERSPACE_32
69         else
70                 EXT_LDFLAGS+=-Wl,-m,elf64_sparc
71         endif
72 endif
73
74 # Alpha only has 64bit userspace and fails the test below
75 ifeq ($(shell uname -m), alpha)
76         POINTERTEST:=1
77 endif
78
79 # Generic test if arch wasn't found above
80 ifneq ($(POINTERTEST),1)
81         # Try to determine if kernel is 64bit and we are compiling for 32bit
82         ifeq ($(shell [ -d $(KERNEL_DIR)/include/asm ] && echo YES), YES)
83                 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)
84                 ifdef 64bitkernel
85                         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)
86                         ifdef 32bituser
87                                 CFLAGS+=-DIPT_MIN_ALIGN=8 -DKERNEL_64_USERSPACE_32
88                         endif
89                 endif
90         else
91                 CFLAGS+=-D_UNKNOWN_KERNEL_POINTER_SIZE
92         endif
93 endif
94
95 ifndef IPT_LIBDIR
96 IPT_LIBDIR:=$(LIBDIR)/iptables
97 endif
98
99 ifndef NO_SHARED_LIBS
100 DEPFILES = $(SHARED_LIBS:%.so=%.d)
101 DEPFILES += $(SHARED_SE_LIBS:%.so=%.d)
102 SH_CFLAGS:=$(CFLAGS) -fPIC
103 STATIC_LIBS  =
104 STATIC6_LIBS =
105 LDFLAGS      = -rdynamic
106 LDLIBS       = -ldl
107 ifeq ($(DO_SELINUX), 1)
108 LDLIBS       += -lselinux
109 endif
110 else
111 DEPFILES = $(EXT_OBJS:%.o=%.d)
112 STATIC_LIBS  = extensions/libext.a
113 STATIC6_LIBS = extensions/libext6.a
114 LDFLAGS      = -static
115 LDLIBS       =
116 ifeq ($(DO_SELINUX), 1)
117 LDLIBS       += -lselinux
118 endif
119 endif
120
121 .PHONY: default
122 default: print-extensions all
123
124 .PHONY: print-extensions
125 print-extensions:
126         @[ -n "$(OPTIONALS)" ] && echo Extensions found: $(OPTIONALS)
127
128 iptables.o: iptables.c
129         $(CC) $(CFLAGS) -DIPT_LIB_DIR=\"$(IPT_LIBDIR)\" -c -o $@ $<
130
131 ifeq ($(DO_MULTI), 1)
132 iptables: iptables-multi.c iptables-save.c iptables-restore.c iptables-xml.c iptables-standalone.c iptables.o $(STATIC_LIBS) libiptc/libiptc.a
133         $(CC) $(CFLAGS) -DIPTABLES_MULTI -DIPT_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
134 else
135 iptables: iptables-standalone.c iptables.o $(STATIC_LIBS) libiptc/libiptc.a
136         $(CC) $(CFLAGS) -DIPT_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
137 endif
138
139 $(DESTDIR)$(BINDIR)/iptables: iptables
140         @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
141         cp $< $@
142
143 iptables-save: iptables-save.c iptables.o $(STATIC_LIBS) libiptc/libiptc.a
144         $(CC) $(CFLAGS) -DIPT_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
145
146 ifeq ($(DO_MULTI), 1)
147 $(DESTDIR)$(BINDIR)/iptables-save: iptables
148         @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
149         ln -sf $< $@
150 else
151 $(DESTDIR)$(BINDIR)/iptables-save: iptables-save
152         @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
153         cp $< $@
154 endif
155
156 iptables-restore: iptables-restore.c iptables.o $(STATIC_LIBS) libiptc/libiptc.a
157         $(CC) $(CFLAGS) -DIPT_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
158
159 ifeq ($(DO_MULTI), 1)
160 $(DESTDIR)$(BINDIR)/iptables-restore: iptables
161         @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
162         ln -sf $< $@
163 else
164 $(DESTDIR)$(BINDIR)/iptables-restore: iptables-restore
165         @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
166         cp $< $@
167 endif
168
169 iptables-xml: iptables-xml.c #iptables.o # $(STATIC_LIBS) libiptc/libiptc.a
170         $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
171
172 ifeq ($(DO_MULTI), 1)
173 $(DESTDIR)$(BINDIR)/iptables-xml: iptables
174         @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
175         ln -sf $< $@
176 else
177 $(DESTDIR)$(BINDIR)/iptables-xml: iptables-xml
178         @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
179         cp $< $@
180 endif
181
182 ip6tables.o: ip6tables.c
183         $(CC) $(CFLAGS) -DIP6T_LIB_DIR=\"$(IPT_LIBDIR)\" -c -o $@ $<
184
185 ip6tables: ip6tables-standalone.c ip6tables.o $(STATIC6_LIBS) libiptc/libiptc.a
186         $(CC) $(CFLAGS) -DIP6T_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
187
188 $(DESTDIR)$(BINDIR)/ip6tables: ip6tables
189         @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
190         cp $< $@
191
192 ip6tables-save: ip6tables-save.c ip6tables.o $(STATIC6_LIBS) libiptc/libiptc.a
193         $(CC) $(CFLAGS) -DIP6T_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
194
195 $(DESTDIR)$(BINDIR)/ip6tables-save: ip6tables-save
196         @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
197         cp $< $@
198
199 ip6tables-restore: ip6tables-restore.c ip6tables.o $(STATIC6_LIBS) libiptc/libiptc.a
200         $(CC) $(CFLAGS) -DIP6T_LIB_DIR=\"$(IPT_LIBDIR)\" $(LDFLAGS) -o $@ $^ $(LDLIBS)
201
202 $(DESTDIR)$(BINDIR)/ip6tables-restore: ip6tables-restore
203         @[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
204         cp $< $@
205
206 $(DESTDIR)$(MANDIR)/man8/%.8: %.8
207         @[ -d $(DESTDIR)$(MANDIR)/man8 ] || mkdir -p $(DESTDIR)$(MANDIR)/man8
208         cp $< $@
209
210 EXTRA_DEPENDS+=iptables-standalone.d iptables.d
211
212 iptables-standalone.d iptables.d: %.d: %.c
213         @-$(CC) -M -MG $(CFLAGS) $< | sed -e 's@^.*\.o:@$*.d $*.o:@' > $@
214
215 iptables.8: iptables.8.in extensions/libipt_matches.man extensions/libipt_targets.man
216         sed -e '/@MATCH@/ r extensions/libipt_matches.man' -e '/@TARGET@/ r extensions/libipt_targets.man' iptables.8.in >iptables.8
217
218 ip6tables.8: ip6tables.8.in extensions/libip6t_matches.man extensions/libip6t_targets.man
219         sed -e '/@MATCH@/ r extensions/libip6t_matches.man' -e '/@TARGET@/ r extensions/libip6t_targets.man' ip6tables.8.in >ip6tables.8
220
221 # Development Targets
222 .PHONY: install-devel-man3
223 install-devel-man3: $(DEVEL_MAN3)
224         @[ -d $(DESTDIR)$(MANDIR)/man3 ] || mkdir -p $(DESTDIR)$(MANDIR)/man3
225         @cp -v $(DEVEL_MAN3) $(DESTDIR)$(MANDIR)/man3
226
227 .PHONY: install-devel-headers
228 install-devel-headers: $(DEVEL_HEADERS)
229         @[ -d $(DESTDIR)$(INCDIR) ] || mkdir -p $(DESTDIR)$(INCDIR)
230         @cp -v $(DEVEL_HEADERS) $(DESTDIR)$(INCDIR)
231
232 .PHONY: install-devel-libs
233 install-devel-libs: $(DEVEL_LIBS)
234         @[ -d $(DESTDIR)$(LIBDIR) ] || mkdir -p $(DESTDIR)$(LIBDIR)
235         @cp -v $(DEVEL_LIBS) $(DESTDIR)$(LIBDIR)
236
237 .PHONY: install-devel
238 install-devel: all install-devel-man3 install-devel-headers install-devel-libs
239
240 .PHONY: distclean
241 distclean: clean
242         @rm -f TAGS `find . -name '*~' -o -name '.*~'` `find . -name '*.rej'` `find . -name '*.d'` .makefirst
243
244 # Rusty's distro magic.
245 .PHONY: distrib
246 distrib: check distclean delrelease $(RELEASE_DIR)/iptables-$(IPTABLES_VERSION).tar.bz2 diff md5sums # nowhitespace
247
248 # Makefile must not define:
249 # -g -pg -DIPTC_DEBUG
250 .PHONY: check
251 check:
252         @if echo $(CFLAGS) | egrep -e '(^|[[:space:]])(-g|-pg|-DIPTC_DEBUG)([[:space:]]|$)' >/dev/null; then echo Remove debugging flags; exit 1; else exit 0; fi
253
254 .PHONY: nowhitespace
255 nowhitespace:
256         @if grep -n '[  ]$$' `find . -name 'Makefile' -o -name '*.[ch]'`; then exit 1; else exit 0; fi
257
258 .PHONY: delrelease
259 delrelease:
260         rm -f $(RELEASE_DIR)/iptables-$(IPTABLES_VERSION).tar.bz2
261
262 $(RELEASE_DIR)/iptables-$(IPTABLES_VERSION).tar.bz2:
263         cd .. && ln -sf iptables iptables-$(IPTABLES_VERSION) && tar cvf - --exclude .svn iptables-$(IPTABLES_VERSION)/. | bzip2 -9 > $@ && rm iptables-$(IPTABLES_VERSION)
264
265 .PHONY: diff
266 diff: $(RELEASE_DIR)/iptables-$(IPTABLES_VERSION).tar.bz2
267         @mkdir /tmp/diffdir
268         @cd /tmp/diffdir && tar -x --bzip2 -f $(RELEASE_DIR)/iptables-$(IPTABLES_VERSION).tar.bz2
269         @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
270         @rm -rf /tmp/diffdir
271
272 .PHONY: md5sums
273 md5sums:
274         cd $(RELEASE_DIR)/ && md5sum patch-iptables-*-$(IPTABLES_VERSION).bz2 iptables-$(IPTABLES_VERSION).tar.bz2
275
276 # $(wildcard) fails wierdly with make v.3.78.1.
277 include $(shell echo */Makefile)
278 include Rules.make