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

name            xemacs
# note: the newer 21.5 series is beta and is not stable.
version         21.4.22
set sumo_date   2010-07-27
set efs_version 1.34
set base_version 2.27
epoch           1
categories      editors x11
platforms       darwin
maintainers     {dstrubbe @dstrubbe} openmaintainer
license         GPL-2+
revision        18

description     A highly customizable open-source text editor.

long_description \
    XEmacs is a highly customizable open-source text editor and application development \
    system. It is protected under the GNU Public License and related to other versions of \
    Emacs, in particular GNU Emacs. \
    efs and xemacs-base packages are installed by default, more with +sumo.

homepage        http://www.xemacs.org
master_sites    http://ftp.xemacs.org/pub/xemacs/xemacs-21.4/:xemacs \
                ftp://ftp.xemacs.org/pub/xemacs/xemacs-21.4/:xemacs \
                http://ftp.xemacs.org/pub/xemacs/packages/:package \
                ftp://ftp.xemacs.org/pub/xemacs/packages/:package \
                http://mirrors.ibiblio.org/pub/mirrors/xemacs/packages/:package

set xemacs_dist ${name}-${version}${extract.suffix}
set sumo_dist   ${name}-sumo-${sumo_date}${extract.suffix}
set mule_dist   ${name}-mule-sumo-${sumo_date}${extract.suffix}

distfiles       ${xemacs_dist}:xemacs efs-${efs_version}-pkg.tar.gz:package xemacs-base-${base_version}-pkg.tar.gz:package

checksums       xemacs-${version}.tar.gz \
                md5     b0b762407316d6de170db69aba7a37cf \
                sha1    24ed9b13d80c53c06bba60c7bb68387f692b7373 \
                rmd160  f7d71d3607c3301760df8f7ae5a93d1d37df56ba \
                xemacs-sumo-${sumo_date}.tar.gz \
                md5     12ee5fca32ff7e3bfd6ecfd4bb157688 \
                sha1    60b9601b9d865bdb031c8babc4020ab2a8a3258f \
                rmd160  15bdf45aaa8dc7fe0a4d378f5993b34054563d81 \
                xemacs-mule-sumo-${sumo_date}.tar.gz \
                md5     2f5cd280cbc2db71d1211a87bcc37344 \
                sha1    852a5ac51bb713a16f62676bb5db3f2ab06379cd \
                rmd160  601a735ff800ceb2443ec9b26bc0f7c5b2215854 \
                efs-${efs_version}-pkg.tar.gz \
                md5 1f424efc4a55b8da53a7d01136793c9d \
                sha1 c2465e7308408edfbedd2758210e100151756546 \
                rmd160 375a56d8bf361222ec84980a6afb762f8e2cd282 \
                xemacs-base-${base_version}-pkg.tar.gz \
                md5     2ec18d0faf31e2d343f558c730474a63 \
                sha1    35861ee64ab00191737e35908553f598bd845c9d \
                rmd160  094fc92d1ebd390ccafcb338b17f44943bd834ae

patchfiles      51ced9b8fb63e4be59ea611b58128c400e3df987.diff \
                bcefd94fa6513d48f4dc8519f633b2df66b553bc.diff \
                texinfo5.patch
patch.pre_args-replace  -p0 -p1

configure.args  --mandir=${prefix}/share/man \
                --without-postgresql \
                --without-ldap \
                --with-sound=none \
                --pdump \
                --site-prefixes=${prefix} \
                --with-tty \
                --with-dialogs=athena \
                --with-widgets=athena \
                --with-athena=3d \
                --with-database=gdbm

depends_build   bin:makeinfo:texinfo port:xbitmaps
depends_skip_archcheck-append texinfo

depends_lib     port:libpng port:Xaw3d port:ncurses port:gdbm path:include/turbojpeg.h:libjpeg-turbo \
                port:tiff port:compface port:zlib port:xorg-libXaw
depends_run     port:ctags

destroot.args   prefix=${destroot}${prefix} mandir=${destroot}${prefix}/share/man/man1

destroot.keepdirs ${destroot}${prefix}/lib/xemacs
post-destroot {
    set xemacs_lib ${destroot}${prefix}/lib/xemacs-${version}
    xinstall -d -m 0755 ${xemacs_lib}

    # this directory is empty
    delete ${destroot}${prefix}/lib/xemacs
    ln -s xemacs-${version} ${destroot}${prefix}/lib/xemacs

    if {![variant_isset sumo]} {
        file mkdir ${workpath}/xemacs-packages
        file copy ${workpath}/man     ${workpath}/xemacs-packages
        file copy ${workpath}/info    ${workpath}/xemacs-packages
        file copy ${workpath}/etc     ${workpath}/xemacs-packages
        file copy ${workpath}/lisp    ${workpath}/xemacs-packages
        file copy ${workpath}/pkginfo ${workpath}/xemacs-packages
    }

    file copy ${workpath}/xemacs-packages ${xemacs_lib}

    if {[variant_isset sumo]} {
        file copy ${workpath}/mule-packages ${xemacs_lib}/
    }

    # avoid conflicts with ctags port
    delete ${destroot}${prefix}/bin/ctags
    delete ${destroot}${prefix}/share/man/man1/ctags.1

    # avoid conflicts with emacs
    move ${destroot}${prefix}/bin/etags ${destroot}${prefix}/bin/etags-xemacs
    move ${destroot}${prefix}/share/man/man1/etags.1 ${destroot}${prefix}/share/man/man1/etags-xemacs.1
}

variant sumo \
    description "Install SUMO (all packages) and mule (multilanguage) support." {
    configure.args-append --with-mule
    depends_lib-append    port:gettext
    distfiles-append      ${sumo_dist}:package ${mule_dist}:package
    distfiles-delete      efs-${efs_version}-pkg.tar.gz:package xemacs-base-${base_version}-pkg.tar.gz:package
}

default_variants +sumo

# https://trac.macports.org/ticket/31679
configure.cflags-append -std=gnu89

if {${os.major} >= 11 && ${os.platform} eq "darwin"} {
    configure.ldflags-append -Wl,-no_pie
}

livecheck.type          regex
livecheck.url           http://ftp.xemacs.org/pub/xemacs/xemacs-21.4
livecheck.regex         ${name}-(\[0-9.\]+)${extract.suffix}
