#!/bin/bash

test -z "$1" && echo "Usage: ./build.sh exynos8895" && exit 1
test ! -f '/opt/python2.7/python' && echo -e "You have no Python where NHLOS expected.\nUse 'sudo mkdir /opt/python2.7; sudo ln -fs $(which python) /opt/python2.7/python' to fix it." && exit 1

cur="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
KMSRK_ROOT_PATH=${cur%/keymint*}

source $KMSRK_ROOT_PATH/keymint/swd/env_swd.sh "$1" || exit 1

# Note, $SWD_SIGN_ONLY and $SWD_BUILD_ONLY are used on CI
if [[ -z "${SWD_SIGN_ONLY}" ]]; then
    test "$V" == "1" && opt="-j16"
    make -C $KM_ROOT_PATH/swd distclean
    make -C $KM_ROOT_PATH/swd ${opt} || exit 1
fi

if [[ -z "${SWD_BUILD_ONLY}" ]]; then
  make -C $KM_ROOT_PATH/swd sign || exit 1
fi
