# $Id: Portfile 68093 2010-05-26 15:59:19Z raimue@macports.org $

PortSystem          1.0

name                vim
set vim_version     7.2
set vim_patchlevel  433
version             ${vim_version}.${vim_patchlevel}
categories          editors
maintainers         raimue
description         Vi \"workalike\" with many additional features
long_description \
    Vim is an advanced text editor that seeks to provide the power of the   \
    de-facto Unix editor 'Vi', with a more complete feature set.

homepage            http://www.vim.org/
platforms           darwin freebsd

use_bzip2           yes

master_sites        http://ftp.vim.org/pub/vim/unix/:vim \
                    http://ftp.vim.org/pub/vim/extra/:extra
patch_sites         http://ftp.vim.org/pub/vim/patches/${vim_version}
distfiles \
    [suffix ${name}-${vim_version}]:vim \
    ${name}-${vim_version}-extra.tar.gz:extra \
    ${name}-${vim_version}-lang.tar.gz:extra

# Generate patchfiles
set low 1
set patchlevel [string trimleft $vim_patchlevel 0]
while {$low <= $patchlevel} {
    set high [expr $low + 99];
    if {$high < $patchlevel} {
        patchfiles-append [format "%s.%03d-%03d.gz" $vim_version $low $high]
        incr low 100
    } else {
        patchfiles-append [format "%s.%03d" $vim_version $low]
        incr low 1
    }
}

checksums \
  [suffix ${name}-${vim_version}] \
    md5     f0901284b338e448bfd79ccca0041254 \
    sha1    a4b6641ca528fada71ea77c998a441495ed4984c \
    rmd160  eaff64d0fec09d725addf8de569f508b80a5766e \
  ${name}-${vim_version}-extra.tar.gz \
    md5     35e04482f07c57221c9a751aaa3b8dac \
    sha1    6a17629093e59958bff336b6c122dea1b8b1b649 \
    rmd160  05976466c8a6c1bd2fb2b1d58eb4613947de07df \
  ${name}-${vim_version}-lang.tar.gz \
    md5     d8884786979e0e520c112faf2e176f05 \
    sha1    970e0dda7e5b2308cf33488be1ea33d593d951cb \
    rmd160  946bd64fbf030b341cc13bee7101f2c0acb26ce2

checksums-append \
    7.2.001-100.gz md5 ba91b19374cee90f71b8f4ab1d92dc0f \
    7.2.101-200.gz md5 b485233d360041d043c56cd99057dbff \
    7.2.201-300.gz md5 069fb537772a8e4a74119d8a6a7e61f3 \
    7.2.301-400.gz md5 137b5821ff4a2266796d14d867be5f9f \
    7.2.401 md5 540a3aa9d405a30b6fef97c1faf80c0c \
    7.2.402 md5 f9b2000d9ef2b3e23c62244efd640f40 \
    7.2.403 md5 5df130e5db1097c5d062af517014ecd8 \
    7.2.404 md5 27aacd95c4834b38c17b04378486cab8 \
    7.2.405 md5 d2cdd35d3b9e76ce0d6b4abdf7b703ba \
    7.2.406 md5 64d97351da772dc675f1c11c5886d9f7 \
    7.2.407 md5 277b53d418c9fb0c48983c5e53b2b74b \
    7.2.408 md5 73845e7170e672e15655610d9f73e1ec \
    7.2.409 md5 c723bf80bdd72053f334cf37269cd2fd \
    7.2.410 md5 ad3c5edcc695600ef7ad254eccb064f4 \
    7.2.411 md5 a3c882ee8006eb4f6a1a1334bca08c11 \
    7.2.412 md5 adba03739abbe73d058fc8ddf474c531 \
    7.2.413 md5 53b9fa0d13737d5efd2827be007ccf4b \
    7.2.414 md5 8e54ea844390ed324d4d449d38cbd260 \
    7.2.415 md5 9212103515da33938f49318fefb2ce27 \
    7.2.416 md5 3b39b379e637de3578796305f8e75e9d \
    7.2.417 md5 cbd7975c5d1488ab24f398198f15ca1e \
    7.2.418 md5 2face7141504f2d89b31c69fbba9b653 \
    7.2.419 md5 e116f5f6c9be5b47aaf8cd1034a61937 \
    7.2.420 md5 5785f807b23a7073c78244cc05ca7a86 \
    7.2.421 md5 5fa7dc7b528b518d5618c35ea38cf048 \
    7.2.422 md5 2ff19a6db082f3e78c764b2131890872 \
    7.2.423 md5 4527e41594caed5bb8ffc140a7a2ad79 \
    7.2.424 md5 119448ee7b1e5fe05ebbb231ae43027e \
    7.2.425 md5 d8c3f2287ea065950ac9bb34ff80b138 \
    7.2.426 md5 2e9fb8257681220bee6509597d3bc6b5 \
    7.2.427 md5 fad1dd6de9372b2e610e52d5f8ee7a56 \
    7.2.428 md5 892bf014f642bfb810be64004a3ddb2a \
    7.2.429 md5 1c4fad5af7e702d7021c30f792914e69 \
    7.2.430 md5 a21c2c41d50b97812f3eb4b1716f72e1 \
    7.2.431 md5 77939e599f984013f53b3dc645bc995a \
    7.2.432 md5 10693840368e34e40430c7d34c71bd2d \
    7.2.433 md5 6a9731f83856d6f7d7d5b37852a1b83f

