# -*- 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

# use the qt4 group (indirectly via the qmake PortGroup); set
# 'building_qt4' so that the portgroup does not include certain parts
set building_qt4    1
PortGroup           qmake 1.0

name                qt4-mac-sqlite2-plugin
version             4.8.7
revision            2
set branch          [join [lrange [split ${version} .] 0 1] .]
categories          aqua databases
platforms           macosx
maintainers         {michaelld @michaelld} openmaintainer
license             {LGPL-2.1 GPL-3}
homepage            http://www.qt.io/

master_sites        http://download.qt.io/official_releases/qt/${branch}/${version}/

distname            qt-everywhere-opensource-src-${version}

checksums           rmd160 afb5e5a99388e6429faca59cb5000054feffd166 \
                    sha256 e2882295097e47fe089f8ac741a95fef47e0a73a3f3cdf21b56990638f626ea0

dist_subdir         qt4-mac

# when using 'building_qt4' and qmake, have to include dependency on qt4-mac
depends_lib-append  port:qt4-mac

qt4.debug_variant   no

if {${name} == ${subport}} {

    set DB              sqlite2

    description         Qt sqlite database plugin for sqlite2
    long_description    ${description}
    conflicts-append    qt4-mac-sqlite3-plugin
    depends_lib-append  port:sqlite2
    configure.args-append \
                        INCLUDEPATH+=${worksrcpath}/include \
                        LIBS+="-L${prefix}/lib -lsqlite"

    configure.post_args sqlite2.pro

    variant debug description {Build both release and debug plugin} {}

    pre-configure {
        configure.args-append CONFIG+=\"${qt_arch_types}\"
    }

    post-patch {
        if {![variant_isset debug]} {
            reinplace "s@debug_and_release@release@" \
                ${worksrcpath}/src/plugins/qpluginbase.pri
        }
    }

}

subport qt4-mac-sqlite3-plugin {

    set DB              sqlite

    description         Qt sqlite database plugin for sqlite3
    long_description    ${description}
    conflicts-append    qt4-mac-sqlite2-plugin
    depends_lib-append  port:sqlite3
    configure.args-append INCLUDEPATH+=${worksrcpath}/include \
                        LIBS+="-L${prefix}/lib -lsqlite3"
    configure.post_args sqlite.pro

    variant debug description \
        {Build both release and debug plugin} {}

    pre-configure {
        configure.args-append CONFIG+=\"${qt_arch_types}\"
    }

    post-patch {
        if {![variant_isset debug]} {
            reinplace "s@debug_and_release@release@" \
                ${worksrcpath}/src/plugins/qpluginbase.pri
        }
    }
}

set DRIVER          src/sql/drivers/${DB}
set PLUGIN          src/plugins/sqldrivers/${DB}

extract.post_args   | tar -xf - \
                    ${distname}/${DRIVER} \
                    ${distname}/${PLUGIN} \
                    ${distname}/src/plugins/sqldrivers/qsqldriverbase.pri \
                    ${distname}/src/plugins/qpluginbase.pri \
                    ${distname}/src/qt_targets.pri \
                    ${distname}/include/QtSql/private \
                    ${distname}/src/sql/kernel

configure.dir       ${worksrcpath}/${PLUGIN}
configure.env-append \
                    QMAKESPEC=${qt_mkspecs_dir}/macx-g++

build.dir           ${worksrcpath}/${PLUGIN}
build.target        {}

# see https://trac.macports.org/ticket/59923
if {[string match *clang* ${configure.compiler}] && ${configure.cxx_stdlib} ne ""} {
    configure.ldflags-append \
                    -stdlib=${configure.cxx_stdlib}
}

livecheck.type      regex
livecheck.url       http://download.qt.io/official_releases/qt/${branch}/
livecheck.regex     >(\[0-9.\]+)/<
