# Require $prefix, $workdir, $python_src
install_python()
(
  [[ -e $prefix/lib/pkgconfig/python3.pc ]] && exit 0

  [[ "$workdir" = */hscpipe_build_dir ]] || exit 1
  rm -rf "$workdir"; mkdir -p "$workdir"; pushd "$workdir"

  curl -L "$python_src" | tar -xJf -

  cd Python*
  ./configure --prefix="$prefix" --enable-shared
  make
  make install

  if [[ ! -e "$prefix/bin/python" ]]
  then
    if [[ -L "$prefix/bin/python3" ]]
    then
      ln -s $(readlink "$prefix/bin/python3") "$prefix/bin/python"
    else
      ln -s "$prefix/bin/python3" "$prefix/bin/python"
    fi
  fi

  if [[ ! -e "$prefix/bin/python-config" ]]
  then
    if [[ -L "$prefix/bin/python3-config" ]]
    then
      ln -s $(readlink "$prefix/bin/python3-config") "$prefix/bin/python-config"
    else
      ln -s "$prefix/bin/python3-config" "$prefix/bin/python-config"
    fi
  fi

  curl -LO https://bootstrap.pypa.io/get-pip.py
  python3 get-pip.py
  pip3 install --upgrade setuptools pip
)
