diff --git a/build.sh b/build.sh index 3957ea4..945cb77 100755 --- a/build.sh +++ b/build.sh @@ -1,15 +1,38 @@ #!/bin/bash set -xe -OUT="$(realpath "$1" 2>/dev/null || echo 'out')" +BUILD_DIR= +OUT= + +while [ $# -gt 0 ] +do + case "$1" in + (-b) BUILD_DIR="$(realpath "$2")"; shift;; + (-o) OUT="$2"; shift;; + (-*) echo "$0: Error: unknown option $1" 1>&2; exit 1;; + (*) OUT="$2"; break;; + esac + shift +done + +OUT="$(realpath "$OUT" 2>/dev/null || echo 'out')" mkdir -p "$OUT" -TMP=$(mktemp -d) +if [ -z "$BUILD_DIR" ]; then + TMP=$(mktemp -d) + TMPDOWN=$(mktemp -d) +else + TMP="$BUILD_DIR/tmp" + mkdir -p "$TMP" + TMPDOWN="$BUILD_DIR/downloads" + mkdir -p "$TMPDOWN" +fi + HERE=$(pwd) SCRIPT="$(dirname "$(realpath "$0")")"/build -mkdir "${TMP}/system" -mkdir "${TMP}/partitions" +mkdir -p "${TMP}/system" +mkdir -p "${TMP}/partitions" source "${HERE}/deviceinfo" @@ -19,20 +42,21 @@ case $deviceinfo_arch in "x86") RAMDISK_ARCH="i386";; esac -TMPDOWN=$(mktemp -d) cd "$TMPDOWN" - git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9 -b pie-gsi --depth 1 + [ -d aarch64-linux-android-4.9 ] || git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9 -b pie-gsi --depth 1 GCC_PATH="$TMPDOWN/aarch64-linux-android-4.9" if [ -n "$deviceinfo_kernel_clang_compile" ] && $deviceinfo_kernel_clang_compile; then - git clone https://github.com/crdroidandroid/android_prebuilts_clang_host_linux-x86_clang-6875598 -b 10.0 --depth=1 linux-x86 + [ -d linux-x86 ] || git clone https://github.com/crdroidandroid/android_prebuilts_clang_host_linux-x86_clang-6875598 -b 10.0 --depth=1 linux-x86 CLANG_PATH="$TMPDOWN/linux-x86" fi - git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9 -b pie-gsi --depth 1 + [ -d arm-linux-androideabi-4.9 ] || git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9 -b pie-gsi --depth 1 GCC_ARM32_PATH="$TMPDOWN/arm-linux-androideabi-4.9" - - git clone "$deviceinfo_kernel_source" -b $deviceinfo_kernel_source_branch --depth 1 - curl --location --output halium-boot-ramdisk.img \ + KERNEL_DIR="$(basename "${deviceinfo_kernel_source}")" + KERNEL_DIR="${KERNEL_DIR%.*}" + [ -d "$KERNEL_DIR" ] || git clone "$deviceinfo_kernel_source" -b $deviceinfo_kernel_source_branch --depth 1 + + [ -f halium-boot-ramdisk.img ] || curl --location --output halium-boot-ramdisk.img \ "https://github.com/halium/initramfs-tools-halium/releases/download/continuous/initrd.img-touch-${RAMDISK_ARCH}" if [ -n "$deviceinfo_kernel_apply_overlay" ] && $deviceinfo_kernel_apply_overlay; then @@ -61,7 +85,9 @@ fi cp -av overlay/* "${TMP}/" "$SCRIPT/build-tarball-mainline.sh" "${deviceinfo_codename}" "${OUT}" "${TMP}" -rm -r "${TMP}" -rm -r "${TMPDOWN}" +if [ -z "$BUILD_DIR" ]; then + rm -r "${TMP}" + rm -r "${TMPDOWN}" +fi echo "done"