[Nexus 6  General] Stephen:
Building CM12 from source for the Nexus 6 Shamu!

Thanks goes to @scrosler and @GROGG88 and @sykopompos for their amazing guide

[Guide][1/19/2015] Buulding AOSP for the Nexus 6!​

This guide will walk you through, how to build CM12 for the Nexus 6 from source. To complete this, you will need a PC with either virtual box setup and Ubuntu or duel boot Windows and Ubuntu. I recommend duel booting as it gets better results.​

Ideally your PC will need a minimum of an I5 processor and 8GB of ram. I won't go into too much detail on how to setup Ubuntu on your PC. For this guide, you do need to know the basic commands and how to use Ubuntu.

This guide is very similar in process to @scrosler and @GROGG88 and @sykopompos amazing guide here: [Guide][1/19/2015] Building AOSP for the Nexus 6! Through the use of their guide and asking a lot of questions on their thread, I was able to learn how to build AOSP from source. My guide is to complement their guide and show you how to build CM12, I found switching from AOSP to CM12 fairly easy, but there were a few changes in the process.

For my guide I will be using CM12 build guide as reference for the commands. How To Build CyanogenMod Android for Google Nexus 6 ("shamu") Even their guide is not 100% up to date, so I had to make a few changes.

So assuming you have Ubuntu 14.* set up, you will need to now set up your build environment:

First on their guide it talks about installing the SDK tools. You do not need these to build the ROM. You only really need ADB commands. I installed fastboot as well.

Install ADB command

sudo apt-get install android-tools-adb

Install Fastboot command

sudo apt-get install android-tools-fastboot

Install Java

sudo apt-get install openjdk-7-jdk

Setting up the build enviroment

bison build-essential curl flex git gnupg gperf libesd0-dev liblz4-tool libncurses5-dev libsdl1.2-dev libwxgtk2.8-dev libxml2 libxml2-utils lzop openjdk-6-jdk openjdk-6-jre pngcrush schedtool squashfs-tools xsltproc zip zlib1g-dev

If you have a 64bit PC install the following:

g++-multilib gcc-multilib lib32ncurses5-dev lib32readline-gplv2-dev lib32z1-dev

Setting your build directory - This can be any folder you want. for my example I will use android as my root folder. Remember that Ubuntu is case sensitive when switching folders.

mkdir -p ~/bin
mkdir -p ~/android

Install Repo

curl [URL]https://storage.googleapis.com/git-repo-downloads/repo[/URL] > ~/bin/repo
chmod a+x ~/bin/repo

Put the ~/bin directory in your path of execution - In recent versions of Ubuntu, ~/bin should already be in your PATH. You can check this by opening ~/.profile with a text editor and verifying the following code exists (add it if it is missing):

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi

Now for the good bit! We are about to download the source for cm12. Warning: The download is large and will take a long time to download. I have a 38mb fiber connection and unlimited data plan, so it is ok for me to download. I believe the download is 16gb+ in size, so you will have to take this into consideration. Note: I will not be held responsible if you go over your payment plan with your service provider. This is were I have had to start changing the guide a bit as CM's document is for building CM11. It has not been updated to CM12 yet.

Identify Yourself to the Repo

git config --global user.email "you@youremailaddress.com"
git config --global user.name "yourpreferredusername"

Initialize the CyanogenMod source repository

cd ~/android [B]- this is your root folder[/B]
repo init -u [URL]https://github.com/CyanogenMod/android.git[/URL] -b cm-12.0

Download the source code - Note this will take a while, as mentioned it is over 16gb in size. Even with my connection it takes about an hour and a half to download, so time for coffee!

repo sync

If repo sync errors and stops during download, don't worry you can simply run the command again and it will pick up were it left off. If you get a lot of errors during download, I recommend using

repo sync -j1

This seems to download the source better. When you have completed the download run it again, to make sure it completes with out any errors. This way you know you have downloaded the full source code.

Backup your home directory

Also at this point, what I do is make a backup using the inbuilt backup software in ubuntu. This backs up my entire home directory to a secondary hard drive I have set up in my PC. This way if I have any issues and need to start from scratch, I can simply delete my android directory, then restore from backup. I then have a fresh working copy and don't have to spend time downloading source from CM12 again. I would also recommend this as part of scrosler's guide as well, when you have finished downloading AOSP source.

Vendor and device specific files

Now this is were the cm12 guide starts to differ a bit from AOSP. AOSP you have to download the vendor files and extract them and then add in missing ones as well. CM12 differs here. At this point I would recommend having CM12 on your Nexus 6. It uses ADB to pull files from your phone and set up the device specific files and the vendor files. I found having CM12 on the phone made life easier at this point. You can use my ROM as an example here: [ROM][5.0.2][CM12 - Android L][LRX22G] Version 1.0.0 - [8/03/2015] - Native LED's

cd ~/android
source build/envsetup.sh
breakfast shamu

Extract proprietary blobs

Now ensure that your Nexus 6 is connected to your computer via the USB cable and that you are in the ~/android/device/moto/shamu directory, then run the extract-files.sh script

cd ~/android/device/moto/shamu
./extract-files.sh

Turn on caching to speed up build

You can speed up subsequent builds by adding: the following command to your to your .bashrc file To do this close your terminal window and then reopen and type ./.bashrc - A text editor will open. Add this line to the bottom of the page.

export USE_CCACHE=1

Close the text editor and save the file

Then in the command window type the following. CM12 recommend 50GB, but you can change to what ever you want.

prebuilts/misc/linux-x86/ccache/ccache -M 50G

Building CM12!!!!

Now you are all set to start building CM12. You have everything you need. So run the following commands:

cd ~\android
source build/envsetup.sh
brunch shamu

Thats it! CM12 is now building. This will take some time to build. I do recommend a duel boot PC as it works better than in Virtual Box. Even in my PC it takes about an hour and a half to do a fresh build and about 15 minutes to do a dirty build.

So once the build finishes you now have a flash-able version of CM12 from their latest source that you can flash on your Nexus 6 - Congratulations - you are now among the elite who can build their own ROM from source :D

The zip file is stored in the following directory:

cd ~/android/out/target/product/shamu/cm-12-20150308-UNOFFICIAL-shamu.zip

The file name will depend on the day you build the ROM, so it may be slightly different.

Here is an example output of a successful build of CM12!

​

Note of caution here:

Now that you have built CM12 as in AOSP I would not recommend flashing at this stage, it will make the following changes to your phone:

Install stock recovery

Encrypt your phone

To get around these we will need to make the following changes. See post 2 on how to make the changes.