1# ebtables Makefile 2 3PROGNAME:=ebtables 4PROGRELEASE:=2 5PROGVERSION_:=2.0.9 6PROGVERSION:=$(PROGVERSION_)-$(PROGRELEASE) 7PROGDATE:=June\ 2009 8 9# default paths 10LIBDIR:=/usr/lib 11MANDIR:=/usr/local/man 12BINDIR:=/usr/local/sbin 13ETCDIR:=/etc 14INITDIR:=/etc/rc.d/init.d 15SYSCONFIGDIR:=/etc/sysconfig 16DESTDIR:= 17 18CFLAGS:=-Wall -Wunused 19CFLAGS_SH_LIB:=-fPIC 20CC:=gcc 21 22ifeq ($(shell uname -m),sparc64) 23CFLAGS+=-DEBT_MIN_ALIGN=8 -DKERNEL_64_USERSPACE_32 24endif 25 26include extensions/Makefile 27 28OBJECTS2:=getethertype.o communication.o libebtc.o \ 29useful_functions.o ebtables.o 30 31OBJECTS:=$(OBJECTS2) $(EXT_OBJS) $(EXT_LIBS) 32 33KERNEL_INCLUDES?=include/ 34 35ETHERTYPESPATH?=$(ETCDIR) 36ETHERTYPESFILE:=$(ETHERTYPESPATH)/ethertypes 37 38PIPE_DIR?=/tmp/$(PROGNAME)-v$(PROGVERSION) 39PIPE=$(PIPE_DIR)/ebtablesd_pipe 40EBTD_CMDLINE_MAXLN?=2048 41EBTD_ARGC_MAX?=50 42 43PROGSPECS:=-DPROGVERSION=\"$(PROGVERSION)\" \ 44 -DPROGNAME=\"$(PROGNAME)\" \ 45 -DPROGDATE=\"$(PROGDATE)\" \ 46 -D_PATH_ETHERTYPES=\"$(ETHERTYPESFILE)\" \ 47 -DEBTD_ARGC_MAX=$(EBTD_ARGC_MAX) \ 48 -DEBTD_CMDLINE_MAXLN=$(EBTD_CMDLINE_MAXLN) 49 50# You can probably ignore this, ebtables{u,d} are normally not used 51PROGSPECSD:=-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)\" 59 60# Uncomment for debugging (slower) 61#PROGSPECS+=-DEBT_DEBUG 62#PROGSPECSD+=-DEBT_DEBUG 63#CFLAGS+=-ggdb 64 65all: ebtables ebtables-restore 66 67communication.o: communication.c include/ebtables_u.h 68 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES) 69 70libebtc.o: libebtc.c include/ebtables_u.h 71 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES) 72 73useful_functions.o: useful_functions.c include/ebtables_u.h 74 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES) 75 76getethertype.o: getethertype.c include/ethernetdb.h 77 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -Iinclude/ 78 79ebtables.o: ebtables.c include/ebtables_u.h 80 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES) 81 82ebtables-standalone.o: ebtables-standalone.c include/ebtables_u.h 83 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c $< -o $@ -I$(KERNEL_INCLUDES) 84 85.PHONY: libebtc 86libebtc: $(OBJECTS2) 87 $(CC) -shared $(LDFLAGS) -Wl,-soname,libebtc.so -o libebtc.so -lc $(OBJECTS2) 88 89ebtables: $(OBJECTS) ebtables-standalone.o libebtc 90 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(LDFLAGS) -o $@ ebtables-standalone.o -I$(KERNEL_INCLUDES) -L. -Lextensions -lebtc $(EXT_LIBSI) \ 91 -Wl,-rpath,$(LIBDIR) 92 93ebtablesu: ebtablesu.c 94 $(CC) $(CFLAGS) $(PROGSPECSD) $< -o $@ 95 96ebtablesd.o: ebtablesd.c include/ebtables_u.h 97 $(CC) $(CFLAGS) $(PROGSPECSD) -c $< -o $@ -I$(KERNEL_INCLUDES) 98 99ebtablesd: $(OBJECTS) ebtablesd.o libebtc 100 $(CC) $(CFLAGS) -o $@ ebtablesd.o -I$(KERNEL_INCLUDES) -L. -Lextensions -lebtc $(EXT_LIBSI) \ 101 -Wl,-rpath,$(LIBDIR) 102 103ebtables-restore.o: ebtables-restore.c include/ebtables_u.h 104 $(CC) $(CFLAGS) $(PROGSPECS) -c $< -o $@ -I$(KERNEL_INCLUDES) 105 106ebtables-restore: $(OBJECTS) ebtables-restore.o libebtc 107 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ ebtables-restore.o -I$(KERNEL_INCLUDES) -L. -Lextensions -lebtc $(EXT_LIBSI) \ 108 -Wl,-rpath,$(LIBDIR) 109 110.PHONY: daemon 111daemon: ebtablesd ebtablesu 112 113# 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 ;\ 136 $(CC) $(CFLAGS) $(PROGSPECS) -o $@ $^ -I$(KERNEL_INCLUDES) -Iinclude ; \ 137 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 150tmp1:=$(shell printf $(BINDIR) | sed 's/\//\\\//g') 151tmp2:=$(shell printf $(SYSCONFIGDIR) | sed 's/\//\\\//g') 152tmp3:=$(shell printf $(PIPE) | sed 's/\//\\\//g') 153.PHONY: scripts 154scripts: ebtables-save ebtables.sysv ebtables-config 155 cat ebtables-save | sed 's/__EXEC_PATH__/$(tmp1)/g' > ebtables-save_ 156 install -m 0755 -o root -g root ebtables-save_ $(DESTDIR)$(BINDIR)/ebtables-save 157 cat ebtables.sysv | sed 's/__EXEC_PATH__/$(tmp1)/g' | sed 's/__SYSCONFIG__/$(tmp2)/g' > ebtables.sysv_ 158 install -m 0755 -o root -g root ebtables.sysv_ $(DESTDIR)$(INITDIR)/ebtables 159 cat ebtables-config | sed 's/__SYSCONFIG__/$(tmp2)/g' > ebtables-config_ 160 install -m 0600 -o root -g root ebtables-config_ $(DESTDIR)$(SYSCONFIGDIR)/ebtables-config 161 rm -f ebtables-save_ ebtables.sysv_ ebtables-config_ 162 163$(MANDIR)/man8/ebtables.8: ebtables.8 164 mkdir -p $(DESTDIR)$(@D) 165 sed 's/$$(VERSION)/$(PROGVERSION)/' ebtables.8 | sed 's/$$(DATE)/$(PROGDATE)/' > ebtables.8_ 166 install -m 0644 -o root -g root ebtables.8_ $(DESTDIR)$@ 167 rm -f ebtables.8_ 168 169$(ETHERTYPESFILE): ethertypes 170 mkdir -p $(DESTDIR)$(@D) 171 install -m 0644 -o root -g root $< $(DESTDIR)$@ 172 173.PHONY: exec 174exec: ebtables ebtables-restore 175 mkdir -p $(DESTDIR)$(BINDIR) 176 install -m 0755 -o root -g root $(PROGNAME) $(DESTDIR)$(BINDIR)/$(PROGNAME) 177 install -m 0755 -o root -g root ebtables-restore $(DESTDIR)$(BINDIR)/ebtables-restore 178 179.PHONY: install 180install: $(MANDIR)/man8/ebtables.8 $(ETHERTYPESFILE) exec scripts 181 mkdir -p $(DESTDIR)$(LIBDIR) 182 install -m 0755 extensions/*.so $(DESTDIR)$(LIBDIR) 183 install -m 0755 *.so $(DESTDIR)$(LIBDIR) 184 185.PHONY: clean 186clean: 187 rm -f ebtables ebtables-restore ebtablesd ebtablesu static 188 rm -f *.o *~ *.so 189 rm -f extensions/*.o extensions/*.c~ extensions/*.so include/*~ 190 191DIR:=$(PROGNAME)-v$(PROGVERSION) 192CVSDIRS:=CVS extensions/CVS examples/CVS examples/perf_test/CVS \ 193examples/ulog/CVS include/CVS 194# This is used to make a new userspace release, some files are altered so 195# do this on a temporary version 196.PHONY: release 197release: 198 rm -f extensions/ebt_inat.c 199 rm -rf $(CVSDIRS) 200 mkdir -p include/linux/netfilter_bridge 201 install -m 0644 -o root -g root \ 202 $(KERNEL_INCLUDES)/linux/netfilter_bridge.h include/linux/ 203# To keep possible compile error complaints about undefined ETH_P_8021Q 204# off my back 205 install -m 0644 -o root -g root \ 206 $(KERNEL_INCLUDES)/linux/if_ether.h include/linux/ 207 install -m 0644 -o root -g root \ 208 $(KERNEL_INCLUDES)/linux/types.h include/linux/ 209 install -m 0644 -o root -g root \ 210 $(KERNEL_INCLUDES)/linux/netfilter_bridge/*.h \ 211 include/linux/netfilter_bridge/ 212 install -m 0644 -o root -g root \ 213 include/ebtables.h include/linux/netfilter_bridge/ 214 make clean 215 touch * 216 touch extensions/* 217 touch include/* 218 touch include/linux/* 219 touch include/linux/netfilter_bridge/* 220 sed -i 's/$$(VERSION)/$(PROGVERSION)/' ebtables.8 221 sed -i 's/$$(DATE)/$(PROGDATE)/' ebtables.8 222 sed -i 's/$$(VERSION)/$(PROGVERSION_)/' ebtables.spec 223 sed -i 's/$$(RELEASE)/$(PROGRELEASE)/' ebtables.spec 224 cd ..;tar -c $(DIR) | gzip >$(DIR).tar.gz; cd - 225 rm -rf include/linux 226 227# This will make the rpm and put it in /usr/src/redhat/RPMS 228# (do this as root after make release) 229.PHONY: rpmbuild 230rpmbuild: 231 cp ../$(DIR).tar.gz /usr/src/redhat/SOURCES/ 232 rpmbuild --buildroot $(shell mktemp -td $(DIR)-XXXXX) -bb ebtables.spec 233 234.PHONY: test_ulog 235test_ulog: examples/ulog/test_ulog.c getethertype.o 236 $(CC) $(CFLAGS) $< -o test_ulog -I$(KERNEL_INCLUDES) -lc \ 237 getethertype.o 238 mv test_ulog examples/ulog/ 239 240.PHONY: examples 241examples: test_ulog 242