MO flag not working properly for building out-of-tree modules, tries to replace the Makefile in the kernel's source.
Anish Rashinkar <[email protected]> Thu, 16 Jul 2026 23:04:23 +0530
| Newsgroups | org.kernel.vger.linux-kbuild |
|---|---|
| Message-ID | <CAOESE2Q2-0KUDaM0mUo+c_F-tMaUsBZ-gpnhdoe0rmYdgnnuJQ@mail.gmail.com> |
I have a few projects in which I am writing kernel modules. I use the MO flag to put the build artifacts in a separate directory. A simple make command with MO would look like - make -C /lib/modules/$(uname -r)/build M=$PWD MO=$PWD/build/ modules This used to work for me, and still works for me if I boot into the 6.19.10-300 kernel that Fedora preserved. I was on 7.0.X for a while on Arch Linux and it worked there too. I am not sure but I might have tried compiling my projects (if so, compiled successfully) on Fedora Atomic that I was trying out, which should have been on 7.0 or 7.1. As of the latest kernels on both Arch Linux and Fedora (7.1.3-201 on Fedora), I encounter an error when using the MO flag. make -C /lib/modules/7.1.3-201.fc44.x86_64/build M=/home/anish/temp MO=/home/anish/temp/build modules make[1]: Entering directory '/usr/src/kernels/7.1.3-201.fc44.x86_64' make[2]: Entering directory '/home/anish/temp/build' /bin/sh: line 1: /usr/src/kernels/7.1.3-201.fc44.x86_64/.tmp_Makefile: Permission denied make[3]: *** [/usr/src/kernels/7.1.3-201.fc44.x86_64/Makefile:705: /usr/src/kernels/7.1.3-201.fc44.x86_64/Makefile] Error 1 make[2]: *** [/usr/src/kernels/7.1.3-201.fc44.x86_64/Makefile:248: __sub-make] Error 2 make[2]: Leaving directory '/home/anish/temp/build' make[1]: *** [Makefile:248: __sub-make] Error 2 make[1]: Leaving directory '/usr/src/kernels/7.1.3-201.fc44.x86_64' make: *** [Makefile:6: all] Error 2 If I grant root privileges to make, it will replace the Makefile at /usr/src/kernels/7.1.3-201.fc44.x86_64/Makefile with its own Makefile wrapper. If I don't use the MO flag, then the build succeeds and all the build artifacts are stored in my source directory. I am new to Linux programming and especially bug reporting like this. I had raised this issue on Fedora Discussions with no one to properly respond that helps the problem. This issue should have appeared relatively recently. Please let me know if this is a bug or something changed with how it should be used, because the official guides state the same way I mentioned in writing a Makefile and using the MO flag. And with what I can comprehend and with what all LLMs are saying, this is a bug.