1 # For building for the current running version of Linux
2 TARGET := $(shell uname -r)
5 KERNEL_MODULES := /lib/modules/$(TARGET)
7 ifneq ("","$(wildcard /usr/src/linux-headers-$(TARGET)/*)")
9 KERNEL_BUILD := /usr/src/linux-headers-$(TARGET)
11 ifneq ("","$(wildcard /usr/src/kernels/$(TARGET)/*)")
13 KERNEL_BUILD := /usr/src/kernels/$(TARGET)
15 KERNEL_BUILD := $(KERNEL_MODULES)/build
19 #SYSTEM_MAP := $(KERNEL_BUILD)/System.map
20 SYSTEM_MAP := /boot/System.map-$(TARGET)
23 ifneq ("","$(wildcard .git/*)")
24 DRIVER_VERSION := $(shell git describe --long)
26 ifneq ("", "$(wildcard VERSION)")
27 DRIVER_VERSION := $(shell cat VERSION)
29 DRIVER_VERSION := unknown
34 DKMS_ROOT_PATH=/usr/src/$(DRIVER)-$(DRIVER_VERSION)
35 MODPROBE_OUTPUT=$(shell lsmod | grep it87)
37 # Directory below /lib/modules/$(TARGET)/kernel into which to install
39 MOD_SUBDIR = drivers/hwmon
40 MODDESTDIR=$(KERNEL_MODULES)/kernel/$(MOD_SUBDIR)
42 obj-m := $(patsubst %,%.o,$(DRIVER))
43 obj-ko := $(patsubst %,%.ko,$(DRIVER))
45 MAKEFLAGS += --no-print-directory
47 ifneq ("","$(wildcard $(MODDESTDIR)/*.ko.gz)")
50 ifneq ("","$(wildcard $(MODDESTDIR)/*.ko.xz)")
54 .PHONY: all install modules modules_install clean dkms dkms_clean
58 # Targets for running make directly in the external module directory:
60 IT87_CFLAGS=-DIT87_DRIVER_VERSION='\"$(DRIVER_VERSION)\"'
63 @$(MAKE) EXTRA_CFLAGS="$(IT87_CFLAGS)" -C $(KERNEL_BUILD) M=$(CURDIR) $@
66 @$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) $@
68 install: modules_install
71 mkdir -p $(MODDESTDIR)
72 cp $(DRIVER).ko $(MODDESTDIR)/
73 ifeq ($(COMPRESS_GZIP), y)
74 @gzip -f $(MODDESTDIR)/$(DRIVER).ko
76 ifeq ($(COMPRESS_XZ), y)
77 @xz -f $(MODDESTDIR)/$(DRIVER).ko
79 depmod -a -F $(SYSTEM_MAP) $(TARGET)
82 @sed -i -e '/^PACKAGE_VERSION=/ s/=.*/=\"$(DRIVER_VERSION)\"/' dkms.conf
83 @echo "$(DRIVER_VERSION)" >VERSION
84 @mkdir $(DKMS_ROOT_PATH)
85 @cp `pwd`/dkms.conf $(DKMS_ROOT_PATH)
86 @cp `pwd`/VERSION $(DKMS_ROOT_PATH)
87 @cp `pwd`/Makefile $(DKMS_ROOT_PATH)
88 @cp `pwd`/compat.h $(DKMS_ROOT_PATH)
89 @cp `pwd`/it87.c $(DKMS_ROOT_PATH)
90 @dkms add -m $(DRIVER) -v $(DRIVER_VERSION)
91 @dkms build -m $(DRIVER) -v $(DRIVER_VERSION)
92 @dkms install --force -m $(DRIVER) -v $(DRIVER_VERSION)
96 @if [ ! -z "$(MODPROBE_OUTPUT)" ]; then \
99 @dkms remove -m $(DRIVER) -v $(DRIVER_VERSION) --all
100 @rm -rf $(DKMS_ROOT_PATH)