emerge @module-rebuild rebuilds modules only for the current running kernel. This causes a double reboot for every new kernel. First compile and install the new kernel, then do a reboot. Second, execute emerge @module-rebuild and reboot again.
This is particularly bad as e.g. I do have a Laptop that refuses to display properly without the Nvidia drivers (using nouveau is not possibe due to Cuda requirements). Thus I do need a second system and remote access just to be able to do a kernel upgrade.
All modules I do need that are not within the Portage tree allow to specify either KVER or KSRC to build against a specific kernel.
A suggestion would be something like:
"emerge --kver=4.9.40-gentoo @module-rebuild"
We'd need some kind of support in linux-mod.eclass for this.
linux-info/linux-mod look at the KERNEL_DIR environment var to find a linux source tree to build against.
If you have set KERNEL_DIR to the new kernel source dir, or set the /usr/src/linux symlink, I would expect @module-rebuild to re-compile modules against the new kernel version, not the currently running kernel version.
Hmm, ok, the soft link version seems to work (tried with running 4.9.39 to build for 4.9.36) though I'm quite sure it didn't work the last time I tried this (well, quite some time ago).
Anyway, it would be nice if this behaviour would be documented somewhere, preferably the emerge man page.
Thanks for your patience.
It's documented here.
It would be nice to have some user docs on this, but that probably belongs on the wiki rather than in any portage documentation.
Don't think there's anything for kernel team to do here.