include local.mk
PREFIX=/usr/local
RELEASE=$(shell uname -r)
MODULE=/lib/modules/$(RELEASE)/misc

all: modules util

modules: aufs.ko

patch:
	cp -upr ./fs $(KDIR)
	find $(KDIR)/fs -type d -name CVS | xargs -r rm -rf
	cp -upr ./include $(KDIR)
	find $(KDIR)/include -type d -name CVS | xargs -r rm -rf
	if [ -z '$(shell grep 'obj-$$(CONFIG_AUFS)' $(KDIR)/fs/Makefile)' ]; then \
		echo 'obj-$$(CONFIG_AUFS)		+= aufs/' >> $(KDIR)/fs/Makefile; fi
	if [ -z "$(shell grep source\ \"fs\/aufs\/Kconfig\" $(KDIR)/fs/Kconfig)" ]; then \
		sed -e 's/menu "Layered filesystems"/menu "Layered filesystems"\n\nsource "fs\/aufs\/Kconfig"/g' \
		$(KDIR)/fs/Kconfig > $(KDIR)/fs/Kconfig.new && \
		mv $(KDIR)/fs/Kconfig.new $(KDIR)/fs/Kconfig; fi


util: aufs.5 aufind.sh mount.aufs auplink aulchown umount.aufs

modules_install: modules
	install -p -D aufs.ko $(MODULE)/aufs.ko
	depmod -a $(RELEASE)

util_install: util
	if [ ! -d $(PREFIX)/sbin ]; then \
		mkdir $(PREFIX)/sbin; fi
	install -m 755 -p mount.aufs umount.aufs auplink aulchown $(PREFIX)/sbin
	install -m 755 -p -D aufs.5 $(PREFIX)/man/man5/aufs.5
	bzip2 -f $(PREFIX)/man/man5/aufs.5
	if [ ! -d /etc/default ]; then \
		mkdir /etc/default; fi
	if [ ! -f /etc/default/auplink ]; then \
		echo FLUSH=ALL > /etc/default/auplink; fi

install: modules_install util_install

up:
	cvs -z3 -d:pserver:anonymous@aufs.cvs.sourceforge.net:/cvsroot/aufs update .
