I think this is right, but I can't be 100% sure.
I've tested the execution of the script itself on 32-bit Raspberry Pi OS running on a Pi400 and on 64-bit Raspberry Pi OS running on a Pi4B, but haven't checked any other Pis. And I've also not tried building any actual out-of-tree kernel modules.
This PR is almost 3 years old now, so is probably woefully outdated, and I have no interest in updating it. So closing.
(but if somebody else wants to pick up this code and update it, that's fine by me)
I think this is right, but I can't be 100% sure. I've tested the execution of the script itself on 32-bit Raspberry Pi OS running on a Pi400 and on 64-bit Raspberry Pi OS running on a Pi4B, but haven't checked any other Pis. And I've also not tried building any actual out-of-tree kernel modules.
But it should fix the issues with
rpi-source
identified in https://github.com/raspberrypi/Raspberry-Pi-OS-64bit/issues/4#issuecomment-717538559