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

Commit b6dec7c

Browse files
committed
Add a Makefile to figure out the compiler flags for kernel builds
1 parent 556012a commit b6dec7c

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

kernel-cflags-finder/.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.built-in.o.cmd
2+
.dummy.ko.cmd
3+
.dummy.mod.o.cmd
4+
.dummy.o.cmd
5+
.tmp_versions/
6+
Module.symvers
7+
built-in.o
8+
dummy.c
9+
dummy.ko
10+
dummy.mod.c
11+
dummy.mod.o
12+
dummy.o
13+
modules.order

kernel-cflags-finder/Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ifneq ($(KERNELRELEASE),)
2+
obj-m += dummy.o
3+
clean-files := dummy.c
4+
5+
$(M)/dummy.c:
6+
@echo $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(__c_flags) $(modkern_cflags)
7+
@touch $@
8+
else
9+
KDIR ?= /lib/modules/$(shell uname -r)/build
10+
CLANG ?= clang
11+
all:
12+
$(MAKE) -C $(KDIR) M=$(CURDIR) CC=$(CLANG)
13+
clean:
14+
$(MAKE) -C $(KDIR) M=$(CURDIR) clean
15+
endif

kernel-cflags-finder/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Prints the compiler arguments needed to run Clang against the kernel
2+
headers. We use this for running libclang from bindgen.
3+
4+
Normal usage: run `make -s` and look at stdout (errors go to stderr). If
5+
you need to build for a specific set of kernel headers, add
6+
something like `KDIR=/lib/modules/3.16.0-4-amd64/build`. If your clang
7+
command is not `clang`, add something like `CLANG=clang-3.8`.
8+
9+
This generates a non-functional kernel module in the process. To clean
10+
up, `make clean`.

0 commit comments

Comments
 (0)