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

perl5.require_variant   yes
perl5.conflict_variants yes
perl5.branches          5.28 5.30 5.32 5.34
perl5.default_branch    5.34
perl5.create_variants   ${perl5.branches}
# since variants are set to conflict, only one can be installed at a time
# therefore omit version suffixes on linked binaries
perl5.link_binaries_suffix

github.setup            XMLTV xmltv 1.2.1 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from     tarball
perl5.setup             xmltv 1.2.1

checksums           rmd160  435b87a4cc489675fcc36f53f8f2f49163326fe5 \
                    sha256  afa75a362ee062b958714cbed93953cd713ee578d7f92724e40752d053a60657 \
                    size    786061

description             utilities to download tv listings and format them in xml 
long_description        {*}${description}

master_sites            {*}${github.master_sites}
license                 GPL-2
maintainers             nomaintainer

homepage                http://www.xmltv.org/
platforms               {darwin any}
supported_archs         noarch
categories              multimedia textproc

patchfiles              patch_Makefile.PL.diff

post-patch {
    fs-traverse f [list ${worksrcpath}] {
        if {[file isfile ${f}]} {
            switch [file extension ${f}] {
                .ico -
                .jpg -
                .png {
                    # Don't touch binary files
                }
                default {
                    reinplace -locale C -q "s|#!/usr/bin/perl|#!${perl5.bin}|" ${f}
                }
            }
        }
    }
}

depends_lib-append      port:p${perl5.major}-archive-zip \
                        port:p${perl5.major}-cgi \
                        port:p${perl5.major}-date-manip \
                        port:p${perl5.major}-datetime \
                        port:p${perl5.major}-datetime-timezone \
                        port:p${perl5.major}-datetime-format-strptime \
                        port:p${perl5.major}-datetime-format-iso8601 \
                        port:p${perl5.major}-datetime-format-sqlite \
                        port:p${perl5.major}-dbd-sqlite \
                        port:p${perl5.major}-dbi \
                        port:p${perl5.major}-file-homedir \
                        port:p${perl5.major}-file-slurp \
                        port:p${perl5.major}-file-which \
                        port:p${perl5.major}-http-cache-transparent \
                        port:p${perl5.major}-json \
                        port:p${perl5.major}-json-xs \
                        port:p${perl5.major}-lingua-preferred \
                        port:p${perl5.major}-list-moreutils \
                        port:p${perl5.major}-lwp-protocol-https \
                        port:p${perl5.major}-lwp-useragent-determined \
                        port:p${perl5.major}-soap-lite \
                        port:p${perl5.major}-term-progressbar \
                        port:p${perl5.major}-term-readkey \
                        port:p${perl5.major}-tk \
                        port:p${perl5.major}-tk-tablematrix \
                        port:p${perl5.major}-unicode-string \
                        port:p${perl5.major}-xml-libxml \
                        port:p${perl5.major}-xml-parser \
                        port:p${perl5.major}-xml-treepp \
                        port:p${perl5.major}-xml-twig \
                        port:p${perl5.major}-xml-writer \
                        port:p${perl5.major}-xml-dom \
                        port:p${perl5.major}-xml-libxslt \
                        port:sqlite3

# These dependencies are missing for tv_grab_it_dvb:
#    Linux::DVB
# These dependencies are missing for tv_grab_pt_vodafone:
#    URI::Encode
# the scripts are created but not linked by port select

set xmlbin              ${prefix}/libexec/perl${perl5.major}
set xmllnk              ${prefix}/bin
set docdir              ${prefix}/share/doc/${name}

post-destroot {
# build system creates these scripts even though they're known to be broken
    file delete ${destroot}${xmlbin}/tv_grab_it_dvb
    file delete ${destroot}${xmllnk}/tv_grab_it_dvb
    file delete ${destroot}${xmlbin}/tv_grab_pt_vodafone
    file delete ${destroot}${xmllnk}/tv_grab_pt_vodafone

    xinstall -m 0755 -d ${destroot}${docdir}

# note that changing the destroot.target from pure_install (as set by 
# the portgroup) to install will install the following plus
# several example files
    xinstall -m 0644 -W ${worksrcpath} \
        COPYING \
        README.md \
        authors.txt \
        xmltv-lineups.xsd \
        xmltv.dtd \
        xmltv_logo.ico \
        xmltv_logo.png \
        doc/QuickStart \
        ${destroot}${docdir}
}

livecheck.type      regex
livecheck.url       ${github.homepage}/tags
livecheck.regex     v(\\d+(?:\\.\\d+)*).tar.gz
