# -*- 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             sunclock
version          3.57
revision         1
categories       x11
maintainers      nomaintainer
license          GPL-2
description      shows Earth's surface illuminated by the Sun
long_description \
    This program is a clock that shows which portion of the \
    Earth's surface is illuminated by the sun. It is designed \
    to be usually iconic, but can be opened for a larger \
    display with the time updated every second and both the \
    local time zone and UTC displayed.
homepage         https://web.archive.org/web/20080821132523/http://www.arvernes.com/wiki/index.php/Sunclock
platforms        darwin

distname         ${name}_${version}.orig
worksrcdir       ${name}-${version}
master_sites     debian:s/${name}
checksums        rmd160 42ef99381405745bf2be13ad9c05c9f07e5ff1cd \
                 sha256 f3b3499b4a84c7a31411d2a9043e2d9171b745ec29a991ef9930ce582b9d41ab

depends_lib      path:include/turbojpeg.h:libjpeg-turbo port:xpm port:zlib port:libpng port:xorg-libX11
patchfiles       gzFile.patch

post-patch {
    reinplace "/#include <malloc.h>/d" ${worksrcpath}/tildepath.c
}

use_configure    no

set datadir ${prefix}/share/${name}
set docdir  ${prefix}/share/doc/${name}

configure.cflags-append -Wall -DZLIB
configure.cflags-append {-DSHAREDIR=\\\"${datadir}\\\"}
configure.cflags-append {-DEMXBINDIR=\\\"${prefix}/bin\\\"}
configure.cflags-append {-DDOCDIR=\\\"${docdir}\\\"}
configure.ldflags-append -lXpm -ljpeg -lpng -lz -lX11

build.env-append prefix=${prefix} datadir=${datadir} docdir=${docdir}

build.pre_args   -f Makefile.noimake
build.target     all
build.args \
    DESTDIR=${prefix} \
    MANDIR=/share/man/man1 \
    XAPPLOADDIR=/share/X11/app-defaults \
    XBINDIR=/bin \
    CC=${configure.cc} \
    CFLAGS="[join ${configure.cflags}] [get_canonical_archflags] ${configure.optflags}" \
    LFLAGS="${configure.ldflags} [get_canonical_archflags]"

destroot {
    xinstall -m 755 -W ${worksrcpath} sunclock editkit/emx ${destroot}${prefix}/bin
    xinstall -m 644 -W ${worksrcpath} sunclock.man ${destroot}${prefix}/share/man/man1/sunclock.1

    xinstall -d -m 755 ${destroot}${datadir}
    xinstall -m 644 -W ${worksrcpath} Sunclockrc ${destroot}${datadir}

    xinstall -d -m 755 ${destroot}${datadir}/earthmaps/vmf
    xinstall -m 644 {*}[glob ${worksrcpath}/vmf/*.vmf] ${destroot}${datadir}/earthmaps/vmf

    xinstall -d -m 755 ${destroot}${datadir}/earthmaps/i18n
    xinstall -m 644 {*}[glob ${worksrcpath}/i18n/Sunclock.??] ${destroot}${datadir}/earthmaps/i18n

    xinstall -d -m 755 ${destroot}${docdir}
    xinstall -m 644 -W ${worksrcpath}/editkit MANUAL.emacs README ${destroot}${docdir}
}
