I built this with Ubuntu 16.04 Xenial Beta. Some of the packages may be different depending on your version/distro.
Firstly, I had to install some packages:
sudo apt-get install git-core gcc-5-arm-linux-gnueabi sudo apt-get install libncurses5-dev
You can use GCC 5 on Xenial, but you might need 4.7 for anything older.
I then had to create a symbolic link to the build tool
sudo ln -s /usr/bin/arm-linux-gnueabi-gcc-5 /usr/bin/arm-linux-gnueabi-gcc
Clone all the things!
mkdir /mnt/raspberrypi cd /mnt/raspberrypi git clone https://github.com/raspberrypi/tools.git git clone https://github.com/raspberrypi/linux.git
So, I wanted to create a 4.5 Kernel, so I had to clone this specific branch:
git clone -b rpi-4.5.y https://github.com/raspberrypi/linux.git
After that, I started the compilation:
cd linux KERNEL=kernel7 make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf- bcm2709_defconfig
I'm told the following command is optional, but I think you need to select certain options to build specific modules and feautres:
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- menuconfig
Compile! The -j8 is the number of threads your CPU has. I have an Intel Core i7-6700T, so I have a 4c/8t CPU.
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- zImage modules dtbs -j8
Move the modules to your MicroSD card of the Pi
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- INSTALL_MOD_PATH=/media/steve/PI_ROOT modules_install scripts/mkknlimg arch/arm/boot/zImage /media/steve/PI_BOOT/$KERNEL.img cp arch/arm/boot/dts/*.dtb /media/steve/PI_BOOT/ cp arch/arm/boot/dts/overlays/*.dtb* /media/steve/PI_BOOT/overlays/ cp arch/arm/boot/dts/overlays/README /media/steve/PI_BOOT/overlays/
All done! Boot your Pi with the new Kernel.