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