For example,
sudo apt-get install -y wget xz-utils
wget https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.9.28.tar.xz
tar xf linux-4.9.28.tar.xz
Patch the files, add code, … etc.
Copy current setting.
sudo cat /boot/config-`uname -r` > .config
make olddefconfig
make -j4
make -j4 modules
sudo make modules_install
sudo make install
Files will be written to /boot
directory.
Reboot the computer. If anything goes wrong, reboot again and select original kernel.