pkgname=vim
pkgver=9.1.1629
_versiondir=91
pkgdesc='Vi Improved, a highly configurable, improved version of the vi text editor'
home='https://www.vim.org'
arch=('x86_64')
license=('custom:vim')
sources=("${pkgname}-${pkgver}.tar.gz")
urls=("https://github.com/vim/vim/archive/v${pkgver}/${sources[0]}")
md5sums=("4f856c3233c1c4570bc17572e4f9e8e4")

src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1
  echo '#define SYS_VIMRC_FILE "/etc/vimrc"' >> src/feature.h
  cat > vimrc << "EOF"
" Begin /etc/vimrc

" Ensure defaults are set before customizing settings, not after
source $VIMRUNTIME/defaults.vim
let skip_defaults_vim=1

set nocompatible
set backspace=2
set mouse=
syntax on
if (&term == "xterm") || (&term == "putty")
  set background=dark
endif

" End /etc/vimrc
EOF
}

src_build() {
  ./configure --prefix=/usr   \
              --disable-gui   \
              --with-x=no     \
              --with-compiledby='LFS'
  make
}

src_check() {
  leaf_record_message "Tests require at least 24 lines with 80 characters."
  leaf_record_message "Test_write_backup_symlink is known to fail if BUILD_DIR is under /tmp."
  if [[ -f /etc/vimrc ]]; then
    mv -v /etc/vimrc /etc/vimrc.old
  fi
  chown -R leaf .
  sed '/test_plugin_glvs/d' -i src/testdir/Make_all.mak
  echo "Testing... May take a while..."
  su leaf -c "TERM=xterm-256color LANG=en_US.UTF-8 make -j1 test" \
   &> vim-test.log
  if [[ -f /etc/vimrc.old ]]; then
    mv -v /etc/vimrc.old /etc/vimrc
  fi
}

src_install() {
  make DESTDIR="${pkgdir}" install
  rm -rf "${pkgdir}/usr/share/icons"
  ln -sv vim ${pkgdir}/usr/bin/vi
  for L in  ${pkgdir}/usr/share/man/{,*/}man1/vim.1; do
    ln -sv vim.1 $(dirname $L)/vi.1
  done
  install -Dv vimrc ${pkgdir}/etc/vimrc
  install -dv ${pkgdir}/usr/share/doc/
  ln -sv ../vim/vim${_versiondir}/doc ${pkgdir}/usr/share/doc/vim-${pkgver}
}

# vim:ft=sh syn=sh et sw=2:
