# -*- 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
# $Id: Portfile 108403 2013-07-22 19:14:54Z michaelld@macports.org $

PortSystem          1.0

# use the qt4 group; set 'building_qt4' so that the portgroup
# does not include certain parts
set building_qt4    1
PortGroup           qt4 1.0
PortGroup           xcodeversion 1.0

name                qt4-mac-mysql55-plugin
version             4.8.5
categories          aqua databases
platforms           macosx
maintainers         michaelld pixilla openmaintainer
license             {LGPL-2.1 GPL-3}

homepage            http://qt.nokia.com/

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

checksums           sha1    745f9ebf091696c0d5403ce691dc28c039d77b9e \
                    rmd160  1e7bb099d5d1cda0b663cebe207c846c8d04750d

dist_subdir         qt4-mac
depends_lib-append  port:qt4-mac

set DB              mysql
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

configure.dir       ${worksrcpath}/${PLUGIN}
configure.env-append \
                    QMAKESPEC=${qt_mkspecs_dir}/macx-g++
configure.cmd       ${qt_qmake_cmd}
configure.pre_args  PREFIX=${prefix}

if {[variant_isset universal]} {

    configure.universal_args-delete --disable-dependency-tracking
}

set mp.ports     {mysql5 mysql51 mysql55 mariadb percona}
foreach mp.port ${mp.ports} {

    lappend mp.names "qt4-mac-${mp.port}-plugin"
}

foreach mp.name ${mp.names} {

    set idx [lsearch ${mp.names} ${mp.name}]
    set mp.port [lindex ${mp.ports} $idx]
    set mp.conflicts [lreplace ${mp.names} $idx $idx]

    if {[string compare ${mp.name} ${name}] == 0 && [string compare ${mp.name} ${subport}] == 0} {

        description         Qt MySQL database plugin for ${mp.port}
        long_description    ${description}
        conflicts-append    ${mp.conflicts}
        depends_lib-append  port:${mp.port}
        configure.args      INCLUDEPATH+="${prefix}/include ${prefix}/include/${mp.port}/mysql" \
                            LIBS+="-L${prefix}/lib -L${prefix}/lib/${mp.port} -L${prefix}/lib/${mp.port}/mysql -lmysqlclient_r"
        configure.post_args mysql.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
            }
        }

    } else {

        subport ${mp.name} {
        
            description         Qt MySQL database plugin for ${mp.port}
            long_description    ${description}
            conflicts-append    ${mp.conflicts}
            depends_lib-append  port:${mp.port}
            configure.args      INCLUDEPATH+="${prefix}/include ${prefix}/include/${mp.port}/mysql" \
                                LIBS+="-L${prefix}/lib -L${prefix}/lib/${mp.port} -L${prefix}/lib/${mp.port}/mysql -lmysqlclient_r"
            configure.post_args mysql.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
                }
            }
        }
    }
}

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

livecheck.type      regex
livecheck.url       http://releases.qt-project.org/qt4/source
livecheck.regex     "qt-everywhere-opensource-src-(\[0-9a-z.-\]+)${extract.suffix}"
