-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
70 lines (53 loc) · 2.37 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Add compiler flag(s)!
ccflags-y += -frecord-gcc-switches -fdiagnostics-color=always
ccflags-y += -save-temps=obj -fverbose-asm -Wall -Werror
ccflags-y += -Wall -Werror -std=gnu11 -D_GNU_SOURCE
ccflags-y += -O2 -DNDEBUG -march=native -ftree-vectorize -fvect-cost-model=very-cheap -Wl,--strip-all
ccflags-y += -I/usr/include -I/usr/local/include
ccflags-y += -L/lib/modules/$(KVER)/updates/dkms
ccflags-y +=
ldflags-y +=
# Add path(s) of external C source or static library file(s) to temporarily copy to the local build directory!
EXTERN-HEADER :=
EXTERN-OBJECT :=
EXTERN-SOURCE :=
# DO NOT EDIT THE BELOW!
SHELL := /bin/bash
M ?= $(shell pwd)
KVER ?= $(shell uname -r)
KDIR ?= /lib/modules/$(shell uname -r)/build
TARGET := $(shell grep '^PACKAGE_NAME=' $(M)/dkms.conf | cut -d'=' -f2 | tr -d '"')
PACKAGE_VERSION := $(shell grep '^PACKAGE_VERSION=' $(M)/dkms.conf | cut -d'=' -f2 | tr -d '"')
ccflags-y += -D__PACKAGE_VERSION__=\"$(PACKAGE_VERSION)\"
EXTERN := $(EXTERN-HEADER) $(EXTERN-OBJECT) $(EXTERN-SOURCE)
# These will be passed to the Makefile of the kernel source.
MY-SRCS += $(filter-out $(wildcard $(M)/*.mod.c), $(wildcard $(M)/*.c))
MY-OBJS += $(MY-SRCS:.c=.o)
obj-m += $(TARGET).o
$(TARGET)-objs += $(notdir $(MY-OBJS)) $(notdir $(EXTERN-OBJECT))
all:
-[[ "$(M)" != *"/dkms/"* ]] && rm -rf $(notdir $(EXTERN))
cp -r $(EXTERN) $(M)/ 2>/dev/null || :
make -C $(KDIR) KVER=$(shell uname -r) KDIR=/lib/modules/$(shell uname -r)/build M=$(shell pwd) modules
ar -rcs $(TARGET).a $(MY-OBJS)
cp /var/lib/dkms/$(TARGET)/$(PACKAGE_VERSION)/build/$(TARGET).a /lib/modules/$(KVER)/updates/dkms/ 2>/dev/null || :
rm -rf $(notdir $(EXTERN))
install:
rm -rf $(notdir $(EXTERN))
cp -r $(EXTERN) $(M)/ 2>/dev/null || :
dkms install "$(M)" --force && cp *.rules /etc/udev/rules.d/ 2>/dev/null || :
rm -rf $(notdir $(EXTERN))
uninstall:
dkms remove $(TARGET)/$(shell cat dkms.conf | grep PACKAGE_VERSION | sed 's/^[^\.]\+\=//' | sed -e 's/["]//g') --all --force || :
rm -rf /usr/src/$(TARGET)-$(PACKAGE_VERSION)
rm -f /lib/modules/$(KVER)/updates/dkms/$(TARGET).a
rm -f $(shell printf " /etc/udev/rules.d/%s" $(notdir $(shell ls $(M)/*.rules 2>/dev/null))) 2>/dev/null || :
load: all
insmod $(TARGET).ko
unload:
rmmod $(TARGET)
clean:
make -C $(KDIR) KVER=$(shell uname -r) KDIR=/lib/modules/$(shell uname -r)/build M=$(shell pwd) clean
rm -rf $(notdir $(EXTERN))
distclean:
git clean -xdf