blob: a05ce174efd0b246fb2599239baf73a919d3f6d3 [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 Schuymercd51fbe2006-04-11 18:20:35 +00004PROGVERSION:=2.0.8-rc2
5PROGDATE:=March\ 2006
Bart De Schuymer1abc55d2002-06-01 19:23:47 +00006
Bart De Schuymer3749f302004-02-11 21:23:38 +00007# default paths
Bart De Schuymer38561e92004-02-23 09:20:42 +00008LIBDIR:=/usr/lib
Bart De Schuymer3749f302004-02-11 21:23:38 +00009MANDIR:=/usr/local/man
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000010BINDIR:=/usr/local/sbin
Bart De Schuymer3749f302004-02-11 21:23:38 +000011ETCDIR:=/etc
Bart De Schuymer50441e92005-08-30 21:20:55 +000012INITDIR:=/etc/rc.d/init.d
13SYSCONFIGDIR:=/etc/sysconfig
Bart De Schuymer38561e92004-02-23 09:20:42 +000014DESTDIR:=
Bart De Schuymer3749f302004-02-11 21:23:38 +000015
16# include DESTDIR param
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000017override LIBDIR:=$(DESTDIR)$(LIBDIR)/$(PROGNAME)
Bart De Schuymer3749f302004-02-11 21:23:38 +000018override MANDIR:=$(DESTDIR)$(MANDIR)
19override BINDIR:=$(DESTDIR)$(BINDIR)
20override ETCDIR:=$(DESTDIR)$(ETCDIR)
Bart De Schuymer50441e92005-08-30 21:20:55 +000021override INITDIR:=$(DESTDIR)$(INITDIR)
22override SYSCONFIGDIR:=$(DESTDIR)$(SYSCONFIGDIR)
Bart De Schuymer3749f302004-02-11 21:23:38 +000023
24
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000025CFLAGS:=-Wall -Wunused
Bart De Schuymer17c60f52006-12-14 18:55:44 +000026CFLAGS_SH_LIB:=-fPIC
Bart De Schuymer06a1b462002-09-07 11:51:13 +000027CC:=gcc
Bart De Schuymer64182a32004-01-21 20:39:54 +000028LD:=ld
Bart De Schuymer3c1e00c2002-12-07 11:18:57 +000029
Bart De Schuymer60c20092003-07-23 21:34:21 +000030ifeq ($(shell uname -m),sparc64)
31CFLAGS+=-DEBT_MIN_ALIGN=8 -DKERNEL_64_USERSPACE_32
32endif
33
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000034include extensions/Makefile
35
Bart De Schuymer64182a32004-01-21 20:39:54 +000036OBJECTS2:=getethertype.o communication.o libebtc.o \
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000037useful_functions.o ebtables.o
Bart De Schuymer64182a32004-01-21 20:39:54 +000038
Bart De Schuymer7d9e3eb2006-02-06 21:24:02 +000039OBJECTS:=$(OBJECTS2) $(EXT_OBJS) $(EXT_LIBS)
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000040
Bart De Schuymer06a96822003-02-19 20:09:51 +000041KERNEL_INCLUDES?=include/
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000042
Bart De Schuymer3749f302004-02-11 21:23:38 +000043ETHERTYPESPATH?=$(ETCDIR)
Bart De Schuymera2960382003-04-01 17:29:13 +000044ETHERTYPESFILE:=$(ETHERTYPESPATH)/ethertypes
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000045
Bart De Schuymer50441e92005-08-30 21:20:55 +000046PIPE_DIR?=$(DESTDIR)/tmp/$(PROGNAME)-v$(PROGVERSION)
Bart De Schuymer6622a012005-01-19 21:09:05 +000047PIPE=$(PIPE_DIR)/ebtablesd_pipe
48EBTD_CMDLINE_MAXLN?=2048
49EBTD_ARGC_MAX?=50
50
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000051PROGSPECS:=-DPROGVERSION=\"$(PROGVERSION)\" \
52 -DPROGNAME=\"$(PROGNAME)\" \
53 -DPROGDATE=\"$(PROGDATE)\" \
Bart De Schuymer9d680cc2005-10-01 09:16:51 +000054 -D_PATH_ETHERTYPES=\"$(ETHERTYPESFILE)\" \
55 -DEBTD_ARGC_MAX=$(EBTD_ARGC_MAX) \
56 -DEBTD_CMDLINE_MAXLN=$(EBTD_CMDLINE_MAXLN)
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000057
Bart De Schuymer96ee8d12005-11-04 21:59:57 +000058# You can probably ignore this, ebtables{u,d} are normally not used
Bart De Schuymer6622a012005-01-19 21:09:05 +000059PROGSPECSD:=-DPROGVERSION=\"$(PROGVERSION)\" \
60 -DPROGNAME=\"$(PROGNAME)\" \
61 -DPROGDATE=\"$(PROGDATE)\" \
62 -D_PATH_ETHERTYPES=\"$(ETHERTYPESFILE)\" \
63 -DEBTD_CMDLINE_MAXLN=$(EBTD_CMDLINE_MAXLN) \
64 -DEBTD_ARGC_MAX=$(EBTD_ARGC_MAX) \
65 -DEBTD_PIPE=\"$(PIPE)\" \
66 -DEBTD_PIPE_DIR=\"$(PIPE_DIR)\"
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000067
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000068# Uncomment for debugging (slower)
69#PROGSPECS+=-DEBT_DEBUG
70#PROGSPECSD+=-DEBT_DEBUG
Bart De Schuymer96ee8d12005-11-04 21:59:57 +000071#CFLAGS+=-ggdb
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000072
Bart De Schuymer96ee8d12005-11-04 21:59:57 +000073all: ebtables ebtables-restore
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000074
75communication.o: communication.c include/ebtables_u.h
Bart De Schuymer17c60f52006-12-14 18:55:44 +000076 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES)
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000077
Bart De Schuymer8339ff12004-01-14 20:05:27 +000078libebtc.o: libebtc.c include/ebtables_u.h
Bart De Schuymer17c60f52006-12-14 18:55:44 +000079 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES)
Bart De Schuymer8339ff12004-01-14 20:05:27 +000080
81useful_functions.o: useful_functions.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 Schuymer8339ff12004-01-14 20:05:27 +000083
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000084getethertype.o: getethertype.c include/ethernetdb.h
Bart De Schuymer17c60f52006-12-14 18:55:44 +000085 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -Iinclude/
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000086
87ebtables.o: ebtables.c include/ebtables_u.h
Bart De Schuymer0f8c4992002-11-20 19:41:02 +000088 $(CC) $(CFLAGS) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES)
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000089
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000090ebtables-standalone.o: ebtables-standalone.c include/ebtables_u.h
91 $(CC) $(CFLAGS) $(PROGSPECS) -c $< -o $@ -I$(KERNEL_INCLUDES)
Bart De Schuymer6622a012005-01-19 21:09:05 +000092
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000093.PHONY: libebtc
94libebtc: $(OBJECTS2)
Bart De Schuymere1c15882004-05-24 19:57:58 +000095 $(LD) -shared -soname libebtc.so -o libebtc.so -lc $(OBJECTS2)
Bart De Schuymer838fa5b2005-06-18 14:43:32 +000096
97ebtables: $(OBJECTS) ebtables-standalone.o libebtc
98 $(CC) $(CFLAGS) -o $@ ebtables-standalone.o -I$(KERNEL_INCLUDES) -L. -Lextensions -lebtc $(EXT_LIBSI) \
99 -Wl,-rpath,$(LIBDIR)
Bart De Schuymer6622a012005-01-19 21:09:05 +0000100
101ebtablesu: ebtablesu.c
102 $(CC) $(CFLAGS) $(PROGSPECSD) $< -o $@
103
Bart De Schuymer838fa5b2005-06-18 14:43:32 +0000104ebtablesd.o: ebtablesd.c include/ebtables_u.h
105 $(CC) $(CFLAGS) $(PROGSPECSD) -c $< -o $@ -I$(KERNEL_INCLUDES)
Bart De Schuymer6622a012005-01-19 21:09:05 +0000106
Bart De Schuymer838fa5b2005-06-18 14:43:32 +0000107ebtablesd: $(OBJECTS) ebtablesd.o libebtc
108 $(CC) $(CFLAGS) -o $@ ebtablesd.o -I$(KERNEL_INCLUDES) -L. -Lextensions -lebtc $(EXT_LIBSI) \
109 -Wl,-rpath,$(LIBDIR)
Bart De Schuymer6622a012005-01-19 21:09:05 +0000110
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000111ebtables-restore.o: ebtables-restore.c include/ebtables_u.h
Bart De Schuymer9d680cc2005-10-01 09:16:51 +0000112 $(CC) $(CFLAGS) $(PROGSPECS) -c $< -o $@ -I$(KERNEL_INCLUDES)
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000113
114ebtables-restore: $(OBJECTS) ebtables-restore.o libebtc
115 $(CC) $(CFLAGS) -o $@ ebtables-restore.o -I$(KERNEL_INCLUDES) -L. -Lextensions -lebtc $(EXT_LIBSI) \
116 -Wl,-rpath,$(LIBDIR)
117
Bart De Schuymer6622a012005-01-19 21:09:05 +0000118.PHONY: daemon
119daemon: ebtablesd ebtablesu
120
Bart De Schuymer7d9e3eb2006-02-06 21:24:02 +0000121# a little scripting for a static binary, making one for ebtables-restore
122# should be completely analogous
123static: extensions/ebt_*.c extensions/ebtable_*.c ebtables.c communication.c ebtables-standalone.c getethertype.c libebtc.c useful_functions.c
124 cp ebtables-standalone.c ebtables-standalone.c_ ; \
125 cp include/ebtables_u.h include/ebtables_u.h_ ; \
126 sed "s/ main(/ pseudomain(/" ebtables-standalone.c > ebtables-standalone.c__ ; \
127 mv ebtables-standalone.c__ ebtables-standalone.c ; \
128 printf "\nint main(int argc, char *argv[])\n{\n " >> ebtables-standalone.c ; \
129 for arg in $(EXT_FUNC) \
130 ; do \
131 sed s/_init/_$${arg}_init/ extensions/ebt_$${arg}.c > extensions/ebt_$${arg}.c_ ; \
132 mv extensions/ebt_$${arg}.c_ extensions/ebt_$${arg}.c ; \
133 printf "\t%s();\n" _$${arg}_init >> ebtables-standalone.c ; \
134 printf "extern void %s();\n" _$${arg}_init >> include/ebtables_u.h ; \
135 done ; \
136 for arg in $(EXT_TABLES) \
137 ; do \
138 sed s/_init/_t_$${arg}_init/ extensions/ebtable_$${arg}.c > extensions/ebtable_$${arg}.c_ ; \
139 mv extensions/ebtable_$${arg}.c_ extensions/ebtable_$${arg}.c ; \
140 printf "\t%s();\n" _t_$${arg}_init >> ebtables-standalone.c ; \
141 printf "extern void %s();\n" _t_$${arg}_init >> include/ebtables_u.h ; \
142 done ; \
143 printf "\n\tpseudomain(argc, argv);\n\treturn 0;\n}\n" >> ebtables-standalone.c ;\
Bart De Schuymerdc5d9fc2006-08-09 10:28:14 +0000144 $(CC) $(CFLAGS) $(PROGSPECS) -o $@ $^ -I$(KERNEL_INCLUDES) -Iinclude ; \
Bart De Schuymer7d9e3eb2006-02-06 21:24:02 +0000145 for arg in $(EXT_FUNC) \
146 ; do \
147 sed "s/ .*_init/ _init/" extensions/ebt_$${arg}.c > extensions/ebt_$${arg}.c_ ; \
148 mv extensions/ebt_$${arg}.c_ extensions/ebt_$${arg}.c ; \
149 done ; \
150 for arg in $(EXT_TABLES) \
151 ; do \
152 sed "s/ .*_init/ _init/" extensions/ebtable_$${arg}.c > extensions/ebtable_$${arg}.c_ ; \
153 mv extensions/ebtable_$${arg}.c_ extensions/ebtable_$${arg}.c ; \
154 done ; \
155 mv ebtables-standalone.c_ ebtables-standalone.c ; \
156 mv include/ebtables_u.h_ include/ebtables_u.h
157
Bart De Schuymer50441e92005-08-30 21:20:55 +0000158tmp1:=$(shell printf $(BINDIR) | sed 's/\//\\\//g')
159tmp2:=$(shell printf $(SYSCONFIGDIR) | sed 's/\//\\\//g')
Bart De Schuymerdb97ab22005-09-01 20:37:07 +0000160tmp3:=$(shell printf $(PIPE) | sed 's/\//\\\//g')
Bart De Schuymer50441e92005-08-30 21:20:55 +0000161.PHONY: scripts
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000162scripts: ebtables-save ebtables.sysv ebtables-config
Bart De Schuymer50441e92005-08-30 21:20:55 +0000163 cat ebtables-save | sed 's/__EXEC_PATH__/$(tmp1)/g' > ebtables-save_
164 install -m 0755 -o root -g root ebtables-save_ $(BINDIR)/ebtables-save
Bart De Schuymerdb97ab22005-09-01 20:37:07 +0000165 cat ebtables.sysv | sed 's/__EXEC_PATH__/$(tmp1)/g' | sed 's/__SYSCONFIG__/$(tmp2)/g' > ebtables.sysv_
Bart De Schuymer50441e92005-08-30 21:20:55 +0000166 install -m 0755 -o root -g root ebtables.sysv_ $(INITDIR)/ebtables
Bart De Schuymer9336b5a2005-11-04 22:01:23 +0000167 cat ebtables-config | sed 's/__SYSCONFIG__/$(tmp2)/g' > ebtables-config_
Bart De Schuymer50441e92005-08-30 21:20:55 +0000168 install -m 0600 -o root -g root ebtables-config_ $(SYSCONFIGDIR)/ebtables-config
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000169 rm -f ebtables-save_ ebtables.sysv_ ebtables-config_
Bart De Schuymer50441e92005-08-30 21:20:55 +0000170
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000171$(MANDIR)/man8/ebtables.8: ebtables.8
172 mkdir -p $(@D)
173 install -m 0644 -o root -g root $< $@
174
Bart De Schuymer2eb1f922002-11-22 18:55:55 +0000175$(ETHERTYPESFILE): ethertypes
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000176 mkdir -p $(@D)
177 install -m 0644 -o root -g root $< $@
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000178
Bart De Schuymer32890542002-07-10 20:09:56 +0000179.PHONY: exec
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000180exec: ebtables ebtables-restore
Bart De Schuymer3749f302004-02-11 21:23:38 +0000181 mkdir -p $(BINDIR)
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000182 install -m 0755 -o root -g root $(PROGNAME) $(BINDIR)/$(PROGNAME)
183 install -m 0755 -o root -g root ebtables-restore $(BINDIR)/ebtables-restore
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000184
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000185.PHONY: install
Bart De Schuymer50441e92005-08-30 21:20:55 +0000186install: $(MANDIR)/man8/ebtables.8 $(ETHERTYPESFILE) exec scripts
Bart De Schuymer0f5e3fe2004-02-10 18:08:00 +0000187 mkdir -p $(LIBDIR)
Bart De Schuymer64182a32004-01-21 20:39:54 +0000188 install -m 0755 extensions/*.so $(LIBDIR)
189 install -m 0755 *.so $(LIBDIR)
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000190
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000191.PHONY: clean
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000192clean:
Bart De Schuymer7d9e3eb2006-02-06 21:24:02 +0000193 rm -f ebtables ebtables-restore ebtablesd ebtablesu static
Bart De Schuymer90db00b2005-09-28 19:36:34 +0000194 rm -f *.o *~ *.so
Bart De Schuymer96ee8d12005-11-04 21:59:57 +0000195 rm -f extensions/*.o extensions/*.c~ extensions/*.so include/*~
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000196
197DIR:=$(PROGNAME)-v$(PROGVERSION)
198# This is used to make a new userspace release
199.PHONY: release
200release:
201 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 \
209 $(KERNEL_INCLUDES)/linux/netfilter_bridge/*.h \
210 include/linux/netfilter_bridge/
Bart De Schuymer60c20092003-07-23 21:34:21 +0000211 install -m 0644 -o root -g root \
212 include/ebtables.h include/linux/netfilter_bridge/
Bart De Schuymer0f8c4992002-11-20 19:41:02 +0000213 make clean
Bart De Schuymere29506d2003-07-26 11:53:32 +0000214 touch *
215 touch extensions/*
216 touch include/*
217 touch include/linux/*
218 touch include/linux/netfilter_bridge/*
Bart De Schuymer308ea9f2005-11-13 12:15:09 +0000219 cd ..;tar -c $(DIR) | gzip >$(DIR).tar.gz; cd -
220 rm -rf include/linux
221
222# This will make the rpm and put it in /usr/src/redhat/RPMS
223# (do this as root after make release)
224.PHONY: rpmbuild
225rpmbuild:
226 cp ../$(DIR).tar.gz /usr/src/redhat/SOURCES/
Bart De Schuymer58acf952005-11-13 12:23:13 +0000227 rpmbuild --buildroot $(shell mktemp -td $(DIR)-XXXXX) -bb ebtables.spec
Bart De Schuymer8bde1012004-11-20 13:00:52 +0000228
229.PHONY: test_ulog
230test_ulog: examples/ulog/test_ulog.c getethertype.o
231 $(CC) $(CFLAGS) $< -o test_ulog -I$(KERNEL_INCLUDES) -lc \
232 getethertype.o
233 mv test_ulog examples/ulog/
234
235.PHONY: examples
236examples: test_ulog