# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 92489 2012-04-30 03:15:19Z dports@macports.org $

PortSystem 1.0
PortGroup  muniversal 1.0

name            emacs-snapshot
version         20120423
revision        0

categories      editors
license         GPL-3+
maintainers     dports saispo openmaintainer
description     The GNU Emacs text editor
long_description \
    GNU Emacs is a self-documenting, customizable, extensible real-time \
    display editor. Users new to Emacs will be able to use basic        \
    features fairly rapidly by studying the tutorial and using the      \
    self-documentation features. Emacs also has an extensive            \
    interactive manual browser. It is easily extensible since its       \
    editing commands are written in Lisp.

platforms       darwin freebsd
homepage        http://www.gnu.org/software/emacs/emacs.html
master_sites    http://emacs.naquadah.org/unstable/
distfiles       ${name}_${version}.orig.tar.xz

checksums       rmd160  8e126cad5d025919573956d6727603a9e21297cd \
                sha256  8b26c0da0c7f36f59f420b240757c0002fe44a0ab9df5577594318dacab2b7b8

set suffix      ".${name}"

pre-configure {
    system "cd ${worksrcpath}; sh ./autogen.sh"
}

configure.args  --without-x \
                --with-dbus \
                --without-gconf \
                --without-libotf \
                --without-m17n-flt \
                --without-gpm \
                --infodir ${prefix}/share/info/${name}

use_xz	yes

depends_build   port:pkgconfig \
                port:autoconf \
                port:automake

depends_lib     port:ncurses \
                path:bin/dbus-daemon:dbus \
                port:texinfo
post-destroot {
    xinstall -d ${destroot}${prefix}/share/emacs/${version}/leim
    # avoid conflict with ctags installed by the ctags port
    delete ${destroot}${prefix}/bin/ctags

    # remove non-version-specific site-lisp dir
    delete ${destroot}${prefix}/share/emacs/site-lisp
    delete ${destroot}${prefix}/var/games/emacs/snake-scores
    delete ${destroot}${prefix}/var/games/emacs/tetris-scores

    # give the emacs binary (and its manpage) a more sane name
    move ${destroot}${prefix}/bin/emacs \
         ${destroot}${prefix}/bin/${name}
    move ${destroot}${prefix}/bin/emacsclient \
         ${destroot}${prefix}/bin/emacsclient-snapshot
    move ${destroot}${prefix}/share/man/man1/emacs.1.gz \
         ${destroot}${prefix}/share/man/man1/${name}.1.gz
}

livecheck.type  regex
livecheck.url   http://emacs.naquadah.org/unstable/?C=M&O=D
livecheck.regex ${name}_(\\d+\\w*)\\.orig.tar.xz

variant x11 description {Builds emacs as a X11 program with Lucid widgets} {
    configure.args-delete   --without-x
    configure.args-append   --with-x-toolkit=lucid \
                            --without-xaw3d \
                            --with-xpm \
                            --with-jpeg \
                            --with-tiff \
                            --with-gif \
                            --with-png \
                            --without-rsvg \
                            --with-xft 
    depends_lib-append      port:xorg-libXmu \
                            port:xorg-libXaw \
                            port:xpm \
                            port:jpeg \
                            port:tiff \
                            port:giflib \
                            port:libpng \
                            port:Xft2

    # autoconf appears to be dropping linker flags for freetype &
    # fontconfig; work around this. See #28083
    configure.ldflags-append -lfreetype -lfontconfig
}

variant motif requires x11 description {Builds emacs as an X11 program with Motif widgets} {
    configure.args-delete   --with-x-toolkit=lucid
    configure.args-append   --with-x-toolkit=motif
    depends_lib-append      lib:libXm:openmotif
}

variant gtk requires x11 description {Builds emacs as an X11 program with GTK+2 widgets} {
    configure.args-delete   --with-x-toolkit=lucid
    configure.args-delete   --without-gconf
    configure.args-delete   --without-rsvg
    configure.args-append   --with-x-toolkit=gtk
    configure.args-append   --with-gconf
    configure.args-append   --with-rsvg
    depends_lib-append      port:gtk2 \
                            port:gconf \
                            port:librsvg
}
