#
# ipvs: IP Virtual Server Module for the NetFilter framework
#

NAME	= ipvs
VERSION	= 1.1.4

# need to specify the path of kernel source
KERNELSOURCE	= /usr/src/linux


all:
	@echo "Fellow the README, apply the patches to your kernel source,"
	@echo "and rebuilt the kernel image. Or, use the following commands"
	@echo "to patch the kernel source (make sure that the KERNELSOURCE"
	@echo "is specified correctly in the Makefile):"
	@echo -e "\tmake patchkernel\t- patch the kernel source (only need patch"
	@echo -e "\t\t\t\ta clean copy of the kernel source one time)"
	@echo -e "\tmake installsource\t- install the ipvs source code"

patchkernel:
	cat linux_net_netsyms_c.diff | (cd $(KERNELSOURCE) && patch -p1)
	cat linux_net_ipv4_Makefile.diff | (cd $(KERNELSOURCE) && patch -p1)
	cat linux_net_ipv4_Config_in.diff | (cd $(KERNELSOURCE) && patch -p1)
	cat linux_ip_fw_compat_c.diff | (cd $(KERNELSOURCE) && patch -p1)

installsource:
	cp -p ipvs/ip_vs.h $(KERNELSOURCE)/include/net/
	if [ ! -d $(KERNELSOURCE)/net/ipv4/ipvs ]; then	\
		mkdir -p $(KERNELSOURCE)/net/ipv4/ipvs;	\
	fi
	cp -p ipvs/linux_net_ipv4_ipvs_Makefile $(KERNELSOURCE)/net/ipv4/ipvs/Makefile
	cp -p ipvs/Kconfig $(KERNELSOURCE)/net/ipv4/ipvs/
	cp -p ipvs/*.c $(KERNELSOURCE)/net/ipv4/ipvs/
	scripts/fixheader.pl $(KERNELSOURCE)/net/ipv4/ipvs/*.c

clean:
	make -C ipvs/ipvsadm clean
	-make -C ipvs clean
	find . -name '*.[ao]' -o -name "*.ko" -o -name "*.orig"	\
		-o -name "*~" -o -name "*.rej" -o -name core	\
		-o -name TAGS -o -name tags | xargs rm -f
	rm -f $(NAME)-$(VERSION).tar.gz


distclean:	clean
	rm -f TAGS tags


dist:	distclean
	if [ ! -x ipvs/ipvsadm/debian/rules ]; then	\
		chmod +x ipvs/ipvsadm/debian/rules;	\
	fi
	(cd .. ; tar cvf - $(NAME)-$(VERSION) --exclude CVS	\
	 | gzip -9 > $(NAME)-$(VERSION).tar.gz)
	mv ../$(NAME)-$(VERSION).tar.gz .
