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

Commit f7443bf

Browse files
committed
Link helpers into the linux_kernel_module library
This saves us needing to manually link them in every individual kernel module's Makefile
1 parent 9486f3c commit f7443bf

File tree

5 files changed

+13
-2
lines changed

5 files changed

+13
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ bitflags = "1"
88

99
[build-dependencies]
1010
bindgen = "*"
11+
cc = "1.0"
1112
shlex = "0.1"

build.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
extern crate bindgen;
2+
extern crate cc;
23
extern crate shlex;
34

45
use std::env;
@@ -66,4 +67,13 @@ fn main() {
6667
bindings
6768
.write_to_file(out_path.join("bindings.rs"))
6869
.expect("Couldn't write bindings!");
70+
71+
let mut builder = cc::Build::new();
72+
println!("cargo:rerun-if-env-changed=CLANG");
73+
builder.compiler(env::var("CLANG").unwrap_or("clang".to_string()));
74+
builder.file("src/helpers.c");
75+
for arg in shlex::split(&output).unwrap() {
76+
builder.flag(&arg);
77+
}
78+
builder.compile("helpers");
6979
}

hello-world/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
obj-m := helloworld.o
2-
helloworld-objs := target/x86_64-linux-kernel-module/debug/libhello_world.a ../src/printk_helper.o
2+
helloworld-objs := target/x86_64-linux-kernel-module/debug/libhello_world.a
33
EXTRA_LDFLAGS += --gc-sections --entry=init_module --undefined=cleanup_module
44

55
all:
File renamed without changes.

static-filesystem/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
obj-m := staticfilesystem.o
2-
staticfilesystem-objs := target/x86_64-linux-kernel-module/debug/libstatic_filesystem.a ../src/printk_helper.o
2+
staticfilesystem-objs := target/x86_64-linux-kernel-module/debug/libstatic_filesystem.a
33
EXTRA_LDFLAGS += --gc-sections --entry=init_module --undefined=cleanup_module
44

55
all:

0 commit comments

Comments
 (0)