#
# tw680x, Twchwell TW6802 and TW6805 video driver with V4L/2 support
#
# Makefile - driver build system
#

# Requires GNU Make


# Usual paths to the kernel source tree
KDIR := /lib/modules/`uname -r`/build

# Standard path to install the driver
MODULE_INSTALLDIR = /lib/modules/`uname -r`/kernel/sound/pci

ifneq ($(KERNELRELEASE),)   # We were called by build system.

snd-tw680x-objs := bt87x.o

obj-$(CONFIG_VIDEO_BT848) += snd-tw680x.o

else   # We were called from command line

PWD := "$(shell pwd)"

default: modules

modules:
	@echo '**************************************************************************'
	@echo '* Building Techwell TW680x audio driver...                              *'
	@echo '* Type "make help" for a list of available targets.                      *'
	@echo '**************************************************************************'
	@echo
	$(MAKE) -C $(KDIR) M=$(PWD) clean
	$(MAKE) -C $(KDIR) M=$(PWD) modules

clean:
	$(MAKE) -C $(KDIR) M=$(PWD) clean


install: modules_install

modules_install:
	/bin/cp ./snd-tw680x.ko $(MODULE_INSTALLDIR)
	/bin/chmod 644 $(MODULE_INSTALLDIR)/snd-tw680x.ko
	/sbin/depmod -ae
	@echo
	@echo '**************************************************************************'
	@echo '* Driver installed successfully. Type "make load" to load it.            *'
	@echo '**************************************************************************'
	@echo

load:
  #  /sbin/modprobe -r snd-tw680x
  #  /bin/cp ./snd-tw680x.ko $(MODULE_INSTALLDIR)
	/sbin/modprobe snd-tw680x

reload:
	/sbin/modprobe -r snd-tw680x
	/sbin/modprobe snd-tw680x

uninstall: modules_uninstall

modules_uninstall:
	/bin/rm -rf $(MODULE_INSTALLDIR)/snd-tw680x.ko
	/sbin/depmod -ae
	@echo
	@echo '**************************************************************************'
	@echo '* Driver uninstalled successfully.                                       *'
	@echo '**************************************************************************'
	@echo

help:
	@echo 'List of available targets. Type:'
	@echo '- "make modules" to build the modules'
	@echo '- "make modules_install" to install the built modules'
	@echo '- "make reload" to reload the modules'
	@echo '- "make load" to load the installed modules'
	@echo '- "make modules_uninstall" to uninstall the installed modules'
	@echo '- "make clean" to remove all generated files in the current directory'
	@echo '- "make tar" to create an source code archive of the current directory in $(TARFILE)'
	@echo '- "make help" to print the list of available targets'


RELEASE_VERSION := $(shell date +%Y%m%d)
TARFILE=../snd-tw680x-$(RELEASE_VERSION).tar.gz
DIR=../
FILE=snd-tw680x


tar:
	$(MAKE) -C $(KDIR) M=$(PWD) clean
	/bin/rm -rf *~
	tar -choz --verbose -C $(DIR) --file=$(TARFILE) $(FILE)
	@echo
	@echo '**************************************************************************'
	@echo '* Source package created in the parent folder ../                        *'
	@echo '**************************************************************************'
	@echo


endif

