#!/bin/bash
###############################################################################
# Copyright (C) Intel Corporation
#
# SPDX-License-Identifier: MIT
###############################################################################
# Install the product.
#
# If argument is provided then it will be interpreted as the install prefix. If
# called without arguments then installation will be to `VPL_INSTALL_DIR` if
# defined or system default location otherwise.

set -o errexit

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

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

source_dir="$(dirname "$script_dir")"
build_dir="$source_dir/_build"

if [ -n "$1" ]; then
  # use first argument as install prefix
  cmake --install "$build_dir" --config Release --strip --prefix "$1"
elif [ -z ${VPL_INSTALL_DIR+x} ]; then
  # no argument or env variable defined, use system default install location
  cmake --install "$build_dir" --config Release --strip
else
  # no argument but env variable was provided, install to VPL_INSTALL_DIR
  cmake --install "$build_dir" --config Release --strip --prefix "$VPL_INSTALL_DIR"
fi
