# -*- 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                fortune
version             6.2.0-RELEASE
revision            1
categories          games
platforms           darwin freebsd
maintainers         nomaintainer
license             BSD
installs_libs       no

description         Infamous electronic fortune-cookie generator

long_description    ${description}

homepage            https://www.freebsd.org/
master_sites        macports
use_bzip2           yes

checksums           md5     6185fe31e512e8b23ac5cc58ede27919

worksrcdir          ${name}

patchfiles          patch-fortune-Makefile \
                    patch-strfile-Makefile \
                    patch-unstr-Makefile \
                    patch-datfiles-Makefile \
                    patch-strfile.h

post-patch {
    reinplace "s|/usr|${prefix}|" ${worksrcpath}/fortune/pathnames.h
    reinplace "s|/usr/share|${prefix}/share|" ${worksrcpath}/fortune/fortune.6
    reinplace "s|/usr/games/fortune|${prefix}/bin/fortune|" ${worksrcpath}/fortune/fortune.6
    move ${worksrcpath}/datfiles/fortunes2-o ${worksrcpath}/datfiles/fortunes2-o.real
    move ${worksrcpath}/datfiles/limerick ${worksrcpath}/datfiles/limerick-o.real
    move ${worksrcpath}/datfiles/murphy-o ${worksrcpath}/datfiles/murphy-o.real
}

use_configure       no

variant universal {}

build.type          bsd
build.env-append    CFLAGS=[get_canonical_archflags] \
                    CC=${configure.cc}

destroot {
    xinstall -m 755 -W ${worksrcpath} fortune/fortune strfile/strfile \
        unstr/unstr ${destroot}${prefix}/bin
    
    xinstall -m 644 ${worksrcpath}/fortune/fortune.6.gz \
        ${destroot}${prefix}/share/man/man6
    xinstall -m 644 ${worksrcpath}/strfile/strfile.8.gz \
        ${destroot}${prefix}/share/man/man8
    xinstall -m 644 ${worksrcpath}/strfile/strfile.8.gz \
        ${destroot}${prefix}/share/man/man8/unstr.8.gz
    
    xinstall -m 755 -d ${destroot}${prefix}/share/games/fortune
    xinstall -m 644 -W ${worksrcpath}/datfiles \
        fortunes fortunes.dat fortunes-o fortunes-o.dat \
        fortunes2-o fortunes2-o.dat limerick-o limerick-o.dat \
        murphy murphy.dat murphy-o murphy-o.dat \
        startrek startrek.dat zippy zippy.dat \
        ${destroot}${prefix}/share/games/fortune
}

platform darwin {
    patchfiles-append patch-fortune.c patch-strfile.c patch-unstr.c
}
