How to build an Android Kernel

Step by step (similar to xda developer page http://forum.xda-developers.com/showthread.php?t=1538580)

1. Download Kernel source

http://opensource.samsung.com/
>> Mobile >> Mobile Phone>>  
Search for GT-I9300 and download latest JB zip

2. Extract Kernel from zip file

3. Install gcc toolchain for building arm kernels

# sudo apt-get install gcc-arm-linux-gnueabi 
 
download prebuilt toolchain (see http://source.android.com/source/building-kernels.html )
# git clone https://android.googlesource.com/platform/prebuilt
 
if you get an error like "undefined reference to `wrefresh'", install these packages:
# sudo apt-get install libncurses5 libncurses5-dev

4. set environment variables

# export ARCH=arm
# export SUBARCH=arm
# export CROSS_COMPILE=<path to toolchain from googlesource>/toolchains/arm-eabi-4.4.3/bin/arm-eabi-

5. configure build for Samsung galaxy S3

Switch to kernel source directory
# make m0_00_defconfig
 
//optional for configuration of the kernel
# make menuconfig

6. Start build

# make -j<X> //<X> number of cpu cores

7. create boot.img from the new zImage

For flashing the new kernel you will need a ramdisk image file from a working build (e.g. nandroid backup or own android source code build). To extract the ramdisk image use the attached perl script (./split_bootimg.pl ) by executing the command:
# perl split_bootimg.pl <boot image file with working ramdisk>
 
Copy the ramdisk image and your zImage in a separate directory together with the attached mkbootimg binary ./mkbootimg . Combine those files to a new boot.img by executing following command in the newly created directory:
# ./mkbootimg --kernel <zImage> --ramdisk <ramdisk image> --output boot.img

8. Flash the kernel

For flashing we used the open source tool heimdall version 1.3.1 for linux_x64 command line http://www.glassechidna.com.au/products/heimdall/ (! using 1.3.2 is not working on galaxy s3!). 
First bring the device into download mode by pressing volume down+menu+power key. Then check if heimdall detects the device:
# heimdall detect
you should see the message "Device detected". If the device is not detected ("Failed to detect compatible download-mode device.") try to restart the device and put it into download mode again. 
 
If this is working, flash it!
# heimdall flash --primary-boot boot.img