# -*- 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 119602 2014-05-02 08:20:05Z ryandesign@macports.org $

PortSystem          1.0

name                screen
version             4.2.1
homepage            http://www.gnu.org/software/screen/
description         Screen manager with VT100/ANSI terminal emulation
long_description    \
    Screen is a full-screen window manager that multiplexes a physical \
    terminal between several processes (typically interactive shells). \
    Each virtual terminal provides the functions of a DEC VT100 terminal \
    and, in addition, several control functions from the ANSI X3.64 (ISO \
    6429) and ISO 2022 standards (e.g. insert/delete line and support for \
    multiple character sets). There is a scrollback history buffer for each \
    virtual terminal and a copy-and-paste mechanism that allows moving text \
    regions between windows.
categories          sysutils
license             GPL-3+
platforms           darwin
maintainers         nomaintainer
master_sites        gnu:${name} \
                    http://www.cis.nctu.edu.tw/~is85005/dports/screen/:encoding \
                    http://www.cis.nctu.edu.tw/~is85005/dports/screen/r23776/:launchd_priv_header

# The file '18' above is a fix for UTF8-to-Big5HKSCS encoding translation.
# Reference: http://freebsd.sinica.edu.tw/~statue/index.php?file=20020513
distfiles-append    18:encoding

checksums           ${distname}${extract.suffix} \
                    rmd160  20ddf4a33f91e60a42a31f02aa2a30a9c5cba9b5 \
                    sha256  5468545047e301d2b3579f9d9ce00466d14a7eec95ce806e3834a3d6b0b9b080 \
                    18 \
                    rmd160  bd143058417e1d4c040a2589fdfbf8f9203f0b4c \
                    sha256  4d4b674a61dab6bac9b4207307c5f020fa670fc3948c39e7ea93c7fb9dfb5174 \
                    vproc_priv.h \
                    rmd160  ea1fb112d58a168c581ee58e761c26f7caed40ec \
                    sha256  dcd2786d82865fb10542c20e97d7052110f7ca9a551f2ab5628c607f20e2bb2f

patchfiles          patch-maxargs \
                    patch-windowsize \
                    patch-Makefile.in \
                    patch-process.c-fix-bogus-strncpy-size.diff
depends_lib         port:ncurses

extract.only        ${distname}${extract.suffix}
post-extract {
    file copy ${distpath}/18 ${workpath}
}
configure.args      --mandir=${prefix}/share/man \
                    --infodir=${prefix}/share/info \
                    --enable-telnet \
                    --enable-colors256 \
                    --enable-rxvt_osc

post-destroot {
    xinstall -m 644 ${workpath}/18 ${destroot}${prefix}/share/${name}/utf8encodings
    xinstall -m 644 ${worksrcpath}/etc/etcscreenrc ${destroot}${prefix}/etc/screenrc
    xinstall -m 644 ${worksrcpath}/terminfo/screencap ${destroot}${prefix}/etc/termcap
    system "tic ${worksrcpath}/terminfo/screeninfo.src"
}

platform darwin {
    patchfiles-append   patch-configure-libelf
}

platform darwin 9 {
    post-patch {
        reinplace s|^deflogin|#deflogin| ${worksrcpath}/etc/etcscreenrc
    }

    # These patches are based on http://www.opensource.apple.com/darwinsource/10.5.6/screen-12/patches/
    # The vproc_priv.h is the private header from launchd, used in Apple's 10.5 screen patches
    # We copied the header file from http://launchd.macosforge.org/trac/browser/trunk/launchd/src/vproc_priv.h, r23776
    distfiles-append    vproc_priv.h:launchd_priv_header
    post-extract {
        file copy ${distpath}/vproc_priv.h ${worksrcpath}
    }
    patchfiles-append   patch-config.h.in patch-configure patch-window.c patch-screen.c-leopard
}

if {${os.platform} eq "darwin" && ${os.major} >= 10 && ${os.major} <= 13} {
    # These patches are based on http://www.opensource.apple.com/source/screen/screen-16/patches/
    # The vproc_priv.h is the private header from launchd, used in Apple's 10.6 screen patches
    # We copied the header file from http://launchd.macosforge.org/trac/browser/trunk/launchd/src/vproc_priv.h, r23776
    distfiles-append    vproc_priv.h:launchd_priv_header
    post-extract {
        file copy ${distpath}/vproc_priv.h ${worksrcpath}
    }
    patchfiles-append   patch-config.h.in patch-configure patch-window.c patch-screen.c
}

notes "
Any screens running before upgrading, will not be available, post-install.
"
