blob: 5103425ccb75832cae045934c50bfecfb8f739fd [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 Schuymer3c1e00c2002-12-07 11:18:57 +000021
Bart De Schuymer60c20092003-07-23 21:34:21 +000022ifeq ($(shell uname -m),sparc64)
23CFLAGS+=-DEBT_MIN_ALIGN=8 -DKERNEL_64_USERSPACE_32
24endif
25
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000026include extensions/Makefile
27
Bart De Schuymer64182a32004-01-21 20:39:54 +000028OBJECTS2:=getethertype.o communication.o libebtc.o \
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000029useful_functions.o ebtables.o
Bart De Schuymer64182a32004-01-21 20:39:54 +000030
Bart De Schuymer7d9e3eb2006-02-06 21:24:02 +000031OBJECTS:=$(OBJECTS2) $(EXT_OBJS) $(EXT_LIBS)
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000032
Bart De Schuymer06a96822003-02-19 20:09:51 +000033KERNEL_INCLUDES?=include/
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000034
Bart De Schuymer3749f302004-02-11 21:23:38 +000035ETHERTYPESPATH?=$(ETCDIR)
Bart De Schuymera2960382003-04-01 17:29:13 +000036ETHERTYPESFILE:=$(ETHERTYPESPATH)/ethertypes
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000037
Bart De Schuymer0ddd5752007-08-12 15:11:40 +000038PIPE_DIR?=/tmp/$(PROGNAME)-v$(PROGVERSION)
Bart De Schuymer6622a012005-01-19 21:09:05 +000039PIPE=$(PIPE_DIR)/ebtablesd_pipe
40EBTD_CMDLINE_MAXLN?=2048
41EBTD_ARGC_MAX?=50
42
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000043PROGSPECS:=-DPROGVERSION=\"$(PROGVERSION)\" \
44 -DPROGNAME=\"$(PROGNAME)\" \
45 -DPROGDATE=\"$(PROGDATE)\" \
Bart De Schuymer9d680cc2005-10-01 09:16:51 +000046 -D_PATH_ETHERTYPES=\"$(ETHERTYPESFILE)\" \
47 -DEBTD_ARGC_MAX=$(EBTD_ARGC_MAX) \
48 -DEBTD_CMDLINE_MAXLN=$(EBTD_CMDLINE_MAXLN)
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000049
Bart De Schuymer96ee8d12005-11-04 21:59:57 +000050# You can probably ignore this, ebtables{u,d} are normally not used
Bart De Schuymer6622a012005-01-19 21:09:05 +000051PROGSPECSD:=-DPROGVERSION=\"$(PROGVERSION)\" \
52 -DPROGNAME=\"$(PROGNAME)\" \
53 -DPROGDATE=\"$(PROGDATE)\" \
54 -D_PATH_ETHERTYPES=\"$(ETHERTYPESFILE)\" \
55 -DEBTD_CMDLINE_MAXLN=$(EBTD_CMDLINE_MAXLN) \
56 -DEBTD_ARGC_MAX=$(EBTD_ARGC_MAX) \
57 -DEBTD_PIPE=\"$(PIPE)\" \
58 -DEBTD_PIPE_DIR=\"$(PIPE_DIR)\"
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000059
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000060# Uncomment for debugging (slower)
61#PROGSPECS+=-DEBT_DEBUG
62#PROGSPECSD+=-DEBT_DEBUG
Bart De Schuymer96ee8d12005-11-04 21:59:57 +000063#CFLAGS+=-ggdb
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000064
Bart De Schuymer96ee8d12005-11-04 21:59:57 +000065all: ebtables ebtables-restore
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000066
67communication.o: communication.c include/ebtables_u.h
Bart De Schuymer17c60f52006-12-14 18:55:44 +000068 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES)
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000069
Bart De Schuymer8339ff12004-01-14 20:05:27 +000070libebtc.o: libebtc.c include/ebtables_u.h
Bart De Schuymer17c60f52006-12-14 18:55:44 +000071 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES)
Bart De Schuymer8339ff12004-01-14 20:05:27 +000072
73useful_functions.o: useful_functions.c include/ebtables_u.h
Bart De Schuymer17c60f52006-12-14 18:55:44 +000074 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES)
Bart De Schuymer8339ff12004-01-14 20:05:27 +000075
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000076getethertype.o: getethertype.c include/ethernetdb.h
Bart De Schuymer17c60f52006-12-14 18:55:44 +000077 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -Iinclude/
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000078
79ebtables.o: ebtables.c include/ebtables_u.h
Bart De Schuymereacf5c92007-07-03 17:48:53 +000080 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES)
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000081
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000082ebtables-standalone.o: ebtables-standalone.c include/ebtables_u.h
Bart De Schuymereacf5c92007-07-03 17:48:53 +000083 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c $< -o $@ -I$(KERNEL_INCLUDES)
Bart De Schuymer6622a012005-01-19 21:09:05 +000084
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000085.PHONY: libebtc
86libebtc: $(OBJECTS2)
Bart De Schuymer078161d2010-03-16 13:10:37 +000087 $(CC) -shared $(LDFLAGS) -Wl,-soname,libebtc.so -o libebtc.so -lc $(OBJECTS2)
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000088
89ebtables: $(OBJECTS) ebtables-standalone.o libebtc
Bart De Schuymer078161d2010-03-16 13:10:37 +000090 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(LDFLAGS) -o $@ ebtables-standalone.o -I$(KERNEL_INCLUDES) -L. -Lextensions -lebtc $(EXT_LIBSI) \
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000091 -Wl,-rpath,$(LIBDIR)
Bart De Schuymer6622a012005-01-19 21:09:05 +000092
93ebtablesu: ebtablesu.c
94 $(CC) $(CFLAGS) $(PROGSPECSD) $< -o $@
95
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000096ebtablesd.o: ebtablesd.c include/ebtables_u.h
97 $(CC) $(CFLAGS) $(PROGSPECSD) -c $< -o $@ -I$(KERNEL_INCLUDES)
Bart De Schuymer6622a012005-01-19 21:09:05 +000098
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000099ebtablesd: $(OBJECTS) ebtablesd.o libebtc
100 $(CC) $(CFLAGS) -o $@ ebtablesd.o -I$(KERNEL_INCLUDES) -L. -Lextensions -lebtc $(EXT_LIBSI) \
101 -Wl,-rpath,$(LIBDIR)
Bart De Schuymer6622a012005-01-19 21:09:05 +0000102
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000103ebtables-restore.o: ebtables-restore.c include/ebtables_u.h
Bart De Schuymer9d680cc2005-10-01 09:16:51 +0000104 $(CC) $(CFLAGS) $(PROGSPECS) -c $< -o $@ -I$(KERNEL_INCLUDES)
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000105
106ebtables-restore: $(OBJECTS) ebtables-restore.o libebtc
Bart De Schuymer078161d2010-03-16 13:10:37 +0000107 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ ebtables-restore.o -I$(KERNEL_INCLUDES) -L. -Lextensions -lebtc $(EXT_LIBSI) \
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000108 -Wl,-rpath,$(LIBDIR)
109
Bart De Schuymer6622a012005-01-19 21:09:05 +0000110.PHONY: daemon
111daemon: ebtablesd ebtablesu
112
Bart De Schuymer7d9e3eb2006-02-06 21:24:02 +0000113# a little scripting for a static binary, making one for ebtables-restore
114# should be completely analogous
115static: extensions/ebt_*.c extensions/ebtable_*.c ebtables.c communication.c ebtables-standalone.c getethertype.c libebtc.c useful_functions.c
116 cp ebtables-standalone.c ebtables-standalone.c_ ; \
117 cp include/ebtables_u.h include/ebtables_u.h_ ; \
118 sed "s/ main(/ pseudomain(/" ebtables-standalone.c > ebtables-standalone.c__ ; \
119 mv ebtables-standalone.c__ ebtables-standalone.c ; \
120 printf "\nint main(int argc, char *argv[])\n{\n " >> ebtables-standalone.c ; \
121 for arg in $(EXT_FUNC) \
122 ; do \
123 sed s/_init/_$${arg}_init/ extensions/ebt_$${arg}.c > extensions/ebt_$${arg}.c_ ; \
124 mv extensions/ebt_$${arg}.c_ extensions/ebt_$${arg}.c ; \
125 printf "\t%s();\n" _$${arg}_init >> ebtables-standalone.c ; \
126 printf "extern void %s();\n" _$${arg}_init >> include/ebtables_u.h ; \
127 done ; \
128 for arg in $(EXT_TABLES) \
129 ; do \
130 sed s/_init/_t_$${arg}_init/ extensions/ebtable_$${arg}.c > extensions/ebtable_$${arg}.c_ ; \
131 mv extensions/ebtable_$${arg}.c_ extensions/ebtable_$${arg}.c ; \
132 printf "\t%s();\n" _t_$${arg}_init >> ebtables-standalone.c ; \
133 printf "extern void %s();\n" _t_$${arg}_init >> include/ebtables_u.h ; \
134 done ; \
135 printf "\n\tpseudomain(argc, argv);\n\treturn 0;\n}\n" >> ebtables-standalone.c ;\
Bart De Schuymerdc5d9fc2006-08-09 10:28:14 +0000136 $(CC) $(CFLAGS) $(PROGSPECS) -o $@ $^ -I$(KERNEL_INCLUDES) -Iinclude ; \
Bart De Schuymer7d9e3eb2006-02-06 21:24:02 +0000137 for arg in $(EXT_FUNC) \
138 ; do \
139 sed "s/ .*_init/ _init/" extensions/ebt_$${arg}.c > extensions/ebt_$${arg}.c_ ; \
140 mv extensions/ebt_$${arg}.c_ extensions/ebt_$${arg}.c ; \
141 done ; \
142 for arg in $(EXT_TABLES) \
143 ; do \
144 sed "s/ .*_init/ _init/" extensions/ebtable_$${arg}.c > extensions/ebtable_$${arg}.c_ ; \
145 mv extensions/ebtable_$${arg}.c_ extensions/ebtable_$${arg}.c ; \
146 done ; \
147 mv ebtables-standalone.c_ ebtables-standalone.c ; \
148 mv include/ebtables_u.h_ include/ebtables_u.h
149
Bart De Schuymer50441e92005-08-30 21:20:55 +0000150tmp1:=$(shell printf $(BINDIR) | sed 's/\//\\\//g')
151tmp2:=$(shell printf $(SYSCONFIGDIR) | sed 's/\//\\\//g')
Bart De Schuymerdb97ab22005-09-01 20:37:07 +0000152tmp3:=$(shell printf $(PIPE) | sed 's/\//\\\//g')
Bart De Schuymer50441e92005-08-30 21:20:55 +0000153.PHONY: scripts
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000154scripts: ebtables-save ebtables.sysv ebtables-config
Bart De Schuymer50441e92005-08-30 21:20:55 +0000155 cat ebtables-save | sed 's/__EXEC_PATH__/$(tmp1)/g' > ebtables-save_
Bart De Schuymer2320f8b2010-03-16 13:00:37 +0000156 mkdir -p $(DESTDIR)$(BINDIR)
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 Schuymer2320f8b2010-03-16 13:00:37 +0000159 if [ $(DESTDIR) != "" ]; then mkdir -p $(DESTDIR)$(INITDIR); fi
160 if test -d $(DESTDIR)$(INITDIR); then install -m 0755 -o root -g root ebtables.sysv_ $(DESTDIR)$(INITDIR)/ebtables; fi
Bart De Schuymer9336b5a2005-11-04 22:01:23 +0000161 cat ebtables-config | sed 's/__SYSCONFIG__/$(tmp2)/g' > ebtables-config_
Bart De Schuymer2320f8b2010-03-16 13:00:37 +0000162 if [ $(DESTDIR) != "" ]; then mkdir -p $(DESTDIR)$(SYSCONFIGDIR); fi
163 if test -d $(DESTDIR)$(SYSCONFIGDIR); then install -m 0600 -o root -g root ebtables-config_ $(DESTDIR)$(SYSCONFIGDIR)/ebtables-config; fi
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000164 rm -f ebtables-save_ ebtables.sysv_ ebtables-config_
Bart De Schuymer50441e92005-08-30 21:20:55 +0000165
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000166$(MANDIR)/man8/ebtables.8: ebtables.8
Bart De Schuymer0ddd5752007-08-12 15:11:40 +0000167 mkdir -p $(DESTDIR)$(@D)
Bart De Schuymer1cda4be2006-12-17 20:05:02 +0000168 sed 's/$$(VERSION)/$(PROGVERSION)/' ebtables.8 | sed 's/$$(DATE)/$(PROGDATE)/' > ebtables.8_
Bart De Schuymer0ddd5752007-08-12 15:11:40 +0000169 install -m 0644 -o root -g root ebtables.8_ $(DESTDIR)$@
Bart De Schuymer865dd4d2006-12-15 11:37:07 +0000170 rm -f ebtables.8_
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000171
Bart De Schuymer2320f8b2010-03-16 13:00:37 +0000172$(DESTDIR)$(ETHERTYPESFILE): ethertypes
173 mkdir -p $(@D)
174 install -m 0644 -o root -g root $< $@
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000175
Bart De Schuymer32890542002-07-10 20:09:56 +0000176.PHONY: exec
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000177exec: ebtables ebtables-restore
Bart De Schuymer0ddd5752007-08-12 15:11:40 +0000178 mkdir -p $(DESTDIR)$(BINDIR)
179 install -m 0755 -o root -g root $(PROGNAME) $(DESTDIR)$(BINDIR)/$(PROGNAME)
180 install -m 0755 -o root -g root ebtables-restore $(DESTDIR)$(BINDIR)/ebtables-restore
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000181
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000182.PHONY: install
Bart De Schuymer2320f8b2010-03-16 13:00:37 +0000183install: $(MANDIR)/man8/ebtables.8 $(DESTDIR)$(ETHERTYPESFILE) exec scripts
Bart De Schuymer0ddd5752007-08-12 15:11:40 +0000184 mkdir -p $(DESTDIR)$(LIBDIR)
185 install -m 0755 extensions/*.so $(DESTDIR)$(LIBDIR)
186 install -m 0755 *.so $(DESTDIR)$(LIBDIR)
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000187
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000188.PHONY: clean
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000189clean:
Bart De Schuymer7d9e3eb2006-02-06 21:24:02 +0000190 rm -f ebtables ebtables-restore ebtablesd ebtablesu static
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000191 rm -f *.o *~ *.so
Bart De Schuymer96ee8d12005-11-04 21:59:57 +0000192 rm -f extensions/*.o extensions/*.c~ extensions/*.so include/*~
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000193
194DIR:=$(PROGNAME)-v$(PROGVERSION)
Bart De Schuymer22d8f5f2007-05-28 16:45:38 +0000195CVSDIRS:=CVS extensions/CVS examples/CVS examples/perf_test/CVS \
196examples/ulog/CVS include/CVS
Bart De Schuymer865dd4d2006-12-15 11:37:07 +0000197# This is used to make a new userspace release, some files are altered so
198# do this on a temporary version
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000199.PHONY: release
200release:
Bart De Schuymer22d8f5f2007-05-28 16:45:38 +0000201 rm -f extensions/ebt_inat.c
202 rm -rf $(CVSDIRS)
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000203 mkdir -p include/linux/netfilter_bridge
204 install -m 0644 -o root -g root \
205 $(KERNEL_INCLUDES)/linux/netfilter_bridge.h include/linux/
206# To keep possible compile error complaints about undefined ETH_P_8021Q
207# off my back
208 install -m 0644 -o root -g root \
209 $(KERNEL_INCLUDES)/linux/if_ether.h include/linux/
210 install -m 0644 -o root -g root \
Bart De Schuymer72ecebe2006-12-17 21:29:34 +0000211 $(KERNEL_INCLUDES)/linux/types.h include/linux/
212 install -m 0644 -o root -g root \
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000213 $(KERNEL_INCLUDES)/linux/netfilter_bridge/*.h \
214 include/linux/netfilter_bridge/
Bart De Schuymer60c20092003-07-23 21:34:21 +0000215 install -m 0644 -o root -g root \
216 include/ebtables.h include/linux/netfilter_bridge/
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000217 make clean
Bart De Schuymere29506d2003-07-26 11:53:32 +0000218 touch *
219 touch extensions/*
220 touch include/*
221 touch include/linux/*
222 touch include/linux/netfilter_bridge/*
Bart De Schuymer865dd4d2006-12-15 11:37:07 +0000223 sed -i 's/$$(VERSION)/$(PROGVERSION)/' ebtables.8
224 sed -i 's/$$(DATE)/$(PROGDATE)/' ebtables.8
Bart De Schuymer22d8f5f2007-05-28 16:45:38 +0000225 sed -i 's/$$(VERSION)/$(PROGVERSION_)/' ebtables.spec
Bart De Schuymer865dd4d2006-12-15 11:37:07 +0000226 sed -i 's/$$(RELEASE)/$(PROGRELEASE)/' ebtables.spec
Bart De Schuymer308ea9f2005-11-13 12:15:09 +0000227 cd ..;tar -c $(DIR) | gzip >$(DIR).tar.gz; cd -
228 rm -rf include/linux
229
230# This will make the rpm and put it in /usr/src/redhat/RPMS
231# (do this as root after make release)
232.PHONY: rpmbuild
233rpmbuild:
234 cp ../$(DIR).tar.gz /usr/src/redhat/SOURCES/
Bart De Schuymer58acf952005-11-13 12:23:13 +0000235 rpmbuild --buildroot $(shell mktemp -td $(DIR)-XXXXX) -bb ebtables.spec
Bart De Schuymer8bde1012004-11-20 13:00:52 +0000236
237.PHONY: test_ulog
238test_ulog: examples/ulog/test_ulog.c getethertype.o
239 $(CC) $(CFLAGS) $< -o test_ulog -I$(KERNEL_INCLUDES) -lc \
240 getethertype.o
241 mv test_ulog examples/ulog/
242
243.PHONY: examples
244examples: test_ulog