blob: 58bd53cb221fe142804cdb37c3186fbf0e426eb3 [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 Schuymer865dd4d2006-12-15 11:37:07 +00004PROGRELEASE:=rc3
5PROGVERSION_:=2.0.8
6ifneq (PROGRELEASE,)
7PROGVERSION:=$(PROGVERSION_)-$(PROGRELEASE)
8else
9PROGVERSION:=$(PROGVERSION_)
10endif
11PROGDATE:=December\ 2006
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000012
Bart De Schuymer3749f302004-02-11 21:23:38 +000013# default paths
Bart De Schuymer38561e92004-02-23 09:20:42 +000014LIBDIR:=/usr/lib
Bart De Schuymer3749f302004-02-11 21:23:38 +000015MANDIR:=/usr/local/man
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000016BINDIR:=/usr/local/sbin
Bart De Schuymer3749f302004-02-11 21:23:38 +000017ETCDIR:=/etc
Bart De Schuymer50441e92005-08-30 21:20:55 +000018INITDIR:=/etc/rc.d/init.d
19SYSCONFIGDIR:=/etc/sysconfig
Bart De Schuymer38561e92004-02-23 09:20:42 +000020DESTDIR:=
Bart De Schuymer3749f302004-02-11 21:23:38 +000021
22# include DESTDIR param
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000023override LIBDIR:=$(DESTDIR)$(LIBDIR)/$(PROGNAME)
Bart De Schuymer3749f302004-02-11 21:23:38 +000024override MANDIR:=$(DESTDIR)$(MANDIR)
25override BINDIR:=$(DESTDIR)$(BINDIR)
26override ETCDIR:=$(DESTDIR)$(ETCDIR)
Bart De Schuymer50441e92005-08-30 21:20:55 +000027override INITDIR:=$(DESTDIR)$(INITDIR)
28override SYSCONFIGDIR:=$(DESTDIR)$(SYSCONFIGDIR)
Bart De Schuymer3749f302004-02-11 21:23:38 +000029
30
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000031CFLAGS:=-Wall -Wunused
Bart De Schuymer17c60f52006-12-14 18:55:44 +000032CFLAGS_SH_LIB:=-fPIC
Bart De Schuymer06a1b462002-09-07 11:51:13 +000033CC:=gcc
Bart De Schuymer64182a32004-01-21 20:39:54 +000034LD:=ld
Bart De Schuymer3c1e00c2002-12-07 11:18:57 +000035
Bart De Schuymer60c20092003-07-23 21:34:21 +000036ifeq ($(shell uname -m),sparc64)
37CFLAGS+=-DEBT_MIN_ALIGN=8 -DKERNEL_64_USERSPACE_32
38endif
39
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000040include extensions/Makefile
41
Bart De Schuymer64182a32004-01-21 20:39:54 +000042OBJECTS2:=getethertype.o communication.o libebtc.o \
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000043useful_functions.o ebtables.o
Bart De Schuymer64182a32004-01-21 20:39:54 +000044
Bart De Schuymer7d9e3eb2006-02-06 21:24:02 +000045OBJECTS:=$(OBJECTS2) $(EXT_OBJS) $(EXT_LIBS)
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000046
Bart De Schuymer06a96822003-02-19 20:09:51 +000047KERNEL_INCLUDES?=include/
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000048
Bart De Schuymer3749f302004-02-11 21:23:38 +000049ETHERTYPESPATH?=$(ETCDIR)
Bart De Schuymera2960382003-04-01 17:29:13 +000050ETHERTYPESFILE:=$(ETHERTYPESPATH)/ethertypes
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000051
Bart De Schuymer50441e92005-08-30 21:20:55 +000052PIPE_DIR?=$(DESTDIR)/tmp/$(PROGNAME)-v$(PROGVERSION)
Bart De Schuymer6622a012005-01-19 21:09:05 +000053PIPE=$(PIPE_DIR)/ebtablesd_pipe
54EBTD_CMDLINE_MAXLN?=2048
55EBTD_ARGC_MAX?=50
56
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000057PROGSPECS:=-DPROGVERSION=\"$(PROGVERSION)\" \
58 -DPROGNAME=\"$(PROGNAME)\" \
59 -DPROGDATE=\"$(PROGDATE)\" \
Bart De Schuymer9d680cc2005-10-01 09:16:51 +000060 -D_PATH_ETHERTYPES=\"$(ETHERTYPESFILE)\" \
61 -DEBTD_ARGC_MAX=$(EBTD_ARGC_MAX) \
62 -DEBTD_CMDLINE_MAXLN=$(EBTD_CMDLINE_MAXLN)
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000063
Bart De Schuymer96ee8d12005-11-04 21:59:57 +000064# You can probably ignore this, ebtables{u,d} are normally not used
Bart De Schuymer6622a012005-01-19 21:09:05 +000065PROGSPECSD:=-DPROGVERSION=\"$(PROGVERSION)\" \
66 -DPROGNAME=\"$(PROGNAME)\" \
67 -DPROGDATE=\"$(PROGDATE)\" \
68 -D_PATH_ETHERTYPES=\"$(ETHERTYPESFILE)\" \
69 -DEBTD_CMDLINE_MAXLN=$(EBTD_CMDLINE_MAXLN) \
70 -DEBTD_ARGC_MAX=$(EBTD_ARGC_MAX) \
71 -DEBTD_PIPE=\"$(PIPE)\" \
72 -DEBTD_PIPE_DIR=\"$(PIPE_DIR)\"
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000073
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000074# Uncomment for debugging (slower)
75#PROGSPECS+=-DEBT_DEBUG
76#PROGSPECSD+=-DEBT_DEBUG
Bart De Schuymer96ee8d12005-11-04 21:59:57 +000077#CFLAGS+=-ggdb
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000078
Bart De Schuymer96ee8d12005-11-04 21:59:57 +000079all: ebtables ebtables-restore
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000080
81communication.o: communication.c include/ebtables_u.h
Bart De Schuymer17c60f52006-12-14 18:55:44 +000082 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES)
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000083
Bart De Schuymer8339ff12004-01-14 20:05:27 +000084libebtc.o: libebtc.c include/ebtables_u.h
Bart De Schuymer17c60f52006-12-14 18:55:44 +000085 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES)
Bart De Schuymer8339ff12004-01-14 20:05:27 +000086
87useful_functions.o: useful_functions.c include/ebtables_u.h
Bart De Schuymer17c60f52006-12-14 18:55:44 +000088 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES)
Bart De Schuymer8339ff12004-01-14 20:05:27 +000089
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000090getethertype.o: getethertype.c include/ethernetdb.h
Bart De Schuymer17c60f52006-12-14 18:55:44 +000091 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -Iinclude/
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000092
93ebtables.o: ebtables.c include/ebtables_u.h
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000094 $(CC) $(CFLAGS) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES)
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000095
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000096ebtables-standalone.o: ebtables-standalone.c include/ebtables_u.h
97 $(CC) $(CFLAGS) $(PROGSPECS) -c $< -o $@ -I$(KERNEL_INCLUDES)
Bart De Schuymer6622a012005-01-19 21:09:05 +000098
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000099.PHONY: libebtc
100libebtc: $(OBJECTS2)
Bart De Schuymere1c15882004-05-24 19:57:58 +0000101 $(LD) -shared -soname libebtc.so -o libebtc.so -lc $(OBJECTS2)
Bart De Schuymer838fa5b2005-06-18 14:43:32 +0000102
103ebtables: $(OBJECTS) ebtables-standalone.o libebtc
104 $(CC) $(CFLAGS) -o $@ ebtables-standalone.o -I$(KERNEL_INCLUDES) -L. -Lextensions -lebtc $(EXT_LIBSI) \
105 -Wl,-rpath,$(LIBDIR)
Bart De Schuymer6622a012005-01-19 21:09:05 +0000106
107ebtablesu: ebtablesu.c
108 $(CC) $(CFLAGS) $(PROGSPECSD) $< -o $@
109
Bart De Schuymer838fa5b2005-06-18 14:43:32 +0000110ebtablesd.o: ebtablesd.c include/ebtables_u.h
111 $(CC) $(CFLAGS) $(PROGSPECSD) -c $< -o $@ -I$(KERNEL_INCLUDES)
Bart De Schuymer6622a012005-01-19 21:09:05 +0000112
Bart De Schuymer838fa5b2005-06-18 14:43:32 +0000113ebtablesd: $(OBJECTS) ebtablesd.o libebtc
114 $(CC) $(CFLAGS) -o $@ ebtablesd.o -I$(KERNEL_INCLUDES) -L. -Lextensions -lebtc $(EXT_LIBSI) \
115 -Wl,-rpath,$(LIBDIR)
Bart De Schuymer6622a012005-01-19 21:09:05 +0000116
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000117ebtables-restore.o: ebtables-restore.c include/ebtables_u.h
Bart De Schuymer9d680cc2005-10-01 09:16:51 +0000118 $(CC) $(CFLAGS) $(PROGSPECS) -c $< -o $@ -I$(KERNEL_INCLUDES)
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000119
120ebtables-restore: $(OBJECTS) ebtables-restore.o libebtc
121 $(CC) $(CFLAGS) -o $@ ebtables-restore.o -I$(KERNEL_INCLUDES) -L. -Lextensions -lebtc $(EXT_LIBSI) \
122 -Wl,-rpath,$(LIBDIR)
123
Bart De Schuymer6622a012005-01-19 21:09:05 +0000124.PHONY: daemon
125daemon: ebtablesd ebtablesu
126
Bart De Schuymer7d9e3eb2006-02-06 21:24:02 +0000127# a little scripting for a static binary, making one for ebtables-restore
128# should be completely analogous
129static: extensions/ebt_*.c extensions/ebtable_*.c ebtables.c communication.c ebtables-standalone.c getethertype.c libebtc.c useful_functions.c
130 cp ebtables-standalone.c ebtables-standalone.c_ ; \
131 cp include/ebtables_u.h include/ebtables_u.h_ ; \
132 sed "s/ main(/ pseudomain(/" ebtables-standalone.c > ebtables-standalone.c__ ; \
133 mv ebtables-standalone.c__ ebtables-standalone.c ; \
134 printf "\nint main(int argc, char *argv[])\n{\n " >> ebtables-standalone.c ; \
135 for arg in $(EXT_FUNC) \
136 ; do \
137 sed s/_init/_$${arg}_init/ extensions/ebt_$${arg}.c > extensions/ebt_$${arg}.c_ ; \
138 mv extensions/ebt_$${arg}.c_ extensions/ebt_$${arg}.c ; \
139 printf "\t%s();\n" _$${arg}_init >> ebtables-standalone.c ; \
140 printf "extern void %s();\n" _$${arg}_init >> include/ebtables_u.h ; \
141 done ; \
142 for arg in $(EXT_TABLES) \
143 ; do \
144 sed s/_init/_t_$${arg}_init/ extensions/ebtable_$${arg}.c > extensions/ebtable_$${arg}.c_ ; \
145 mv extensions/ebtable_$${arg}.c_ extensions/ebtable_$${arg}.c ; \
146 printf "\t%s();\n" _t_$${arg}_init >> ebtables-standalone.c ; \
147 printf "extern void %s();\n" _t_$${arg}_init >> include/ebtables_u.h ; \
148 done ; \
149 printf "\n\tpseudomain(argc, argv);\n\treturn 0;\n}\n" >> ebtables-standalone.c ;\
Bart De Schuymerdc5d9fc2006-08-09 10:28:14 +0000150 $(CC) $(CFLAGS) $(PROGSPECS) -o $@ $^ -I$(KERNEL_INCLUDES) -Iinclude ; \
Bart De Schuymer7d9e3eb2006-02-06 21:24:02 +0000151 for arg in $(EXT_FUNC) \
152 ; do \
153 sed "s/ .*_init/ _init/" extensions/ebt_$${arg}.c > extensions/ebt_$${arg}.c_ ; \
154 mv extensions/ebt_$${arg}.c_ extensions/ebt_$${arg}.c ; \
155 done ; \
156 for arg in $(EXT_TABLES) \
157 ; do \
158 sed "s/ .*_init/ _init/" extensions/ebtable_$${arg}.c > extensions/ebtable_$${arg}.c_ ; \
159 mv extensions/ebtable_$${arg}.c_ extensions/ebtable_$${arg}.c ; \
160 done ; \
161 mv ebtables-standalone.c_ ebtables-standalone.c ; \
162 mv include/ebtables_u.h_ include/ebtables_u.h
163
Bart De Schuymer50441e92005-08-30 21:20:55 +0000164tmp1:=$(shell printf $(BINDIR) | sed 's/\//\\\//g')
165tmp2:=$(shell printf $(SYSCONFIGDIR) | sed 's/\//\\\//g')
Bart De Schuymerdb97ab22005-09-01 20:37:07 +0000166tmp3:=$(shell printf $(PIPE) | sed 's/\//\\\//g')
Bart De Schuymer50441e92005-08-30 21:20:55 +0000167.PHONY: scripts
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000168scripts: ebtables-save ebtables.sysv ebtables-config
Bart De Schuymer50441e92005-08-30 21:20:55 +0000169 cat ebtables-save | sed 's/__EXEC_PATH__/$(tmp1)/g' > ebtables-save_
170 install -m 0755 -o root -g root ebtables-save_ $(BINDIR)/ebtables-save
Bart De Schuymerdb97ab22005-09-01 20:37:07 +0000171 cat ebtables.sysv | sed 's/__EXEC_PATH__/$(tmp1)/g' | sed 's/__SYSCONFIG__/$(tmp2)/g' > ebtables.sysv_
Bart De Schuymer50441e92005-08-30 21:20:55 +0000172 install -m 0755 -o root -g root ebtables.sysv_ $(INITDIR)/ebtables
Bart De Schuymer9336b5a2005-11-04 22:01:23 +0000173 cat ebtables-config | sed 's/__SYSCONFIG__/$(tmp2)/g' > ebtables-config_
Bart De Schuymer50441e92005-08-30 21:20:55 +0000174 install -m 0600 -o root -g root ebtables-config_ $(SYSCONFIGDIR)/ebtables-config
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000175 rm -f ebtables-save_ ebtables.sysv_ ebtables-config_
Bart De Schuymer50441e92005-08-30 21:20:55 +0000176
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000177$(MANDIR)/man8/ebtables.8: ebtables.8
178 mkdir -p $(@D)
Bart De Schuymer865dd4d2006-12-15 11:37:07 +0000179 sed 's/$$(VERSION)/$(PROGVERSION)/' ebtables.8 | sed 's/$$(PROGDATE)/$(PROGDATE)/' > ebtables.8_
180 install -m 0644 -o root -g root ebtables.8_ $@
181 rm -f ebtables.8_
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000182
Bart De Schuymer2eb1f922002-11-22 18:55:55 +0000183$(ETHERTYPESFILE): ethertypes
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000184 mkdir -p $(@D)
185 install -m 0644 -o root -g root $< $@
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000186
Bart De Schuymer32890542002-07-10 20:09:56 +0000187.PHONY: exec
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000188exec: ebtables ebtables-restore
Bart De Schuymer3749f302004-02-11 21:23:38 +0000189 mkdir -p $(BINDIR)
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000190 install -m 0755 -o root -g root $(PROGNAME) $(BINDIR)/$(PROGNAME)
191 install -m 0755 -o root -g root ebtables-restore $(BINDIR)/ebtables-restore
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000192
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000193.PHONY: install
Bart De Schuymer50441e92005-08-30 21:20:55 +0000194install: $(MANDIR)/man8/ebtables.8 $(ETHERTYPESFILE) exec scripts
Bart De Schuymer0f5e3fe2004-02-10 18:08:00 +0000195 mkdir -p $(LIBDIR)
Bart De Schuymer64182a32004-01-21 20:39:54 +0000196 install -m 0755 extensions/*.so $(LIBDIR)
197 install -m 0755 *.so $(LIBDIR)
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000198
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000199.PHONY: clean
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000200clean:
Bart De Schuymer7d9e3eb2006-02-06 21:24:02 +0000201 rm -f ebtables ebtables-restore ebtablesd ebtablesu static
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000202 rm -f *.o *~ *.so
Bart De Schuymer96ee8d12005-11-04 21:59:57 +0000203 rm -f extensions/*.o extensions/*.c~ extensions/*.so include/*~
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000204
205DIR:=$(PROGNAME)-v$(PROGVERSION)
Bart De Schuymer865dd4d2006-12-15 11:37:07 +0000206# This is used to make a new userspace release, some files are altered so
207# do this on a temporary version
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000208.PHONY: release
209release:
210 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 \
218 $(KERNEL_INCLUDES)/linux/netfilter_bridge/*.h \
219 include/linux/netfilter_bridge/
Bart De Schuymer60c20092003-07-23 21:34:21 +0000220 install -m 0644 -o root -g root \
221 include/ebtables.h include/linux/netfilter_bridge/
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000222 make clean
Bart De Schuymere29506d2003-07-26 11:53:32 +0000223 touch *
224 touch extensions/*
225 touch include/*
226 touch include/linux/*
227 touch include/linux/netfilter_bridge/*
Bart De Schuymer865dd4d2006-12-15 11:37:07 +0000228 sed -i 's/$$(VERSION)/$(PROGVERSION)/' ebtables.8
229 sed -i 's/$$(DATE)/$(PROGDATE)/' ebtables.8
230 sed -i 's/$$(VERSION)/$(PROGVERSION_)/' ebtables.spec
231 sed -i 's/$$(RELEASE)/$(PROGRELEASE)/' ebtables.spec
Bart De Schuymer308ea9f2005-11-13 12:15:09 +0000232 cd ..;tar -c $(DIR) | gzip >$(DIR).tar.gz; cd -
233 rm -rf include/linux
234
235# This will make the rpm and put it in /usr/src/redhat/RPMS
236# (do this as root after make release)
237.PHONY: rpmbuild
238rpmbuild:
239 cp ../$(DIR).tar.gz /usr/src/redhat/SOURCES/
Bart De Schuymer58acf952005-11-13 12:23:13 +0000240 rpmbuild --buildroot $(shell mktemp -td $(DIR)-XXXXX) -bb ebtables.spec
Bart De Schuymer8bde1012004-11-20 13:00:52 +0000241
242.PHONY: test_ulog
243test_ulog: examples/ulog/test_ulog.c getethertype.o
244 $(CC) $(CFLAGS) $< -o test_ulog -I$(KERNEL_INCLUDES) -lc \
245 getethertype.o
246 mv test_ulog examples/ulog/
247
248.PHONY: examples
249examples: test_ulog