blob: 7e149a1b25de7b4bcd7f407f68132f93c9a6a71b [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 Schuymerf9ebb5e2010-02-03 21:13:27 +00004PROGRELEASE:=2
Bart De Schuymer7ae403b2009-06-21 13:13:02 +00005PROGVERSION_:=2.0.9
Bart De Schuymer865dd4d2006-12-15 11:37:07 +00006PROGVERSION:=$(PROGVERSION_)-$(PROGRELEASE)
Bart De Schuymer7ae403b2009-06-21 13:13:02 +00007PROGDATE:=June\ 2009
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
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000018CFLAGS:=-Wall -Wunused
Bart De Schuymer17c60f52006-12-14 18:55:44 +000019CFLAGS_SH_LIB:=-fPIC
Bart De Schuymer06a1b462002-09-07 11:51:13 +000020CC:=gcc
Bart De Schuymer64182a32004-01-21 20:39:54 +000021LD:=ld
Bart De Schuymer3c1e00c2002-12-07 11:18:57 +000022
Bart De Schuymer60c20092003-07-23 21:34:21 +000023ifeq ($(shell uname -m),sparc64)
24CFLAGS+=-DEBT_MIN_ALIGN=8 -DKERNEL_64_USERSPACE_32
25endif
26
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000027include extensions/Makefile
28
Bart De Schuymer64182a32004-01-21 20:39:54 +000029OBJECTS2:=getethertype.o communication.o libebtc.o \
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000030useful_functions.o ebtables.o
Bart De Schuymer64182a32004-01-21 20:39:54 +000031
Bart De Schuymer7d9e3eb2006-02-06 21:24:02 +000032OBJECTS:=$(OBJECTS2) $(EXT_OBJS) $(EXT_LIBS)
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000033
Bart De Schuymer06a96822003-02-19 20:09:51 +000034KERNEL_INCLUDES?=include/
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000035
Bart De Schuymer3749f302004-02-11 21:23:38 +000036ETHERTYPESPATH?=$(ETCDIR)
Bart De Schuymera2960382003-04-01 17:29:13 +000037ETHERTYPESFILE:=$(ETHERTYPESPATH)/ethertypes
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000038
Bart De Schuymer0ddd5752007-08-12 15:11:40 +000039PIPE_DIR?=/tmp/$(PROGNAME)-v$(PROGVERSION)
Bart De Schuymer6622a012005-01-19 21:09:05 +000040PIPE=$(PIPE_DIR)/ebtablesd_pipe
41EBTD_CMDLINE_MAXLN?=2048
42EBTD_ARGC_MAX?=50
43
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000044PROGSPECS:=-DPROGVERSION=\"$(PROGVERSION)\" \
45 -DPROGNAME=\"$(PROGNAME)\" \
46 -DPROGDATE=\"$(PROGDATE)\" \
Bart De Schuymer9d680cc2005-10-01 09:16:51 +000047 -D_PATH_ETHERTYPES=\"$(ETHERTYPESFILE)\" \
48 -DEBTD_ARGC_MAX=$(EBTD_ARGC_MAX) \
49 -DEBTD_CMDLINE_MAXLN=$(EBTD_CMDLINE_MAXLN)
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000050
Bart De Schuymer96ee8d12005-11-04 21:59:57 +000051# You can probably ignore this, ebtables{u,d} are normally not used
Bart De Schuymer6622a012005-01-19 21:09:05 +000052PROGSPECSD:=-DPROGVERSION=\"$(PROGVERSION)\" \
53 -DPROGNAME=\"$(PROGNAME)\" \
54 -DPROGDATE=\"$(PROGDATE)\" \
55 -D_PATH_ETHERTYPES=\"$(ETHERTYPESFILE)\" \
56 -DEBTD_CMDLINE_MAXLN=$(EBTD_CMDLINE_MAXLN) \
57 -DEBTD_ARGC_MAX=$(EBTD_ARGC_MAX) \
58 -DEBTD_PIPE=\"$(PIPE)\" \
59 -DEBTD_PIPE_DIR=\"$(PIPE_DIR)\"
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000060
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000061# Uncomment for debugging (slower)
62#PROGSPECS+=-DEBT_DEBUG
63#PROGSPECSD+=-DEBT_DEBUG
Bart De Schuymer96ee8d12005-11-04 21:59:57 +000064#CFLAGS+=-ggdb
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000065
Bart De Schuymer96ee8d12005-11-04 21:59:57 +000066all: ebtables ebtables-restore
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000067
68communication.o: communication.c include/ebtables_u.h
Bart De Schuymer17c60f52006-12-14 18:55:44 +000069 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES)
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000070
Bart De Schuymer8339ff12004-01-14 20:05:27 +000071libebtc.o: libebtc.c include/ebtables_u.h
Bart De Schuymer17c60f52006-12-14 18:55:44 +000072 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES)
Bart De Schuymer8339ff12004-01-14 20:05:27 +000073
74useful_functions.o: useful_functions.c include/ebtables_u.h
Bart De Schuymer17c60f52006-12-14 18:55:44 +000075 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES)
Bart De Schuymer8339ff12004-01-14 20:05:27 +000076
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000077getethertype.o: getethertype.c include/ethernetdb.h
Bart De Schuymer17c60f52006-12-14 18:55:44 +000078 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -Iinclude/
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000079
80ebtables.o: ebtables.c include/ebtables_u.h
Bart De Schuymereacf5c92007-07-03 17:48:53 +000081 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES)
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000082
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000083ebtables-standalone.o: ebtables-standalone.c include/ebtables_u.h
Bart De Schuymereacf5c92007-07-03 17:48:53 +000084 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c $< -o $@ -I$(KERNEL_INCLUDES)
Bart De Schuymer6622a012005-01-19 21:09:05 +000085
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000086.PHONY: libebtc
87libebtc: $(OBJECTS2)
Bart De Schuymer147ebcd2009-09-24 18:05:23 +000088 $(CC) -shared -Wl,-soname,libebtc.so -o libebtc.so -lc $(OBJECTS2)
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000089
90ebtables: $(OBJECTS) ebtables-standalone.o libebtc
Bart De Schuymere1c315a2006-12-22 18:08:41 +000091 $(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 +000092 -Wl,-rpath,$(LIBDIR)
Bart De Schuymer6622a012005-01-19 21:09:05 +000093
94ebtablesu: ebtablesu.c
95 $(CC) $(CFLAGS) $(PROGSPECSD) $< -o $@
96
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000097ebtablesd.o: ebtablesd.c include/ebtables_u.h
98 $(CC) $(CFLAGS) $(PROGSPECSD) -c $< -o $@ -I$(KERNEL_INCLUDES)
Bart De Schuymer6622a012005-01-19 21:09:05 +000099
Bart De Schuymer838fa5b2005-06-18 14:43:32 +0000100ebtablesd: $(OBJECTS) ebtablesd.o libebtc
101 $(CC) $(CFLAGS) -o $@ ebtablesd.o -I$(KERNEL_INCLUDES) -L. -Lextensions -lebtc $(EXT_LIBSI) \
102 -Wl,-rpath,$(LIBDIR)
Bart De Schuymer6622a012005-01-19 21:09:05 +0000103
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000104ebtables-restore.o: ebtables-restore.c include/ebtables_u.h
Bart De Schuymer9d680cc2005-10-01 09:16:51 +0000105 $(CC) $(CFLAGS) $(PROGSPECS) -c $< -o $@ -I$(KERNEL_INCLUDES)
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000106
107ebtables-restore: $(OBJECTS) ebtables-restore.o libebtc
108 $(CC) $(CFLAGS) -o $@ ebtables-restore.o -I$(KERNEL_INCLUDES) -L. -Lextensions -lebtc $(EXT_LIBSI) \
109 -Wl,-rpath,$(LIBDIR)
110
Bart De Schuymer6622a012005-01-19 21:09:05 +0000111.PHONY: daemon
112daemon: ebtablesd ebtablesu
113
Bart De Schuymer7d9e3eb2006-02-06 21:24:02 +0000114# a little scripting for a static binary, making one for ebtables-restore
115# should be completely analogous
116static: extensions/ebt_*.c extensions/ebtable_*.c ebtables.c communication.c ebtables-standalone.c getethertype.c libebtc.c useful_functions.c
117 cp ebtables-standalone.c ebtables-standalone.c_ ; \
118 cp include/ebtables_u.h include/ebtables_u.h_ ; \
119 sed "s/ main(/ pseudomain(/" ebtables-standalone.c > ebtables-standalone.c__ ; \
120 mv ebtables-standalone.c__ ebtables-standalone.c ; \
121 printf "\nint main(int argc, char *argv[])\n{\n " >> ebtables-standalone.c ; \
122 for arg in $(EXT_FUNC) \
123 ; do \
124 sed s/_init/_$${arg}_init/ extensions/ebt_$${arg}.c > extensions/ebt_$${arg}.c_ ; \
125 mv extensions/ebt_$${arg}.c_ extensions/ebt_$${arg}.c ; \
126 printf "\t%s();\n" _$${arg}_init >> ebtables-standalone.c ; \
127 printf "extern void %s();\n" _$${arg}_init >> include/ebtables_u.h ; \
128 done ; \
129 for arg in $(EXT_TABLES) \
130 ; do \
131 sed s/_init/_t_$${arg}_init/ extensions/ebtable_$${arg}.c > extensions/ebtable_$${arg}.c_ ; \
132 mv extensions/ebtable_$${arg}.c_ extensions/ebtable_$${arg}.c ; \
133 printf "\t%s();\n" _t_$${arg}_init >> ebtables-standalone.c ; \
134 printf "extern void %s();\n" _t_$${arg}_init >> include/ebtables_u.h ; \
135 done ; \
136 printf "\n\tpseudomain(argc, argv);\n\treturn 0;\n}\n" >> ebtables-standalone.c ;\
Bart De Schuymerdc5d9fc2006-08-09 10:28:14 +0000137 $(CC) $(CFLAGS) $(PROGSPECS) -o $@ $^ -I$(KERNEL_INCLUDES) -Iinclude ; \
Bart De Schuymer7d9e3eb2006-02-06 21:24:02 +0000138 for arg in $(EXT_FUNC) \
139 ; do \
140 sed "s/ .*_init/ _init/" extensions/ebt_$${arg}.c > extensions/ebt_$${arg}.c_ ; \
141 mv extensions/ebt_$${arg}.c_ extensions/ebt_$${arg}.c ; \
142 done ; \
143 for arg in $(EXT_TABLES) \
144 ; do \
145 sed "s/ .*_init/ _init/" extensions/ebtable_$${arg}.c > extensions/ebtable_$${arg}.c_ ; \
146 mv extensions/ebtable_$${arg}.c_ extensions/ebtable_$${arg}.c ; \
147 done ; \
148 mv ebtables-standalone.c_ ebtables-standalone.c ; \
149 mv include/ebtables_u.h_ include/ebtables_u.h
150
Bart De Schuymer50441e92005-08-30 21:20:55 +0000151tmp1:=$(shell printf $(BINDIR) | sed 's/\//\\\//g')
152tmp2:=$(shell printf $(SYSCONFIGDIR) | sed 's/\//\\\//g')
Bart De Schuymerdb97ab22005-09-01 20:37:07 +0000153tmp3:=$(shell printf $(PIPE) | sed 's/\//\\\//g')
Bart De Schuymer50441e92005-08-30 21:20:55 +0000154.PHONY: scripts
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000155scripts: ebtables-save ebtables.sysv ebtables-config
Bart De Schuymer50441e92005-08-30 21:20:55 +0000156 cat ebtables-save | sed 's/__EXEC_PATH__/$(tmp1)/g' > ebtables-save_
Bart De Schuymer0ddd5752007-08-12 15:11:40 +0000157 install -m 0755 -o root -g root ebtables-save_ $(DESTDIR)$(BINDIR)/ebtables-save
Bart De Schuymerdb97ab22005-09-01 20:37:07 +0000158 cat ebtables.sysv | sed 's/__EXEC_PATH__/$(tmp1)/g' | sed 's/__SYSCONFIG__/$(tmp2)/g' > ebtables.sysv_
Bart De Schuymer0ddd5752007-08-12 15:11:40 +0000159 install -m 0755 -o root -g root ebtables.sysv_ $(DESTDIR)$(INITDIR)/ebtables
Bart De Schuymer9336b5a2005-11-04 22:01:23 +0000160 cat ebtables-config | sed 's/__SYSCONFIG__/$(tmp2)/g' > ebtables-config_
Bart De Schuymer0ddd5752007-08-12 15:11:40 +0000161 install -m 0600 -o root -g root ebtables-config_ $(DESTDIR)$(SYSCONFIGDIR)/ebtables-config
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000162 rm -f ebtables-save_ ebtables.sysv_ ebtables-config_
Bart De Schuymer50441e92005-08-30 21:20:55 +0000163
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000164$(MANDIR)/man8/ebtables.8: ebtables.8
Bart De Schuymer0ddd5752007-08-12 15:11:40 +0000165 mkdir -p $(DESTDIR)$(@D)
Bart De Schuymer1cda4be2006-12-17 20:05:02 +0000166 sed 's/$$(VERSION)/$(PROGVERSION)/' ebtables.8 | sed 's/$$(DATE)/$(PROGDATE)/' > ebtables.8_
Bart De Schuymer0ddd5752007-08-12 15:11:40 +0000167 install -m 0644 -o root -g root ebtables.8_ $(DESTDIR)$@
Bart De Schuymer865dd4d2006-12-15 11:37:07 +0000168 rm -f ebtables.8_
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000169
Bart De Schuymer2eb1f922002-11-22 18:55:55 +0000170$(ETHERTYPESFILE): ethertypes
Bart De Schuymer0ddd5752007-08-12 15:11:40 +0000171 mkdir -p $(DESTDIR)$(@D)
172 install -m 0644 -o root -g root $< $(DESTDIR)$@
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000173
Bart De Schuymer32890542002-07-10 20:09:56 +0000174.PHONY: exec
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000175exec: ebtables ebtables-restore
Bart De Schuymer0ddd5752007-08-12 15:11:40 +0000176 mkdir -p $(DESTDIR)$(BINDIR)
177 install -m 0755 -o root -g root $(PROGNAME) $(DESTDIR)$(BINDIR)/$(PROGNAME)
178 install -m 0755 -o root -g root ebtables-restore $(DESTDIR)$(BINDIR)/ebtables-restore
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000179
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000180.PHONY: install
Bart De Schuymer50441e92005-08-30 21:20:55 +0000181install: $(MANDIR)/man8/ebtables.8 $(ETHERTYPESFILE) exec scripts
Bart De Schuymer0ddd5752007-08-12 15:11:40 +0000182 mkdir -p $(DESTDIR)$(LIBDIR)
183 install -m 0755 extensions/*.so $(DESTDIR)$(LIBDIR)
184 install -m 0755 *.so $(DESTDIR)$(LIBDIR)
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000185
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000186.PHONY: clean
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000187clean:
Bart De Schuymer7d9e3eb2006-02-06 21:24:02 +0000188 rm -f ebtables ebtables-restore ebtablesd ebtablesu static
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000189 rm -f *.o *~ *.so
Bart De Schuymer96ee8d12005-11-04 21:59:57 +0000190 rm -f extensions/*.o extensions/*.c~ extensions/*.so include/*~
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000191
192DIR:=$(PROGNAME)-v$(PROGVERSION)
Bart De Schuymer22d8f5f2007-05-28 16:45:38 +0000193CVSDIRS:=CVS extensions/CVS examples/CVS examples/perf_test/CVS \
194examples/ulog/CVS include/CVS
Bart De Schuymer865dd4d2006-12-15 11:37:07 +0000195# This is used to make a new userspace release, some files are altered so
196# do this on a temporary version
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000197.PHONY: release
198release:
Bart De Schuymer22d8f5f2007-05-28 16:45:38 +0000199 rm -f extensions/ebt_inat.c
200 rm -rf $(CVSDIRS)
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000201 mkdir -p include/linux/netfilter_bridge
202 install -m 0644 -o root -g root \
203 $(KERNEL_INCLUDES)/linux/netfilter_bridge.h include/linux/
204# To keep possible compile error complaints about undefined ETH_P_8021Q
205# off my back
206 install -m 0644 -o root -g root \
207 $(KERNEL_INCLUDES)/linux/if_ether.h include/linux/
208 install -m 0644 -o root -g root \
Bart De Schuymer72ecebe2006-12-17 21:29:34 +0000209 $(KERNEL_INCLUDES)/linux/types.h include/linux/
210 install -m 0644 -o root -g root \
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000211 $(KERNEL_INCLUDES)/linux/netfilter_bridge/*.h \
212 include/linux/netfilter_bridge/
Bart De Schuymer60c20092003-07-23 21:34:21 +0000213 install -m 0644 -o root -g root \
214 include/ebtables.h include/linux/netfilter_bridge/
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000215 make clean
Bart De Schuymere29506d2003-07-26 11:53:32 +0000216 touch *
217 touch extensions/*
218 touch include/*
219 touch include/linux/*
220 touch include/linux/netfilter_bridge/*
Bart De Schuymer865dd4d2006-12-15 11:37:07 +0000221 sed -i 's/$$(VERSION)/$(PROGVERSION)/' ebtables.8
222 sed -i 's/$$(DATE)/$(PROGDATE)/' ebtables.8
Bart De Schuymer22d8f5f2007-05-28 16:45:38 +0000223 sed -i 's/$$(VERSION)/$(PROGVERSION_)/' ebtables.spec
Bart De Schuymer865dd4d2006-12-15 11:37:07 +0000224 sed -i 's/$$(RELEASE)/$(PROGRELEASE)/' ebtables.spec
Bart De Schuymer308ea9f2005-11-13 12:15:09 +0000225 cd ..;tar -c $(DIR) | gzip >$(DIR).tar.gz; cd -
226 rm -rf include/linux
227
228# This will make the rpm and put it in /usr/src/redhat/RPMS
229# (do this as root after make release)
230.PHONY: rpmbuild
231rpmbuild:
232 cp ../$(DIR).tar.gz /usr/src/redhat/SOURCES/
Bart De Schuymer58acf952005-11-13 12:23:13 +0000233 rpmbuild --buildroot $(shell mktemp -td $(DIR)-XXXXX) -bb ebtables.spec
Bart De Schuymer8bde1012004-11-20 13:00:52 +0000234
235.PHONY: test_ulog
236test_ulog: examples/ulog/test_ulog.c getethertype.o
237 $(CC) $(CFLAGS) $< -o test_ulog -I$(KERNEL_INCLUDES) -lc \
238 getethertype.o
239 mv test_ulog examples/ulog/
240
241.PHONY: examples
242examples: test_ulog