KERNELDIR = /usr/src/linux
MODDIR = /lib/modules/`uname -r`/kernel/drivers/media/video
CROSS_COMPILE =
LD	= $(CROSS_COMPILE)ld
CC	= $(CROSS_COMPILE)gcc
AR	= $(CROSS_COMPILE)ar
IVTVOBJS	= ivtv-driver.o ivtv-i2c.o ivtv-api.o
OBJS	= msp3400.o saa7115.o tveeprom.o ivtv.o saa7127.o ivtv-fb.o

include $(KERNELDIR)/.config

CFLAGS = -D__KERNEL__ -D__KERNEL_SYSCALLS__ -DMODULE -DMODVERSIONS -I$(KERNELDIR)/include -O2 -fomit-frame-pointer -march=i586 -mcpu=i586 -fno-strict-aliasing -Wno-unused -include $(KERNELDIR)/include/linux/modversions.h

# uncomment if you use i2c 2.8.0+
#CFLAGS += -DNEW_I2C

all: $(OBJS)

ivtv.o: $(IVTVOBJS)
	$(LD) -r -o $@ $^

clean: 
	rm -f *.o *~ core

install: all
	mkdir -p $(MODDIR)
	install -m 0644 $(OBJS) $(MODDIR)

reload: all
	sudo make install
	-sudo rmmod ivtv-fb ivtv msp3400 saa7115 saa7127 tuner
	sync
	-ls -la /dev/video0 # (force devfs to reload the modules)

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

