#################################################
# config
#
MFII_VERSION := 0.0.9
#
# where the kernel sources are located
KERNEL_LOCATION := /usr/src/linux
#
# currently running kernel
CURRENT := $(shell uname -r)
#CURRENT=$(shell grep "UTS_RELEASE" $(KERNEL_LOCATION)/include/linux/version.h | cut -d\" -f2)
TREE := $(shell echo $(CURRENT) | cut -d. -f1-2)
#
# conditional stuff
ifeq ($(TREE),2.4)
  KCOMPAT :=
else
  KCOMPAT := kcompat24.o
endif

MODULE_DIR := $(shell test -d "/lib/modules/$(CURRENT)/kernel" && \
	echo "/lib/modules/$(CURRENT)/kernel/drivers/media/video" || \
	echo "/lib/modules/$(CURRENT)/misc")
# 
# If I2C header files reside at an "unusual" place,
# remove the '#' from the following parameter line
# and tell the actual directory
#I2C_HEADERS := /usr/src/linux/include

#################################################
# some magic for using linux kernel settings
# when compiling module(s)

export CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
          else if [ -x /bin/bash ]; then echo /bin/bash; \
          else echo sh; fi ; fi)
export TOPDIR=$(KERNEL_LOCATION)

# for new-style kernel Makefiles (2.4)
obj-y		:=
obj-m		:=
obj-n		:=
obj-		:=

SUB_DIRS	:=
MOD_SUB_DIRS	:= $(SUB_DIRS)
ALL_SUB_DIRS	:= $(SUB_DIRS)

export-objs	:= saa7146_core.o $(KCOMPAT)

obj-m		:= $(KCOMPAT) saa7146_core.o saa7146_v4l.o sp5055II.o stv0056af.o saa7113h.o msp3400satII.o drp3510II.o ee24lc16.o mfII.o

# for old-style kernel Makefiles (2.2)
M_OBJS		:= $(sort $(filter-out	$(export-objs), $(obj-m)))
MX_OBJS		:= $(sort $(filter	$(export-objs), $(obj-m)))


CFLAGS_mfII.o	:= -DVERS='"$(MFII_VERSION)"'

ifneq ($(strip $(I2C_HEADERS)),)
EXTRA_CFLAGS	+= -I$(I2C_HEADERS)
endif

here:
	DIR=`pwd`; (cd $(KERNEL_LOCATION); make SUBDIRS=$$DIR modules)

dep:
	DIR=`pwd`; (cd $(KERNEL_LOCATION); make SUBDIRS=$$DIR dep)

install:
	install -m 644 -o root -g root $(M_OBJS) $(MX_OBJS) $(MODULE_DIR)

uninstall:
	rm -f $(foreach f, $(M_OBJS) $(MX_OBJS), $(MODULE_DIR)/$(f))

clean:
	rm -f $(M_OBJS) $(MX_OBJS) .*.o.flags *~ *bak *ASV

include $(KERNEL_LOCATION)/Rules.make
#
