# -*- 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           github 1.0
PortGroup           makefile 1.0

github.setup        davidgiven wordgrinder 0.8
revision            0
checksums           rmd160  2624730aa538162f134f80ece6804e2435c7fa8c \
                    sha256  856cbed2b4ccd5127f61c4997a30e642d414247970f69932f25b4b5a81b18d3f \
                    size    2015849

categories          editors
license             MIT
platforms           darwin
maintainers         nomaintainer
description         WordGrinder, lightweight character-cell word processor designed for the console
long_description    WordGrinder is a light-weight character-cell word processor designed for text\
                    entry on the console, supporting Unicode and styled text. It provides a clean,\
                    easy-to-use interface that gets out of your way and get the job done.

homepage            http://cowlark.com/wordgrinder/
github.tarball_from archive

depends_build       port:ninja \
                    port:pkgconfig

# Setting SOURCE_DATE_EPOCH requires GNU date.
# https://github.com/davidgiven/wordgrinder/issues/150
depends_build-append \
                    path:libexec/coreutils/libstdbuf.so:coreutils

depends_lib         port:minizip \
                    port:ncurses \
                    port:zlib

post-extract {
    # Base doesn't set SOURCE_DATE_EPOCH so we have to.
    # https://trac.macports.org/ticket/59672
    set latest 0
    fs-traverse i [list ${worksrcpath}] {
        if {[file isfile ${i}]} {
            set t [file mtime ${i}]
            if {${t} > ${latest}} {
                set latest ${t}
            }
        }
    }
    set fp [open $env(TMPDIR)/SOURCE_DATE_EPOCH w]
    puts -nonewline ${fp} ${latest}
    close ${fp}
}

patchfiles          Makefile.patch

build.env           CURSES_PACKAGE=ncursesw \
                    LPEG_PACKAGE=builtin \
                    LUA_PACKAGE=builtin \
                    LUABITOP_PACKAGE=builtin \
                    MINIZIP_PACKAGE=minizip \
                    UTHASH_PACKAGE=builtin \
                    XFT_PACKAGE=none

# Disable silent rules.
build.env-append    hide=

# The value of DESTDIR gets baked in at build time.
# https://github.com/davidgiven/wordgrinder/issues/41
build.env-append    DESTDIR=${destroot}

pre-build {
    set fp [open $env(TMPDIR)/SOURCE_DATE_EPOCH r]
    set latest [read ${fp}]
    close ${fp}
    build.env-append \
                    SOURCE_DATE_EPOCH=${latest}
}

post-destroot {
    # Delete the files that aren't for this subport.
    set isxwordgrinder [expr {${subport} eq {xwordgrinder}}]
    fs-traverse i [list ${destroot}] {
        if {![file isdirectory ${i}]} {
            if {[string match xwordgrinder* [file tail ${i}]] != ${isxwordgrinder}} {
                delete ${i}
            }
        }
    }
}

subport xwordgrinder {
    depends_lib-append \
                    port:freetype \
                    port:Xft2 \
                    port:xorg-libX11

    build.env-replace \
                    XFT_PACKAGE=none \
                    "XFT_PACKAGE=--cflags={-I${prefix}/include/X11} --libs={-lX11 -lXft}"
}

if {${subport} ne ${name}} {
    livecheck.type  none
}
