# For building for the current running version of Linux
TARGET		:= $(shell uname -r)
# Or specific version
#TARGET		:= 2.6.33.5
#TARGET		:= 2.6.32.15
KERNEL_MODULES	:= /lib/modules/$(TARGET)
KERNEL_BUILD	:= $(KERNEL_MODULES)/build

DRIVER := f71882ed

# Directory below /lib/modules/$(TARGET)/kernel into which to install
# the module:
# kernel 2.6.14 or later
MOD_SUBDIR = drivers/hwmon
# kernel 2.6.13 or earlier
#MOD_SUBDIR = drivers/i2c/chips

obj-m	:= $(DRIVER).o

#MAKEFLAGS	+= --no-print-directory
#CFLAGS		:= -DDEBUG -O2 -I$(KERNEL_BUILD)/include \
#		   -I$(KERNEL_BUILD)/include/asm/mach-default \
#		   -fomit-frame-pointer -fno-strict-aliasing
# This one is often needed for 64-bit kernels
#CFLAGS		+= -mcmodel=kernel

.PHONY: all install modules modules_install clean

all: modules

# Targets for running make directly in the external module directory:
modules clean:
	@$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) $@

install: modules_install

modules_install:
	test -d $(KERNEL_MODULES)/kernel/$(MOD_SUBDIR) || mkdir $(KERNEL_MODULES)/kernel/$(MOD_SUBDIR)
	cp $(DRIVER).ko $(KERNEL_MODULES)/kernel/$(MOD_SUBDIR)
	depmod -a -F $(KERNEL_BUILD)/System.map $(TARGET)
