#!/bin/sh
#

#
# KIM-API: An API for interatomic models
# Copyright (c) 2013--2022, Regents of the University of Minnesota.
# All rights reserved.
#
# Contributors:
#    Ryan S. Elliott
#    Yaser Afshar
#
# SPDX-License-Identifier: LGPL-2.1-or-later
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
#

#
# Release: This file is part of the kim-api.git repository.
#


# Ensure that this script is sourced, not executed
BASENAME_SOURCE=`basename -- "$0" 2> /dev/null`

if test -n "${ZSH_VERSION}"; then
  if test $options[posixargzero] != "on"; then
    setopt posixargzero
    BASENAME_SOURCE=`basename -- "$0" 2> /dev/null`
    setopt posixargzero
  fi
fi

if test x"${BASENAME_SOURCE}" = x"@PROJECT_NAME@-deactivate"; then
  (>&2 printf "\nError:\t@PROJECT_NAME@-deactivate must be sourced.\n"
   printf "\tRun 'source @PROJECT_NAME@-deactivate' not "
   printf "'@PROJECT_NAME@-deactivate'.\n\n")
  exit 1
fi


if test -n "${ORIGIN}"; then
  OLD_KIM_ORIGIN="${ORIGIN}"
fi
if test -n "${ZSH_VERSION}"; then
  ORIGIN=$(cd "$(dirname "${(%):-%x}")" && pwd)
else
  # Get ORIGIN location of this script:
  SOURCE="${BASH_SOURCE[0]}"
  # https://stackoverflow.com/questions/59895/how-to-get-the-source-directory-of-a-bash-script-from-within-the-script-itself
  if command -v readlink >/dev/null 2>&1; then
    while test -h "$SOURCE"; do # resolve $SOURCE until the file is no longer a symlink
      DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
      SOURCE="$(readlink "$SOURCE")"
      [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
    done
  fi
  ORIGIN="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
fi

export PATH=`printf "${PATH}" | sed -e "s|:${ORIGIN}|:|g" \
                                    -e "s|^${ORIGIN}:*||" \
                                    -e "s|:${ORIGIN}$||"`
_libdir_rel=$(cd "@_libdir_rel@" && pwd)
export PKG_CONFIG_PATH=`printf "${PKG_CONFIG_PATH}" | \
                                sed -e "s|:${_libdir_rel}/pkgconfig|:|g" \
                                    -e "s|^${_libdir_rel}/pkgconfig:*||" \
                                    -e "s|:${_libdir_rel}/pkgconfig$||"`
unset _libdir_rel
if test -z "${PKG_CONFIG_PATH}"; then unset PKG_CONFIG_PATH; fi

unset @KIM_API_ENVIRONMENT_CMAKE_PREFIX_DIR@

if test -n "${ZSH_VERSION}"; then
  _completion_dir="@_zshcompdir_rel@"
else
  _completion_dir="@_bashcompdir_rel@"
fi

for _func in `grep "_@KIM_API_C_ID_PROJECT_NAME@_.*[[:space:]]*()" \
    "${_completion_dir}/@PROJECT_NAME@-collections-management.bash"`; do
  _func=`printf "${_func}" | sed -e 's|[[:space:]]*().*||'`
  unset -f "${_func}"
done

unset _func
unset _completion_dir

if test -n "${OLD_KIM_ORIGIN}"; then
  ORIGIN="${OLD_KIM_ORIGIN}"
  unset OLD_KIM_ORIGIN
else
  unset ORIGIN
fi
