# SliTaz package receipt.

PACKAGE="vim-tiny"
VERSION="7.3"
CATEGORY="development"
SHORT_DESC="Advanced text editor with no GUI"
MAINTAINER="erjo@slitaz.org"
DEPENDS="ncurses"
SOURCE="vim"
TARBALL="$SOURCE-$VERSION.tar.bz2"
WEB_SITE="http://www.vim.org/"
WGET_URL="ftp://ftp.vim.org/pub/vim/unix/$TARBALL"
CONFIG_FILES="/etc/vim/vimrc"
TAGS="text-editor"

# Rules to configure and make the package.
compile_rules()
{
	cd $src

	# define the place for the global vimrc file (set to /etc/vim/vimrc)
	# (patch from Arch Linux PKGBUILD)
	sed -i 's|^.*\(#define SYS_VIMRC_FILE\).*$|\1 "/etc/vim/vimrc"|' $src/src/feature.h
	
	./configure --prefix=/usr \
	 --cache-file=$PWD/config.cache \
	 --infodir=/usr/share/info \
	 --with-features=tiny \
	 --with-x=no \
	 --disable-gui \
         --enable-multibyte \
	 --with-vim-name=$PACKAGE \
	 --disable-acl \
	 --disable-motif-check \
	 --disable-athena-check \
	 --mandir=/usr/share/man $CONFIGURE_ARGS && 
	 
	make VIMRCLOC=/etc/vim VIMRUNTIMEDIR=/usr/share/vim/vim73 MAKE="make -e" &&
	make DESTDIR=$DESTDIR install
	mkdir -p $DESTDIR/etc/vim
	cp -a $src/runtime/vimrc_example.vim $DESTDIR/etc/vim/vimrc
}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	mkdir -p $fs/usr/share $fs/etc
	
	cp -a $_pkg/usr/bin $fs/usr
	cp -a $_pkg/usr/share/vim $fs/usr/share
	cp -a $_pkg/etc/vim $fs/etc
	rm -f $fs/usr/bin/*tutor
}

post_install()
{
    local root
    root=$1
    echo "Processing post-install commands..."
    cmd=`readlink $root/bin/vi`
    if [ ! "$cmd" = "/usr/bin/vim" ]; then
        echo ""
        echo "**** Actual VI link : $cmd"
        echo ""
        echo -n "Do you want vim  for /bin/vi (y/N) ? : "; read anser
        if [ "$anser" == "y" ]; then
            echo ""
            echo -n "Removing vi link to make a new one pointing on /usr/bin/vim..."
            rm $root/bin/vi && ln -sf $root/usr/bin/vim-tiny $root/bin/vi
            status
        else
            echo ""
            echo "Leaving /bin/vi to : $cmd"
        fi
    fi
}

post_remove()
{
	# restore previous symlink
	echo "Processing post-remove commands..."
	ln -sf /bin/busybox $1/bin/vi
}