#!/bin/bash set -e build_directory="/build" function initializeSourceTree() { manifest="$1" branch="$2" repo init -u "$manifest" -b "$branch" } function repoSync() { repo sync } function getPrebuilts() { cd "$build_directory" gpg \ --keyserver pool.sks-keyservers.net \ --recv-key 7A029E54DD5DCE7A ./vendor/replicant/get-prebuilts } function buildToolchain() { cd "$build_directory" ./vendor/replicant/build-toolchain } function loadBuildVars() { source "$build_directory"/build/envsetup.sh } function lunchDevice() { device="$1" mode="$2" lunch replicant_"$device"-"${mode:-userdebug}" } function buildPackage() { device="$1" mode="$2" loadBuildVars lunchDevice "$device" "$mode" getPrebuilts cd "$build_directory" make -j ${threads:-4} bacon } function partialBuildPackage() { device="$2" sub_project="$3" cd "$build_directory"/"$sub_project" mm -B make -j ${threads:-4} snod } function cleanBuild() { cd "$build_directory" loadBuildVars make clean } cd "$build_directory" if [ $# -eq 0 ]; then echo -e "No parameter specified." exit 1 else while [ $# -ne 0 ]; do case $1 in -j | --threads ) threads="$2" shift ;; -i | --initialize ) manifest="$2" branch="$3" initializeSourceTree "$manifest" "$branch" shift shift ;; -p | --pull ) repoSync ;; -t | --build-toolchain ) buildToolchain ;; -b | --build ) device="$2" buildPackage "$device" shift ;; -B | --partial ) device="$2" sub_project="$3" partialBuildPackage "$device" "$sub_project" shift ;; -c | --clean ) cleanBuild ;; esac shift done fi