mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.33k stars 1.53k forks source link

Build linux kernel modules (ko) with Meson? #9084

Open Muffo opened 2 years ago

Muffo commented 2 years ago

This is clearly a question from some one who doesn't have much experience with the compilation of Linux kernel modules :)

I searched online and found tutorials on how these can be created using Makefile. However, I couldn't figure out if Meson also supports these builds.

I hate Makefiles and thought I would make one last attempt asking here: can I build Linux kernel modules with Meson?

eli-schwartz commented 2 years ago

The Linux kernel has a very robust... and fairly large... build system infrastructure. Part of that is a quite excellent extensibility system which lets you write a very tiny makefile of a single line and have it work: https://www.kernel.org/doc/html/latest/kbuild/modules.html

You can have an additional two lines for a target that actually runs uname -r and passes the right directory to a sub-make.

Duplicating this in meson is theoretically possible, however figuring out how to integrate with the kernel build system would be complicated and I'm not sure it's actually worth it.

eli-schwartz commented 2 years ago

If anyone is interested in writing a meson module for building kernel modules, that would be neat ;)

xclaesse commented 2 years ago

I remember having discussed using Meson's external-project module for that, but it does not seems to be a great fit. As far as I understand replacing kbuild is way too complicated, so the best we can do it wrap around make.

Muffo commented 2 years ago

Thanks for the inputs! If I understand, the recommendation would be to wrap the make with a custom target, right?

xclaesse commented 2 years ago

@Muffo yes, you still need to write the makefile, but you can call it from meson with custom_target().

Freed-Wu commented 2 weeks ago

I know xmake support linux kernel module https://github.com/xmake-io/xmake/issues/1902

Maybe meson can refer its commit to support it :smile: