-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
39 lines (28 loc) · 961 Bytes
/
Copy pathMakefile
File metadata and controls
39 lines (28 loc) · 961 Bytes
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
ROOT_DIR = $(CURDIR)
SRCDIR = src
DESTDIR = build
TARGET = remapper
KERNEL_DIR = /lib/modules/$(KERNEL_UNAME)/build
SOURCES = $(SRCDIR)/main.c
HEADERS = $(SRCDIR)/utils.h
# Depends on bin/include bin/*.c and bin/Kbuild
all: $(DESTDIR)/ $(subst $(SRCDIR),$(DESTDIR),$(SOURCES)) $(subst $(SRCDIR),$(DESTDIR),$(HEADERS)) $(DESTDIR)/Kbuild
$(MAKE) -C $(KERNEL_DIR) M=$(ROOT_DIR)/$(DESTDIR) modules
install: all
$(MAKE) -C $(KERNEL_DIR) M=$(ROOT_DIR)/$(DESTDIR) modules_install
remove:
rmmod $(TARGET)
# Create a symlink from src to bin
$(DESTDIR)/%: $(SRCDIR)/%
cp $(ROOT_DIR)/$< $@
dkms: install
cp $(DESTDIR)/*.ko .
# Create any needed folder
%/:
mkdir -p $@
# Generate a Makefile with the needed obj-m and mymodule-objs set
$(DESTDIR)/Kbuild:
printf "obj-m += $(TARGET).o\n$(TARGET)-y := $(subst $(TARGET).o,, $(subst .c,.o,$(subst $(SRCDIR)/,,$(SOURCES))))" > $@
clean:
make -C $(KERNEL_DIR) M=$(ROOT_DIR)/$(DESTDIR) clean
rm -rf $(DESTDIR)