1 # For building for the current running version of Linux
2 TARGET := $(shell uname -r)
3 KERNEL_MODULES := /lib/modules/$(TARGET)
5 ifneq ("","$(wildcard /usr/src/linux-headers-$(TARGET)/*)")
7 KERNEL_BUILD := /usr/src/linux-headers-$(TARGET)
9 ifneq ("","$(wildcard /usr/src/kernels/$(TARGET)/*)")
11 KERNEL_BUILD := /usr/src/kernels/$(TARGET)
13 KERNEL_BUILD := $(KERNEL_MODULES)/build
17 SYSTEM_MAP := /boot/System.map-$(TARGET)
21 # Directory below /lib/modules/$(TARGET)/kernel into which to install
23 MOD_SUBDIR = drivers/hwmon
24 MODDESTDIR=$(KERNEL_MODULES)/kernel/$(MOD_SUBDIR)
26 obj-m := $(patsubst %,%.o,$(DRIVER))
27 obj-ko := $(patsubst %,%.ko,$(DRIVER))
29 MAKEFLAGS += --no-print-directory
31 ifneq ("","$(wildcard $(MODDESTDIR)/*.ko.gz)")
34 ifneq ("","$(wildcard $(MODDESTDIR)/*.ko.xz)")
38 .PHONY: all install modules modules_install clean
42 # Targets for running make directly in the external module directory:
45 @$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) $@
47 install: modules_install
50 mkdir -p $(MODDESTDIR)
51 cp $(DRIVER).ko $(MODDESTDIR)/
52 ifeq ($(COMPRESS_GZIP), y)
53 @gzip -f $(MODDESTDIR)/$(DRIVER).ko
55 ifeq ($(COMPRESS_XZ), y)
56 @xz -f $(MODDESTDIR)/$(DRIVER).ko
58 depmod -a -F $(SYSTEM_MAP) $(TARGET)