Compile Kernel using AOSP's prebuilts
I've made symlinks to the missing OSX headers from the linux host ones and apparently it worked out well! In my setup I have sync'd the whole AOSP repo, which includes all prebuilts, but the ones that I am actually using to built the kernel are:
Missing Linux headers: gcc/linux-x86/host/x86_64-linux-glibc2.11-4.8
Cross compiler: gcc/darwin-x86/arm/arm-eabi-4.8/
Clone them so that the following directory tree is valid:
/prebuilts/
/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.8/
/prebuilts/gcc/darwin-x86/arm/arm-eabi-4.8/
Make sure you checkout the appropriate branch/tag, according to your Android target version.
Install the missing headers
Not sure if it's the proper way to do it, but putting the a bunch of linux headers in /usr/local/include resolves all issues. Don't forget to chmod +x the script.
install_headers.sh:
#!/bin/sh
PREBUILTS_DIR="/prebuilts" # fill in the path here!
PREBUILT_GCC=$PREBUILTS_DIR"/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.8"
KERNEL_HEADERS=$PREBUILT_GCC"/sysroot/usr/include"
HOST_HEADERS="/usr/local/include"
function install_header() {
header=$1
ln -s $KERNEL_HEADERS/$header $HOST_HEADERS/$header
}
# create symlinks for the missing headers
install_header elf.h
install_header features.h
# the following are folders (that contain headers)
install_header bits
install_header gnu
install_header linux
install_header asm
install_header asm-generic
Build the kernel
export PATH=/prebuilts/gcc/darwin-x86/arm/arm-eabi-4.8/bin:$PATH
export ARCH=arm
export SUBARCH=arm
export CROSS_COMPILE=arm-eabi-
# in this example it builds for N6
make shamu_defconfig
make -j8
Voila:
Kernel: arch/arm/boot/zImage-dtb is ready
My configuration
macOS Sierra 10.12.3
XCode: using MacOSX10.11.sdk, which allows building AOSP on mac
Target device: N6/shamu
AOSP branch: Marshmallow (updated mac_version.mk in build to allow using 10.12.3 sdk)