]> git.sur5r.net Git - groeck-it87/blob - Makefile
Add optional DKMS target to Makefile
[groeck-it87] / Makefile
1 # For building for the current running version of Linux
2 TARGET          := $(shell uname -r)
3 # Or specific version
4 #TARGET         := 2.6.33.5
5 KERNEL_MODULES  := /lib/modules/$(TARGET)
6
7 ifneq ("","$(wildcard /usr/src/linux-headers-$(TARGET)/*)")
8 # Ubuntu
9 KERNEL_BUILD    := /usr/src/linux-headers-$(TARGET)
10 else
11 ifneq ("","$(wildcard /usr/src/kernels/$(TARGET)/*)")
12 # Fedora
13 KERNEL_BUILD    := /usr/src/kernels/$(TARGET)
14 else
15 KERNEL_BUILD    := $(KERNEL_MODULES)/build
16 endif
17 endif
18
19 #SYSTEM_MAP     := $(KERNEL_BUILD)/System.map
20 SYSTEM_MAP      := /boot/System.map-$(TARGET)
21
22 DRIVER := it87
23 ifneq ("","$(wildcard .git/*)")
24 DRIVER_VERSION := $(shell git describe --long)
25 else
26 ifneq ("", "$(wildcard VERSION)")
27 DRIVER_VERSION := $(shell cat VERSION)
28 else
29 DRIVER_VERSION := unknown
30 endif
31 endif
32
33 # DKMS
34 DKMS_ROOT_PATH=/usr/src/$(DRIVER)-$(DRIVER_VERSION)
35 MODPROBE_OUTPUT=$(shell lsmod | grep it87)
36
37 # Directory below /lib/modules/$(TARGET)/kernel into which to install
38 # the module:
39 MOD_SUBDIR = drivers/hwmon
40 MODDESTDIR=$(KERNEL_MODULES)/kernel/$(MOD_SUBDIR)
41
42 obj-m   := $(patsubst %,%.o,$(DRIVER))
43 obj-ko  := $(patsubst %,%.ko,$(DRIVER))
44
45 MAKEFLAGS += --no-print-directory
46
47 ifneq ("","$(wildcard $(MODDESTDIR)/*.ko.gz)")
48 COMPRESS_GZIP := y
49 endif
50 ifneq ("","$(wildcard $(MODDESTDIR)/*.ko.xz)")
51 COMPRESS_XZ := y
52 endif
53
54 .PHONY: all install modules modules_install clean dkms dkms_clean
55
56 all: modules
57
58 # Targets for running make directly in the external module directory:
59
60 IT87_CFLAGS=-DIT87_DRIVER_VERSION='\"$(DRIVER_VERSION)\"'
61
62 modules:
63         @$(MAKE) EXTRA_CFLAGS="$(IT87_CFLAGS)" -C $(KERNEL_BUILD) M=$(CURDIR) $@
64
65 clean:
66         @$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) $@
67
68 install: modules_install
69
70 modules_install:
71         mkdir -p $(MODDESTDIR)
72         cp $(DRIVER).ko $(MODDESTDIR)/
73 ifeq ($(COMPRESS_GZIP), y)
74         @gzip -f $(MODDESTDIR)/$(DRIVER).ko
75 endif
76 ifeq ($(COMPRESS_XZ), y)
77         @xz -f $(MODDESTDIR)/$(DRIVER).ko
78 endif
79         depmod -a -F $(SYSTEM_MAP) $(TARGET)
80
81 dkms:
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)
93         @modprobe $(DRIVER)
94
95 dkms_clean:
96         @if [ ! -z "$(MODPROBE_OUTPUT)" ]; then \
97                 rmmod $(DRIVER);\
98         fi
99         @dkms remove -m $(DRIVER) -v $(DRIVER_VERSION) --all
100         @rm -rf $(DKMS_ROOT_PATH)