#!/bin/bash
###############################################################################
# Copyright (C) Intel Corporation
#
# SPDX-License-Identifier: MIT
###############################################################################
# Clean cpu.

if [ -z "$BASH_VERSION" ]
then
  echo "This script must be run under bash"
  exit 1
fi

if [ "$0" = "$BASH_SOURCE" ]
then
  set -o errexit
else
  echo "Warning: This script should not be sourced. Skipping exit on error."
fi


SCRIPT_DIR="$( cd "$(dirname "${BASH_SOURCE[0]:-$0}")" >/dev/null 2>&1 ; pwd -P )"

# Read command line options
. "${SCRIPT_DIR}/_buildopts.sh" \
    --name clean \
    --desc "Clean cpu." \
    -- "$@"

###############################################################################
# Globals
if [ -z "${VPL_CPU_DEPS_BUILD_DIR}" ]
then
  VPL_CPU_DEPS_BUILD_DIR="${PROJ_DIR}/_extbuild"
fi

if [ -z "${VPL_BUILD_DEPENDENCIES}" ]
then
  VPL_BUILD_DEPENDENCIES="${PROJ_DIR}/_deps"
fi

if [ -z "${VPL_CPU_BUILD_DIR}" ]
then
  VPL_CPU_BUILD_DIR="${PROJ_DIR}/_build"
fi
###############################################################################


if [ -n "${BOOTSTRAP_OPT}" ]
then
  if [ -e "${VPL_BUILD_DEPENDENCIES}" ]
  then
      echo "Cleaning dependencies cache folder..."
      rm -rf "${VPL_BUILD_DEPENDENCIES}"
  fi
  if [ -e "${VPL_CPU_DEPS_BUILD_DIR}" ]
  then
      echo "Cleaning dependencies build folder..."
      rm -rf "${VPL_CPU_DEPS_BUILD_DIR}"
  fi
fi

if [ -e "${VPL_CPU_BUILD_DIR}" ]
then
    echo "Cleaning cpu build folder..."
    rm -rf "${VPL_CPU_BUILD_DIR}"
fi
