[Android General] notiflux:
I know there are many of these guides on XDA, but when I wanted to learn how to compile ROMs, all those guides didn't help me out cause all those guides are for more advanced users. I will try to explain every step clearly.

Step 1: Prepare your PC for building Android

Here's a good guide how to do that. http://xdaforums.com/showthread.php?t=2639611

Follow this guide up to step 9, then return to this thread.

Step 2: Downloading the sources

First, in terminal type "mkdir <android>" and then "cd <android>". Replace <android> with the ROM name that you want to build. For example if you want to build omni, type "mkdir omni" and "cd omni". Now you created a directory called "omni" and switched to it. Now, pick a ROM that you want to build and go to its github page. Then search for a repository that has the word "manifest" in it (sometimes it's also just called "android"). Click on it. On the top, select the branch. Most times every branch is for a different android version. Select the latest android version (For this guide it's Android 5.1.1, so the branch most times is LP-5.1). Then scroll down to the readme, copy the command starting with "repo init" and paste it in your terminal. Now just type "repo sync" and it will download the sources. This will take time, since it's about 15gb that will be downloaded.

Step 3: Download the Device specific sources

Next, you have to download the device tree, the kernel and the vendor files. If you're lucky, someone already put together a roomservice.xml for your device where all the needed stuff is declared. Search for "<devicename> roomservice" and hopefully you'll find a github page with this file. If you do, download it and push it to <android>/.repo/local_manifests/. Then go back to the terminal and type "repo sync" again. This time it won't take that long. If there's no roomservice.xml for your device, You have to create it. The device tree and kernel most times can be found by going to github.com/CyanogenMod and searching for your brand. For example, if you have a Motorola Moto G 2nd Generation (codename titan), search for motorola and open android_device_motorola_titan (sources for titan), android_device_motorola_msm8226-common (sources for titan's chipset) and android_kernel_motorola_msm8226 (sources for the kernel of the chipset) in a new tab. Also you need the vendor files which can be found at github.com/TheMuppets. For motorola devices, open proprietary_vendor_motorola. Create a new file on your desktop called "roomservice.xml" and open it. Paste this:

<?xml version="1.0" encoding="UTF-8"?>
<manifest>

<project name="" path="" remote="github" revision="cm-12.1" />
<project name="" path="" remote="github" revision="cm-12.1" />
<project name="" path="" remote="github" revision="cm-12.1" />
<project name="" path="" remote="github" revision="cm-12.1" />
</manifest>

Then go back to the github pages, copy the names of the repositorys and paste <project-name-on-github>/<name-of-the-repository> in the quotes after "name=". For titan, it would look like this:

<?xml version="1.0" encoding="UTF-8"?>
<manifest>

<project name="CyanogenMod/android_device_motorola_titan" path="" remote="github" revision="cm-12.1" />
<project name="CyanogenMod/android_device_motorola_msm8226-common" path="" remote="github" revision="cm-12.1" />
<project name="CyanogenMod/android_kernel_motorola_msm8226" path="" remote="github" revision="cm-12.1" />
<project name="TheMuppets/proprietary_vendor_motorola" path="" remote="github" revision="cm-12.1" />
</manifest>

Now for the path, just copy the name of the repository, remove "android_" or "proprietary_" and replace each "_" with a "/"

<?xml version="1.0" encoding="UTF-8"?>
<manifest>

<project name="android_device_motorola_titan" path="device/motorola/titan" remote="github" revision="cm-12.1" />
<project name="android_device_motorola_msm8226-common" path="device/motorola/msm8226-common" remote="github" revision="cm-12.1" />
<project name="android_kernel_motorola_msm8226" path="kernel/motorola/msm8226" remote="github" revision="cm-12.1" />
<project name="proprietary_vendor_motorola" path="vendor/motorola" remote="github" revision="cm-12.1" />
</manifest>

Sometimes you need some more repositorys, for example for titan you also need android_hardware_qcom_fm and android_device_qcom_common. Add them the same way as you added all the other sources. You can find out which repositorys you need by opening cm.dependencies in your decive- and chipset sources.

Now save the file and push it to "<android>/.repo/local_manifests/". Now return to your terminal and type "repo sync" again.

Step 4: Edit the device tree

You have to edit the device tree so that it fits to the ROM that you want to build. Go to <android>/vendor. In there you will find a folder with the abbreviation for the ROM. For example for CarbonROM the abbreviation is carbon, for EuhoriaOS it's eos, for AOKP it's aokp and for CyanogenMod it's cm. Remember this abbreviation. Back in terminal, type "cd device/<brand-you-are-building-for>/<phone-you-are-building-for>/" and then "mv cm.mk <remembered-abbreviation>.mk" and "mv cm.dependencies <remembered-abbreviation>.dependencies". After that, type "nano <remembered-abbreviation>.mk" and replace "cm" with "<remembered-abbreviation>" where ever you see it. To save the file, hit Ctrl+O, then Enter and then Ctrl+X. Now type "cd .." and then "cd <chipset-you-are-building-for>. Now, type "mv cm.dependencies <remembered-abbreviation>.dependencies" again.

Step 5: Building

We finally arrived there! To build our ROM, in terminal type ". build/envsetup.sh" and then "brunch <codename-for-your-device>".

This process takes time, depending on your PC specs. On my PC (2 cores, 3gb RAM), building takes about 8h. On my friends Server (12 cores, 128gb RAM), building takes about 20 mins.

Happy building!

Credits:

[MENTION=5139849]Sarath280[/MENTION] for teaching me how to build ROMs

My dad for teaching me everything else aboout technology

[MENTION=2645562]sylentprofet[/MENTION] for the guide how to prepare linux to build Android