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