distname            ${name}[strsed ${vim_version} {g/\.//}]
dist_subdir         ${distname}

depends_build       bin:gnutar:gnutar \
                    bin:grep:grep
depends_lib         port:ncurses \
                    port:libiconv \
                    port:ctags

autoconf.cmd make autoconf
autoconf.dir ${worksrcpath}/src

configure.args      --enable-gui=no \
                    --without-x \
                    --disable-gpm \
                    --disable-nls \
                    --mandir=${prefix}/share/man \
                    --with-tlib=ncurses \
                    --enable-multibyte \
                    --with-developer-dir=${developer_dir}

extract.only        [suffix ${name}-${vim_version}]
post-extract {
    system "gnutar xvfz ${distpath}/${name}-${vim_version}-extra.tar.gz -C \
      ${workpath}"
    system "gnutar xvfz ${distpath}/${name}-${vim_version}-lang.tar.gz -C \
      ${workpath}"
}

post-patch {
	set features [open ${worksrcpath}/src/feature.h a+]
	puts $features "#define SYS_VIMRC_FILE \"${prefix}/etc/vimrc\""
	close $features
}

post-destroot {
    ln -s ${prefix}/bin/vim ${destroot}${prefix}/bin/vi
}

test.run            yes

variant x requires x11 description {Compatibility variant, requires +x11} {}
variant x11 description {Build CLI version with X support} {
    configure.args-delete   --without-x
    configure.args-append   --with-x
    depends_lib-append      port:xorg-libXt
}

variant athena description {Build GUI version using Athena widgets} requires x11 conflicts gtk1 gtk2 motif {
    configure.args-delete   --enable-gui=no
    configure.args-append   --enable-gui=athena --disable-darwin
    depends_lib-append      port:xorg-libXaw
}
variant gtk1 description {Build GUI version using GTK 1.x widgets} requires x11 conflicts athena gtk2 motif {
    configure.args-delete   --enable-gui=no
    configure.args-append   --enable-gui=gtk --disable-darwin
    depends_lib-append      port:gtk1
}
variant gtk2 description {Build GUI version using GTK 2.x widgets} requires x11 conflicts athena gtk1 motif {
    configure.args-delete   --enable-gui=no
    configure.args-append   --enable-gui=gtk2 --disable-darwin
    depends_lib-append      port:gtk2
}
variant motif description {Build GUI version with Motif widgets} requires x11 conflicts athena gtk1 gtk2 {
    configure.args-delete   --enable-gui=no
    configure.args-append   --enable-gui=motif --disable-darwin
    depends_lib-append      lib:libXm:openmotif
}

variant tiny description {Build tiny feature set} {
    configure.args-append --with-features=tiny
}
variant small description {Build small feature set} conflicts tiny {
    configure.args-append --with-features=small
}
variant big description {Build big feature set} conflicts tiny small	{
    configure.args-append --with-features=big
}
variant huge description {Build huge feature set} conflicts tiny small big {
    configure.args-append --with-features=huge
}
variant xim description {Build with support for X Input Method} {
    configure.args-append --with-xim
}

variant shell description {Enables shell windows} {
    # Patch taken from http://www.wana.at/vimshell/
    patchfiles-append       patch-vimshell.diff
}

variant perl description {Enable Perl scripting} {
    configure.args-append   --enable-perlinterp
    depends_lib-append      path:bin/perl:perl5
}
variant python requires python25 description {Compatibility variant, requires +python25} {}
variant python25 conflicts python26 description {Enable Python scripting} {
    configure.args-append   --enable-pythoninterp --with-python=${prefix}/bin/python2.5
    patchfiles-append       patch-python.diff
    depends_lib-append      port:python25

    use_autoconf yes
    # Overwriting autoconf.cmd above removes dependency, add it again
    depends_build-append port:autoconf
}
variant python26 conflicts python25 description {Enable Python scripting} {
    configure.args-append   --enable-pythoninterp --with-python=${prefix}/bin/python2.6
    patchfiles-append       patch-python.diff
    depends_lib-append      port:python26

    use_autoconf yes
    # Overwriting autoconf.cmd above removes dependency, add it again
    depends_build-append port:autoconf
}
variant ruby description {Enable Ruby scripting} {
    configure.args-append   --enable-rubyinterp
    depends_lib-append      port:ruby
}
variant tcl description {Enable Tcl scripting} {
    configure.args-append   --enable-tclinterp
    patchfiles-append       patch-tcl.diff
    depends_lib-append      port:tcl

    use_autoconf yes
    # Overwriting autoconf.cmd above removes dependency, add it again
    depends_build-append port:autoconf
}

variant cscope description {Enable source code browsing with cscope} {
    configure.args-append   --enable-cscope
}

variant nls {
    configure.args-delete   --disable-nls
    depends_lib-append      port:gettext
}

platform puredarwin {
    configure.args-append --disable-darwin
}

livecheck.type  regex
livecheck.url   http://ftp.vim.org/pub/${name}/patches/${vim_version}/?O=D
livecheck.regex (${vim_version}\.\\d+)
