Skip to content
This repository was archived by the owner on Mar 7, 2021. It is now read-only.

Commit 4432fa5

Browse files
nathansgreengeofft
authored andcommitted
Parameterize the kernel module build dir in all makefiles.
Builds that can target kernels besides the currently running one cannot work when the path is hard-coded to use (uname -r). Define KDIR parameter and set a default value if it is undefined.
1 parent d0f609e commit 4432fa5

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

example-sysctl/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
obj-m := examplesysctl.o
22
examplesysctl-objs := target/x86_64-linux-kernel-module/debug/libexample_sysctl.a
33
EXTRA_LDFLAGS += --entry=init_module
4+
KDIR ?= /lib/modules/$(shell uname -r)/build
45

56
all:
6-
$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(CURDIR)
7+
$(MAKE) -C $(KDIR) M=$(CURDIR)
78

89
clean:
9-
$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(CURDIR) clean
10+
$(MAKE) -C $(KDIR) M=$(CURDIR) clean

hello-world/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
obj-m := helloworld.o
22
helloworld-objs := target/x86_64-linux-kernel-module/debug/libhello_world.a
33
EXTRA_LDFLAGS += --entry=init_module
4+
KDIR ?= /lib/modules/$(shell uname -r)/build
45

56
all:
6-
$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(CURDIR)
7+
$(MAKE) -C $(KDIR) M=$(CURDIR)
78

89
clean:
9-
$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(CURDIR) clean
10+
$(MAKE) -C $(KDIR) M=$(CURDIR) clean

static-filesystem/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
obj-m := staticfilesystem.o
22
staticfilesystem-objs := target/x86_64-linux-kernel-module/debug/libstatic_filesystem.a
33
EXTRA_LDFLAGS += --entry=init_module
4+
KDIR ?= /lib/modules/$(shell uname -r)/build
45

56
all:
6-
$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(CURDIR)
7+
$(MAKE) -C $(KDIR) M=$(CURDIR)
78

89
clean:
9-
$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(CURDIR) clean
10+
$(MAKE) -C $(KDIR) M=$(CURDIR) clean

tests/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
obj-m := testmodule.o
22
testmodule-objs := $(TEST_LIBRARY)
33
EXTRA_LDFLAGS += --entry=init_module
4+
KDIR ?= /lib/modules/$(shell uname -r)/build
45

56
all:
6-
$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(CURDIR)
7+
$(MAKE) -C $(KDIR) M=$(CURDIR)
78

89
clean:
9-
$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(CURDIR) clean
10+
$(MAKE) -C $(KDIR) M=$(CURDIR) clean

0 commit comments

Comments
 (0)