#!/usr/bin/env bash

if (( ${rvm_trace_flag:=0} == 2 ))
then
  set -x
  export rvm_trace_flag
fi

rvm_base_except="selector"

source "$rvm_scripts_path/base"
source "$rvm_scripts_path/functions/build"
source "$rvm_scripts_path/functions/db"
source "$rvm_scripts_path/functions/pkg"

__rvm_setup_compile_environment

set +o errexit

# Tools to make managing ruby dependencies inside of rvm easier.
args=($*)
action="${args[0]:-""}"
library="${args[1]:-""}"
args="$(echo ${args[@]:2})"

if [[ -n "$library" ]]
then
  case $library in
    readline|iconv|curl|openssl|zlib|autoconf|ncurses|pkgconfig|gettext|glib|mono|llvm|libxml2|libyaml)
      ${library}
    ;;
    ree_dependencies)
      for i in zlib ncurses readline openssl iconv; do
        ${i}
        reset
      done
    ;;
    *)
      rvm_error "Package '${library}' is unknown."
    ;;
  esac

  exit $?

else
  rvm_log "\nUsage:\n  'rvm pkg {install,uninstall} {readline,iconv,curl,openssl,zlib,autoconf,ncurses,pkgconfig,gettext,glib,mono,llvm,libxml2,libxslt,libyaml}'\n
    'ree_dependencies' installs zlib, ncurses, readline, openssl and iconv in this order.\n
    still need to add ' --with-readline-dir=\$rvm_usr_path --with-iconv-dir=\$rvm_usr_path --with-zlib-dir=\$rvm_usr_path --with-openssl-dir=\$rvm_usr_path' to 'rvm install ree'\n"
  exit 1
fi
