Addition to the above comment by sarnold, I tried with the 5.4 kernel, and that seemed to compile ok. But it still fails for 5.11 installed on the same system, regardless of changing $KERNELS to $CURRENT_KERNEL. Here is some relevant output:
sudo apt install nvidia-340 # after installing and booting linux 5.4 https://paste.ubuntu.com/p/HqJjsQk7hN/ contents of /var/lib/dkms/nvidia-340/340.108/build/make.log https://paste.ubuntu.com/p/nGtrn67VBJ/ -- You received this bug notification because you are a member of Ubuntu-X, which is subscribed to nvidia-graphics-drivers in Ubuntu. https://bugs.launchpad.net/bugs/1853977 Title: nvidia-340 dpkg: error: version '-' has bad syntax: revision number is empty To manage notifications about this bug go to: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1853977/+subscriptions _______________________________________________ Mailing list: https://launchpad.net/~ubuntu-x-swat Post to : [email protected] Unsubscribe : https://launchpad.net/~ubuntu-x-swat More help : https://help.launchpad.net/ListHelp

