blob: 00758aec0a5a1b6534917afc3efa1e75b1f1037e [file] [log] [blame]
Bart De Schuymer1abc55d2002-06-01 19:23:47 +00001# ebtables Makefile
2
Bart De Schuymer1abc55d2002-06-01 19:23:47 +00003PROGNAME:=ebtables
Bart De Schuymer22d8f5f2007-05-28 16:45:38 +00004PROGRELEASE:=1
Bart De Schuymer865dd4d2006-12-15 11:37:07 +00005PROGVERSION_:=2.0.8
Bart De Schuymer865dd4d2006-12-15 11:37:07 +00006PROGVERSION:=$(PROGVERSION_)-$(PROGRELEASE)
Bart De Schuymerbb791d92007-05-28 11:06:14 +00007PROGDATE:=May\ 2007
Bart De Schuymer1abc55d2002-06-01 19:23:47 +00008
Bart De Schuymer3749f302004-02-11 21:23:38 +00009# default paths
Bart De Schuymer38561e92004-02-23 09:20:42 +000010LIBDIR:=/usr/lib
Bart De Schuymer3749f302004-02-11 21:23:38 +000011MANDIR:=/usr/local/man
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000012BINDIR:=/usr/local/sbin
Bart De Schuymer3749f302004-02-11 21:23:38 +000013ETCDIR:=/etc
Bart De Schuymer50441e92005-08-30 21:20:55 +000014INITDIR:=/etc/rc.d/init.d
15SYSCONFIGDIR:=/etc/sysconfig
Bart De Schuymer38561e92004-02-23 09:20:42 +000016DESTDIR:=
Bart De Schuymer3749f302004-02-11 21:23:38 +000017
18# include DESTDIR param
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000019override LIBDIR:=$(DESTDIR)$(LIBDIR)/$(PROGNAME)
Bart De Schuymer3749f302004-02-11 21:23:38 +000020override MANDIR:=$(DESTDIR)$(MANDIR)
21override BINDIR:=$(DESTDIR)$(BINDIR)
22override ETCDIR:=$(DESTDIR)$(ETCDIR)
Bart De Schuymer50441e92005-08-30 21:20:55 +000023override INITDIR:=$(DESTDIR)$(INITDIR)
24override SYSCONFIGDIR:=$(DESTDIR)$(SYSCONFIGDIR)
Bart De Schuymer3749f302004-02-11 21:23:38 +000025
26
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000027CFLAGS:=-Wall -Wunused
Bart De Schuymer17c60f52006-12-14 18:55:44 +000028CFLAGS_SH_LIB:=-fPIC
Bart De Schuymer06a1b462002-09-07 11:51:13 +000029CC:=gcc
Bart De Schuymer64182a32004-01-21 20:39:54 +000030LD:=ld
Bart De Schuymer3c1e00c2002-12-07 11:18:57 +000031
Bart De Schuymer60c20092003-07-23 21:34:21 +000032ifeq ($(shell uname -m),sparc64)
33CFLAGS+=-DEBT_MIN_ALIGN=8 -DKERNEL_64_USERSPACE_32
34endif
35
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000036include extensions/Makefile
37
Bart De Schuymer64182a32004-01-21 20:39:54 +000038OBJECTS2:=getethertype.o communication.o libebtc.o \
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000039useful_functions.o ebtables.o
Bart De Schuymer64182a32004-01-21 20:39:54 +000040
Bart De Schuymer7d9e3eb2006-02-06 21:24:02 +000041OBJECTS:=$(OBJECTS2) $(EXT_OBJS) $(EXT_LIBS)
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000042
Bart De Schuymer06a96822003-02-19 20:09:51 +000043KERNEL_INCLUDES?=include/
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000044
Bart De Schuymer3749f302004-02-11 21:23:38 +000045ETHERTYPESPATH?=$(ETCDIR)
Bart De Schuymera2960382003-04-01 17:29:13 +000046ETHERTYPESFILE:=$(ETHERTYPESPATH)/ethertypes
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000047
Bart De Schuymer50441e92005-08-30 21:20:55 +000048PIPE_DIR?=$(DESTDIR)/tmp/$(PROGNAME)-v$(PROGVERSION)
Bart De Schuymer6622a012005-01-19 21:09:05 +000049PIPE=$(PIPE_DIR)/ebtablesd_pipe
50EBTD_CMDLINE_MAXLN?=2048
51EBTD_ARGC_MAX?=50
52
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000053PROGSPECS:=-DPROGVERSION=\"$(PROGVERSION)\" \
54 -DPROGNAME=\"$(PROGNAME)\" \
55 -DPROGDATE=\"$(PROGDATE)\" \
Bart De Schuymer9d680cc2005-10-01 09:16:51 +000056 -D_PATH_ETHERTYPES=\"$(ETHERTYPESFILE)\" \
57 -DEBTD_ARGC_MAX=$(EBTD_ARGC_MAX) \
58 -DEBTD_CMDLINE_MAXLN=$(EBTD_CMDLINE_MAXLN)
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000059
Bart De Schuymer96ee8d12005-11-04 21:59:57 +000060# You can probably ignore this, ebtables{u,d} are normally not used
Bart De Schuymer6622a012005-01-19 21:09:05 +000061PROGSPECSD:=-DPROGVERSION=\"$(PROGVERSION)\" \
62 -DPROGNAME=\"$(PROGNAME)\" \
63 -DPROGDATE=\"$(PROGDATE)\" \
64 -D_PATH_ETHERTYPES=\"$(ETHERTYPESFILE)\" \
65 -DEBTD_CMDLINE_MAXLN=$(EBTD_CMDLINE_MAXLN) \
66 -DEBTD_ARGC_MAX=$(EBTD_ARGC_MAX) \
67 -DEBTD_PIPE=\"$(PIPE)\" \
68 -DEBTD_PIPE_DIR=\"$(PIPE_DIR)\"
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000069
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000070# Uncomment for debugging (slower)
71#PROGSPECS+=-DEBT_DEBUG
72#PROGSPECSD+=-DEBT_DEBUG
Bart De Schuymer96ee8d12005-11-04 21:59:57 +000073#CFLAGS+=-ggdb
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000074
Bart De Schuymer96ee8d12005-11-04 21:59:57 +000075all: ebtables ebtables-restore
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000076
77communication.o: communication.c include/ebtables_u.h
Bart De Schuymer17c60f52006-12-14 18:55:44 +000078 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES)
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000079
Bart De Schuymer8339ff12004-01-14 20:05:27 +000080libebtc.o: libebtc.c include/ebtables_u.h
Bart De Schuymer17c60f52006-12-14 18:55:44 +000081 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES)
Bart De Schuymer8339ff12004-01-14 20:05:27 +000082
83useful_functions.o: useful_functions.c include/ebtables_u.h
Bart De Schuymer17c60f52006-12-14 18:55:44 +000084 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES)
Bart De Schuymer8339ff12004-01-14 20:05:27 +000085
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000086getethertype.o: getethertype.c include/ethernetdb.h
Bart De Schuymer17c60f52006-12-14 18:55:44 +000087 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -Iinclude/
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000088
89ebtables.o: ebtables.c include/ebtables_u.h
Bart De Schuymereacf5c92007-07-03 17:48:53 +000090 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES)
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000091
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000092ebtables-standalone.o: ebtables-standalone.c include/ebtables_u.h
Bart De Schuymereacf5c92007-07-03 17:48:53 +000093 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c $< -o $@ -I$(KERNEL_INCLUDES)
Bart De Schuymer6622a012005-01-19 21:09:05 +000094
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000095.PHONY: libebtc
96libebtc: $(OBJECTS2)
Bart De Schuymere1c15882004-05-24 19:57:58 +000097 $(LD) -shared -soname libebtc.so -o libebtc.so -lc $(OBJECTS2)
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000098
99ebtables: $(OBJECTS) ebtables-standalone.o libebtc
Bart De Schuymere1c315a2006-12-22 18:08:41 +0000100 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) -o $@ ebtables-standalone.o -I$(KERNEL_INCLUDES) -L. -Lextensions -lebtc $(EXT_LIBSI) \
Bart De Schuymer838fa5b2005-06-18 14:43:32 +0000101 -Wl,-rpath,$(LIBDIR)
Bart De Schuymer6622a012005-01-19 21:09:05 +0000102
103ebtablesu: ebtablesu.c
104 $(CC) $(CFLAGS) $(PROGSPECSD) $< -o $@
105
Bart De Schuymer838fa5b2005-06-18 14:43:32 +0000106ebtablesd.o: ebtablesd.c include/ebtables_u.h
107 $(CC) $(CFLAGS) $(PROGSPECSD) -c $< -o $@ -I$(KERNEL_INCLUDES)
Bart De Schuymer6622a012005-01-19 21:09:05 +0000108
Bart De Schuymer838fa5b2005-06-18 14:43:32 +0000109ebtablesd: $(OBJECTS) ebtablesd.o libebtc
110 $(CC) $(CFLAGS) -o $@ ebtablesd.o -I$(KERNEL_INCLUDES) -L. -Lextensions -lebtc $(EXT_LIBSI) \
111 -Wl,-rpath,$(LIBDIR)
Bart De Schuymer6622a012005-01-19 21:09:05 +0000112
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000113ebtables-restore.o: ebtables-restore.c include/ebtables_u.h
Bart De Schuymer9d680cc2005-10-01 09:16:51 +0000114 $(CC) $(CFLAGS) $(PROGSPECS) -c $< -o $@ -I$(KERNEL_INCLUDES)
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000115
116ebtables-restore: $(OBJECTS) ebtables-restore.o libebtc
117 $(CC) $(CFLAGS) -o $@ ebtables-restore.o -I$(KERNEL_INCLUDES) -L. -Lextensions -lebtc $(EXT_LIBSI) \
118 -Wl,-rpath,$(LIBDIR)
119
Bart De Schuymer6622a012005-01-19 21:09:05 +0000120.PHONY: daemon
121daemon: ebtablesd ebtablesu
122
Bart De Schuymer7d9e3eb2006-02-06 21:24:02 +0000123# a little scripting for a static binary, making one for ebtables-restore
124# should be completely analogous
125static: extensions/ebt_*.c extensions/ebtable_*.c ebtables.c communication.c ebtables-standalone.c getethertype.c libebtc.c useful_functions.c
126 cp ebtables-standalone.c ebtables-standalone.c_ ; \
127 cp include/ebtables_u.h include/ebtables_u.h_ ; \
128 sed "s/ main(/ pseudomain(/" ebtables-standalone.c > ebtables-standalone.c__ ; \
129 mv ebtables-standalone.c__ ebtables-standalone.c ; \
130 printf "\nint main(int argc, char *argv[])\n{\n " >> ebtables-standalone.c ; \
131 for arg in $(EXT_FUNC) \
132 ; do \
133 sed s/_init/_$${arg}_init/ extensions/ebt_$${arg}.c > extensions/ebt_$${arg}.c_ ; \
134 mv extensions/ebt_$${arg}.c_ extensions/ebt_$${arg}.c ; \
135 printf "\t%s();\n" _$${arg}_init >> ebtables-standalone.c ; \
136 printf "extern void %s();\n" _$${arg}_init >> include/ebtables_u.h ; \
137 done ; \
138 for arg in $(EXT_TABLES) \
139 ; do \
140 sed s/_init/_t_$${arg}_init/ extensions/ebtable_$${arg}.c > extensions/ebtable_$${arg}.c_ ; \
141 mv extensions/ebtable_$${arg}.c_ extensions/ebtable_$${arg}.c ; \
142 printf "\t%s();\n" _t_$${arg}_init >> ebtables-standalone.c ; \
143 printf "extern void %s();\n" _t_$${arg}_init >> include/ebtables_u.h ; \
144 done ; \
145 printf "\n\tpseudomain(argc, argv);\n\treturn 0;\n}\n" >> ebtables-standalone.c ;\
Bart De Schuymerdc5d9fc2006-08-09 10:28:14 +0000146 $(CC) $(CFLAGS) $(PROGSPECS) -o $@ $^ -I$(KERNEL_INCLUDES) -Iinclude ; \
Bart De Schuymer7d9e3eb2006-02-06 21:24:02 +0000147 for arg in $(EXT_FUNC) \
148 ; do \
149 sed "s/ .*_init/ _init/" extensions/ebt_$${arg}.c > extensions/ebt_$${arg}.c_ ; \
150 mv extensions/ebt_$${arg}.c_ extensions/ebt_$${arg}.c ; \
151 done ; \
152 for arg in $(EXT_TABLES) \
153 ; do \
154 sed "s/ .*_init/ _init/" extensions/ebtable_$${arg}.c > extensions/ebtable_$${arg}.c_ ; \
155 mv extensions/ebtable_$${arg}.c_ extensions/ebtable_$${arg}.c ; \
156 done ; \
157 mv ebtables-standalone.c_ ebtables-standalone.c ; \
158 mv include/ebtables_u.h_ include/ebtables_u.h
159
Bart De Schuymer50441e92005-08-30 21:20:55 +0000160tmp1:=$(shell printf $(BINDIR) | sed 's/\//\\\//g')
161tmp2:=$(shell printf $(SYSCONFIGDIR) | sed 's/\//\\\//g')
Bart De Schuymerdb97ab22005-09-01 20:37:07 +0000162tmp3:=$(shell printf $(PIPE) | sed 's/\//\\\//g')
Bart De Schuymer50441e92005-08-30 21:20:55 +0000163.PHONY: scripts
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000164scripts: ebtables-save ebtables.sysv ebtables-config
Bart De Schuymer50441e92005-08-30 21:20:55 +0000165 cat ebtables-save | sed 's/__EXEC_PATH__/$(tmp1)/g' > ebtables-save_
166 install -m 0755 -o root -g root ebtables-save_ $(BINDIR)/ebtables-save
Bart De Schuymerdb97ab22005-09-01 20:37:07 +0000167 cat ebtables.sysv | sed 's/__EXEC_PATH__/$(tmp1)/g' | sed 's/__SYSCONFIG__/$(tmp2)/g' > ebtables.sysv_
Bart De Schuymer50441e92005-08-30 21:20:55 +0000168 install -m 0755 -o root -g root ebtables.sysv_ $(INITDIR)/ebtables
Bart De Schuymer9336b5a2005-11-04 22:01:23 +0000169 cat ebtables-config | sed 's/__SYSCONFIG__/$(tmp2)/g' > ebtables-config_
Bart De Schuymer50441e92005-08-30 21:20:55 +0000170 install -m 0600 -o root -g root ebtables-config_ $(SYSCONFIGDIR)/ebtables-config
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000171 rm -f ebtables-save_ ebtables.sysv_ ebtables-config_
Bart De Schuymer50441e92005-08-30 21:20:55 +0000172
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000173$(MANDIR)/man8/ebtables.8: ebtables.8
174 mkdir -p $(@D)
Bart De Schuymer1cda4be2006-12-17 20:05:02 +0000175 sed 's/$$(VERSION)/$(PROGVERSION)/' ebtables.8 | sed 's/$$(DATE)/$(PROGDATE)/' > ebtables.8_
Bart De Schuymer865dd4d2006-12-15 11:37:07 +0000176 install -m 0644 -o root -g root ebtables.8_ $@
177 rm -f ebtables.8_
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000178
Bart De Schuymer2eb1f922002-11-22 18:55:55 +0000179$(ETHERTYPESFILE): ethertypes
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000180 mkdir -p $(@D)
181 install -m 0644 -o root -g root $< $@
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000182
Bart De Schuymer32890542002-07-10 20:09:56 +0000183.PHONY: exec
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000184exec: ebtables ebtables-restore
Bart De Schuymer3749f302004-02-11 21:23:38 +0000185 mkdir -p $(BINDIR)
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000186 install -m 0755 -o root -g root $(PROGNAME) $(BINDIR)/$(PROGNAME)
187 install -m 0755 -o root -g root ebtables-restore $(BINDIR)/ebtables-restore
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000188
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000189.PHONY: install
Bart De Schuymer50441e92005-08-30 21:20:55 +0000190install: $(MANDIR)/man8/ebtables.8 $(ETHERTYPESFILE) exec scripts
Bart De Schuymer0f5e3fe2004-02-10 18:08:00 +0000191 mkdir -p $(LIBDIR)
Bart De Schuymer64182a32004-01-21 20:39:54 +0000192 install -m 0755 extensions/*.so $(LIBDIR)
193 install -m 0755 *.so $(LIBDIR)
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000194
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000195.PHONY: clean
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000196clean:
Bart De Schuymer7d9e3eb2006-02-06 21:24:02 +0000197 rm -f ebtables ebtables-restore ebtablesd ebtablesu static
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000198 rm -f *.o *~ *.so
Bart De Schuymer96ee8d12005-11-04 21:59:57 +0000199 rm -f extensions/*.o extensions/*.c~ extensions/*.so include/*~
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000200
201DIR:=$(PROGNAME)-v$(PROGVERSION)
Bart De Schuymer22d8f5f2007-05-28 16:45:38 +0000202CVSDIRS:=CVS extensions/CVS examples/CVS examples/perf_test/CVS \
203examples/ulog/CVS include/CVS
Bart De Schuymer865dd4d2006-12-15 11:37:07 +0000204# This is used to make a new userspace release, some files are altered so
205# do this on a temporary version
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000206.PHONY: release
207release:
Bart De Schuymer22d8f5f2007-05-28 16:45:38 +0000208 rm -f extensions/ebt_inat.c
209 rm -rf $(CVSDIRS)
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000210 mkdir -p include/linux/netfilter_bridge
211 install -m 0644 -o root -g root \
212 $(KERNEL_INCLUDES)/linux/netfilter_bridge.h include/linux/
213# To keep possible compile error complaints about undefined ETH_P_8021Q
214# off my back
215 install -m 0644 -o root -g root \
216 $(KERNEL_INCLUDES)/linux/if_ether.h include/linux/
217 install -m 0644 -o root -g root \
Bart De Schuymer72ecebe2006-12-17 21:29:34 +0000218 $(KERNEL_INCLUDES)/linux/types.h include/linux/
219 install -m 0644 -o root -g root \
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000220 $(KERNEL_INCLUDES)/linux/netfilter_bridge/*.h \
221 include/linux/netfilter_bridge/
Bart De Schuymer60c20092003-07-23 21:34:21 +0000222 install -m 0644 -o root -g root \
223 include/ebtables.h include/linux/netfilter_bridge/
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000224 make clean
Bart De Schuymere29506d2003-07-26 11:53:32 +0000225 touch *
226 touch extensions/*
227 touch include/*
228 touch include/linux/*
229 touch include/linux/netfilter_bridge/*
Bart De Schuymer865dd4d2006-12-15 11:37:07 +0000230 sed -i 's/$$(VERSION)/$(PROGVERSION)/' ebtables.8
231 sed -i 's/$$(DATE)/$(PROGDATE)/' ebtables.8
Bart De Schuymer22d8f5f2007-05-28 16:45:38 +0000232 sed -i 's/$$(VERSION)/$(PROGVERSION_)/' ebtables.spec
Bart De Schuymer865dd4d2006-12-15 11:37:07 +0000233 sed -i 's/$$(RELEASE)/$(PROGRELEASE)/' ebtables.spec
Bart De Schuymer308ea9f2005-11-13 12:15:09 +0000234 cd ..;tar -c $(DIR) | gzip >$(DIR).tar.gz; cd -
235 rm -rf include/linux
236
237# This will make the rpm and put it in /usr/src/redhat/RPMS
238# (do this as root after make release)
239.PHONY: rpmbuild
240rpmbuild:
241 cp ../$(DIR).tar.gz /usr/src/redhat/SOURCES/
Bart De Schuymer58acf952005-11-13 12:23:13 +0000242 rpmbuild --buildroot $(shell mktemp -td $(DIR)-XXXXX) -bb ebtables.spec
Bart De Schuymer8bde1012004-11-20 13:00:52 +0000243
244.PHONY: test_ulog
245test_ulog: examples/ulog/test_ulog.c getethertype.o
246 $(CC) $(CFLAGS) $< -o test_ulog -I$(KERNEL_INCLUDES) -lc \
247 getethertype.o
248 mv test_ulog examples/ulog/
249
250.PHONY: examples
251examples: test_ulog