# By default, the build is done against the running kernel version.
# to build against a different kernel version, set KVER
#
#  make KVER=2.6.11-alpha

ifneq ($(KERNELRELEASE),)
include $(src)/Kbuild
else
CONFIG := CONFIG_VIDEO_IVTV=m

MDIR := ivtv
PWD  := $(shell pwd)
KVER ?= $(shell uname -r)
KDIR := $(KERNEL_SOURCE)

# Note: building external modules for a 2.6 kernel causes 'has no CRC' warnings
# to be generated. These messages are harmless but cannot be suppressed.
all:
	$(MAKE) $(CONFIG) -C $(KDIR) M=$(PWD) modules
	@echo
	@echo "Any 'has no CRC' warnings are harmless and can be ignored."
	@echo

install: all
	$(MAKE) $(CONFIG) -C $(KDIR) M=$(PWD) modules_install
	@ for m in ` find $(INSTALL_MOD_PATH)/lib/modules/$(KVER)/kernel -name msp3400.ko -o -name tuner.ko -o -name tda9887.ko -o -name tveeprom.ko ` ; \
	  do \
	  	if ! cmp -s $$m `basename $$m` ; \
		then \
			echo "Module $$m conflicts with the ivtv module of the same name -- please hide or delete it." ; \
			echo "To hide:  mv $$m $$m.HIDE" ; \
			echo "You will then need to run depmod." ; \
		fi ; \
	  done

clean: 
	rm -rf .*.cmd *.o *.mod.c *.ko *~ core .tmp_versions

modules: all

reload:
	-sudo rmmod ivtv-fb ivtv msp3400 saa7115 saa7127 tuner
	sync
	-sudo modprobe i2c-core
	-sudo modprobe i2c-algo-bit
	-sudo insmod saa7115.ko
	-sudo insmod msp3400.ko
	-sudo modprobe tuner type=29
	-sudo modprobe videodev
	-sudo insmod ivtv.ko ivtv_debug=255

unload:
	-sudo rmmod ivtv-fb ivtv msp3400 saa7115 saa7127 tuner

endif
