Tip:
Highlight text to annotate it
X
Why download the pre-built CyanogenMod when you can experiment with the code and build it yourself?
CyanogenMod is based on AOSP: the Android Open Source Project. One of the best things about Android is that, if you have a Nexus device, you can download the source code and compile it yourself. This means you can change the code exactly where you want, re-compile and then deploy it to your device.
As CyanogenMod is based on AOSP and everything is open source, the same thing applies.
However, there is no such reliance on owning a Nexus as many more devices are supported. In order to use this tutorial, you should ensure that your device is on the official supported list at wiki. cyanogenmod.org/w/Devices.
In order to build the code, you'll need a relatively powerful PC (Windows, Mac or Linux) ideally with 8GB RAM or more, at least 50GB free disk space and a good internet connection too!
Install prerequisites
Android builds best on Linux, so try to use a Linux machine or VM. Download and install the Android SDK from goo.gl/2qpr and the required build packages listed at goo.gl/gtrYW. Finally, you need to install repo, which is used to actually check out the CyanogenMod code
Download source code
Create a directory to download the source into, ‘mkdir ~/android/system/’. Change to that directory and use the installed repo command to get the source code - repo init -u https://github.com/CyanogenMod/android.git -b cm-12.1 downloads CyanogenMod 12.1.
Device-specific code
Set up the build environment with the source build/envsetup.sh command then grab the device-specific code. You need to know the codename for your device from the supported device list. For the Nexus 5, aka ‘hammerhead’, use the command breakfast hammerhead.
Extract proprietary files
Building CyanogenMod requires closed source proprietary files that Cyanogen doesn’t have permission to distribute, so extract these from your device. Connect your device, ensure ADB is working then run the ./extract-files.sh script that will pull the files to your PC.
Build the code!
You should be ready to go! Use the export USE_CCACHE=1 command to speed up future builds then croot and brunch hammerhead (replacing the codename with your device’s one) to launch the build process. The compilation process will take a long time.
Deploy to your device
In the ‘out’ directory you’ll see a file with a name like cm-12.1-20151001-UNOFFICIAL-hammerhead.zip. This is a ROM ZIP that can be installed via your custom recovery (either CyanogenMod or TWRP) as normal. Remember you need GApps installed for the full experience!