Here is how I managed to get CyanogenMod on my Galaxy S4 – the Japanse DoCoMo model.

Starting back to front, the short version is:

Get the repo command, and get ready to compile CyanogenMod as usual

repo init -u git://github.com/CyanogenMod/android.git -b cm-10.2

Prep the extra repositories needed to compile the Samsung phone model.

$ cat .repo/local_manifests/s4.xml
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
  <project path="device/samsung/jf-common"      name="kbc-developers/android_device_samsung_jf-common"   />
  <project path="device/samsung/jfltedcm"       name="kbc-developers/android_device_samsung_jfltedcm"    />
  <project path="device/samsung/msm8960-common" name="CyanogenMod/android_device_samsung_msm8960-common" />
  <project path="device/samsung/qcom-common"    name="CyanogenMod/android_device_samsung_qcom-common"    />
  <project path="hardware/samsung"              name="CyanogenMod/android_hardware_samsung"              />
  <project path="kernel/samsung/jf"             name="CyanogenMod/android_kernel_samsung_jf"             />
  <project path="kernel/samsung/jfdcm"          name="kbc-developers/android_kernel_samsung_jfdcm" revision="kbc-aosp-jb-mr2" />
  <project path="vendor/samsung"                name="kbc-developers/proprietary_vendor_samsung"         />
</manifest>

Note that I am using a few of the kbc-developers’ repositories. These have important updates for the DoCoMo phone model.

On that note, it doesn’t really matter which kernel is to be used (the jfdcm DoCoMo customized version modded by KBC, or the official jf version), but I thought I’d go go with KBC’s one, since it had some updates for the NFC, and I was hoping to get the NFC working.

As I was trying to replicate the binary releases that KBC published, I also had to disable SELINUX by adding the following line to device/samsung/jfltedcm/BoardConfig.mk:

TARGET_KERNEL_SELINUX_CONFIG :=

And to actually allow the boot partition to be flashed, I had to register my phone’s bootloader in device/samsung/msm8960-common/loki_bootloaders. Just append this text to the file:

# DoCoMo
bootloader=SC04EOMUAMDI
bootloader=SC04EOMUAMF1

Once all this is done, building CyanogenMod as usual worked just fine. I source the following file to do the trick, where $HOME/android/cm-10.2 is where I ran the repo init command:

export USE_CCACHE=1
export CCACHE_DIR=$HOME/android/ccache
export OUT_DIR_COMMON_BASE=$HOME/android/out
export PATH=$PATH:$HOME/android/bin
export ANDROID_JAVA_HOME=/etc/java-config-2/current-system-vm
export CM_BUILDTYPE="chutz"
cd $HOME/android/cm-10.2
. build/envsetup.sh
breakfast jfltedcm
TOP=$T

Inside $HOME/android/bin I keep a copy of the repo command itself.

External links I found useful