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

PortSystem 1.0
PortGroup muniversal 1.0

name            emacs22
version         22.3
revision        8

categories      editors
license         GPL-3+
maintainers     {dports @drkp} 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        https://www.gnu.org/software/emacs/emacs.html
master_sites    gnu:emacs
distname        emacs-${version}
checksums       md5     aa8ba34f548cd78b35914ae5a7bb87eb \
                sha1    5e9b3e0205099a83be7198fd43ba1c9442a3feb0 \
                rmd160  a7eed5099d0cab25f34152f1b18b5c1b4e2e0746

patchfiles      patch-Makefile.in.diff \
                patch-leim-Makefile.in.diff \
                patch-unexmacosx.c.diff \
                patch-unexmacosx.c-2.diff \
                patch-s-darwin.h.diff \
                patch-configure-ignore-xaw3d.diff

set major       22
set suffix      ".${name}"

configure.args  --without-x \
                --without-carbon \
                --program-suffix=${suffix} \
                --infodir=${prefix}/share/info/${name}

depends_lib     port:ncurses


post-destroot {
    xinstall -d ${destroot}${prefix}/share/emacs/${version}/leim
    # avoid conflict with ctags installed by the ctags port
    delete ${destroot}${prefix}/bin/ctags${suffix}
    delete ${destroot}${prefix}/share/man/man1/ctags.1

    # 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

    # add suffixes to man pages to match binary names
    foreach f [glob -dir ${destroot}${prefix}/share/man/man1 *.1] {
        move $f "[file rootname $f]${suffix}.1"
    }

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

livecheck.type  regex
livecheck.url   http://ftp.gnu.org/gnu/emacs/?C=M&O=D
livecheck.regex emacs-(${major}\\.\\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-carbon \
                            --with-xpm \
                            --with-jpeg \
                            --with-tiff \
                            --with-gif \
                            --with-png
    depends_lib-append      port:xorg-libXmu \
                            port:xorg-libXaw \
                            port:xpm \
                            lib:libjpeg:jpeg \
                            lib:libtiff:tiff \
                            port:giflib \
                            lib:libpng:libpng
}

if {${os.platform} eq "darwin" && ${os.major} >= 11} {
    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-append   --with-x-toolkit=gtk
    depends_lib-append      lib:libgtk.2:gtk2 \
                            lib:libglib.2:glib2
}