# -*- 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$

PortSystem 1.0
PortGroup  muniversal 1.0
PortGroup  active_variants 1.1

name            emacs
conflicts       xemacs
version         25.1
categories      editors
license         GPL-3+
maintainers     dports 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    gnu

checksums       rmd160  d29ddba846024c7df3e1dc02ac32690f3650e7b9 \
                sha256  763344b90db4d40e9fe90c5d14748a9dbd201ce544e2cf0835ab48a0aa4a1c67

# our dbus is autolaunched by launchd, so disable the check that it's running
patchfiles      patch-src_dbusbind.c.diff

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

depends_build   port:pkgconfig \
                port:texinfo
depends_lib     port:ncurses \
                port:libxml2

post-destroot {
    xinstall -d ${destroot}${prefix}/share/emacs/${version}/leim
    delete ${destroot}${prefix}/bin/ctags
    delete ${destroot}${prefix}/share/man/man1/ctags.1.gz
}

livecheck.type  regex
livecheck.url   http://ftp.gnu.org/gnu/emacs/?C=M&O=D
livecheck.regex ${name}-(\\d+\\.\\d+\\w*)\\.tar

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 \
                            --without-imagemagick \
                            --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
}

platform darwin {
    post-patch {
        # Leopard's XCode 3.1.x ld(1) man page claims -no_pie is supported, but it's not
        if {${os.major} < 9} {
            reinplace "s:-fno-pie::" ${worksrcpath}/configure
        } elseif {${os.major} > 10} {
            configure.ldflags-append -Wl,-no_pie
        }
    }
}

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=gtk2
    configure.args-append   --with-gconf
    configure.args-append   --with-rsvg
    depends_lib-append      port:gtk2 \
                            path:lib/pkgconfig/glib-2.0.pc:glib2 \
                            port:gconf \
                            port:librsvg

    # see #21917
    require_active_variants gtk2 x11
}

variant dbus description {Builds emacs with D-Bus support} {
    configure.args-delete   --without-dbus
    configure.args-append   --with-dbus
    depends_lib-append      port:dbus
}