# For building for the current running version of Linux TARGET := $(shell uname -r) # Or specific version #TARGET := 3.4.16 #TARGET := 3.0.39 #TARGET := 2.6.32.57 KERNEL_MODULES := /lib/modules/$(TARGET) KERNEL_BUILD := $(KERNEL_MODULES)/build SYSTEM_MAP := $(shell if test -r /boot/System.map-$(TARGET) ; then echo /boot/System.map-$(TARGET) ; else echo $(KERNEL_BUILD)/System.map ; fi) DRIVER := it87 # Directory below /lib/modules/$(TARGET)/kernel into which to install # the module: MOD_SUBDIR = drivers/hwmon obj-m := $(DRIVER).o .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 # Backup original module if it exists modules_install: test -d $(KERNEL_MODULES)/kernel/$(MOD_SUBDIR) || mkdir $(KERNEL_MODULES)/kernel/$(MOD_SUBDIR) if test -f $(KERNEL_MODULES)/kernel/$(MOD_SUBDIR)/$(DRIVER).ko -a ! -f $(KERNEL_MODULES)/kernel/$(MOD_SUBDIR)/$(DRIVER)_original.ko ; \ then \ cp -a $(KERNEL_MODULES)/kernel/$(MOD_SUBDIR)/$(DRIVER).ko $(KERNEL_MODULES)/kernel/$(MOD_SUBDIR)/$(DRIVER)_original.ko ; \ fi cp $(DRIVER).ko $(KERNEL_MODULES)/kernel/$(MOD_SUBDIR) depmod -a -F $(SYSTEM_MAP) $(TARGET) uninstall: modules_uninstall # Restore original module if it exists modules_uninstall: rm -f $(KERNEL_MODULES)/kernel/$(MOD_SUBDIR)/$(DRIVER).ko if test -f $(KERNEL_MODULES)/kernel/$(MOD_SUBDIR)/$(DRIVER)_original.ko ; \ then \ mv $(KERNEL_MODULES)/kernel/$(MOD_SUBDIR)/$(DRIVER)_original.ko $(KERNEL_MODULES)/kernel/$(MOD_SUBDIR)/$(DRIVER).ko ; \ fi depmod -a -F $(SYSTEM_MAP) $(TARGET)