# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 116256 2014-01-23 12:20:28Z nicos@macports.org $

PortSystem      1.0
PortGroup       compiler_blacklist_versions 1.0
PortGroup       muniversal 1.0

name            poppler
conflicts       pdf2json xpdf-tools
version         0.24.5
license         GPL-2+
maintainers     devans openmaintainer
categories      graphics
platforms       darwin
homepage        http://${name}.freedesktop.org/

description     Poppler is a PDF rendering library based on the xpdf-3.0 code base.
long_description \
                ${description}

master_sites    ${homepage}

use_xz          yes

checksums       rmd160  34a017f79e624091a62845beb26b3f81fb971645 \
                sha256  a2654910100c923c44e366242495e226db2798254f2fa2781138867348759f84

depends_build   port:pkgconfig

depends_lib     port:bzip2 \
                port:curl \
                port:expat \
                port:fontconfig \
                port:freetype \
                port:gobject-introspection \
                port:jpeg \
                path:lib/pkgconfig/glib-2.0.pc:glib2 \
                path:lib/pkgconfig/cairo.pc:cairo \
                port:lcms2 \
                port:libpng \
                port:openjpeg15 \
                port:poppler-data \
                port:tiff \
                port:zlib

# Generate newer libtool that passes -stdlib when linking dylibs.
use_autoreconf  yes
autoreconf.args -fvi

compiler.blacklist {gcc-4.0 < 5493}

configure.args  --disable-poppler-qt4 \
                --disable-poppler-qt5 \
                --disable-gtk-test \
                --disable-silent-rules \
                --enable-xpdf-headers \
                --enable-zlib \
                --enable-libcurl \
                --enable-introspection=yes

post-patch {
    # clang: error: unknown argument: '-fno-check-new'
    # Strip it out rather than --disable-compile-warnings
    reinplace "s:-fno-check-new::g" ${worksrcpath}/configure.ac
}

# gobject-introspection uses g-ir-scanner, which uses $CC from env

if {[variant_isset universal]} {
    foreach arch ${configure.universal_archs} {
        lappend merger_build_args(${arch})  CC='${configure.cc} -arch ${arch}'
    }
} else {
    build.args-append       CC="${configure.cc} ${configure.cc_archflags}"
}

# TODO:
# add subport for poppler-qt4-x11 when qt4-x11 builds and port group qt4 allows
# add subport(s) for poppler-qt5-* when a qt5 port is available

subport poppler-qt4-mac {
    PortGroup qt4 1.0
    revision    1
    
    depends_lib-append port:poppler
    configure.args-delete --disable-poppler-qt4
    configure.args-append --disable-cairo-output \
                          --disable-poppler-glib \
                          --disable-poppler-cpp \
                          --disable-utils
    post-destroot {
        foreach dot_h [glob -nocomplain -directory ${destroot}${prefix}/include/poppler *.h] {
            delete $dot_h
        }
        delete ${destroot}${prefix}/include/poppler/fofi \
               ${destroot}${prefix}/include/poppler/goo \
               ${destroot}${prefix}/include/poppler/splash \
               ${destroot}${prefix}/lib/libpoppler.44.dylib \
               ${destroot}${prefix}/lib/libpoppler.a \
               ${destroot}${prefix}/lib/libpoppler.dylib \
               ${destroot}${prefix}/lib/libpoppler.la \
               ${destroot}${prefix}/lib/pkgconfig/poppler-splash.pc \
               ${destroot}${prefix}/lib/pkgconfig/poppler.pc
    }
}

platform darwin 8 {
    # The rules enabled by gobject-introspection require GNU make 3.81+ (#39144)
    depends_build-append    port:gmake
    build.cmd               ${prefix}/bin/gmake
}

livecheck.type  regex
livecheck.url   ${master_sites}
livecheck.regex ${name}-(\[0-9\]+\\.\[0-9\]*\[02468\](\\.\[0-9\]+)*)${extract.suffix}
