#!/usr/bin/env bash
#
# Clone or update vim to $HOME/dev/vim, build and install to $HOME/local
set -e

mkdir -p $HOME/dev
destdir=$HOME/dev/vim
if [ -d $destdir ]; then
  echo "Updating vim..."
  cd $destdir
  git pull --rebase
else
  echo "Cloning vim..."
  cd $HOME/dev
  git clone -q https://github.com/vim/vim.git vim
fi

cd $destdir

# TODO: https://stackoverflow.com/questions/53135863/macos-mojave-ruby-config-h-file-not-found
opts="--enable-luainterp --enable-python3interp --with-features=huge --enable-multibyte --enable-gui=gtk2"
if [ ! $(uname -s) = "Darwin" ]; then
  opts="$opts --with-rubyinterp --with-x"
fi

./configure --prefix=$HOME/local $opts
make -j6
make install