# -*- 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                sphinx
version             2.2.11
revision            1
categories          textproc net
license             GPL-2
maintainers         nomaintainer

description         Sphinx is a full-text search engine

long_description    Sphinx is a full-text search engine, meant to provide \
                    fast, size-efficient and relevant fulltext search \
                    functions to other applications. Sphinx was specially \
                    designed to integrate well with SQL databases and \
                    scripting languages. Currently built-in data sources \
                    support fetching data either via direct connection to \
                    MySQL or PostgreSQL, or from an XML pipe.

homepage            http://sphinxsearch.com/
master_sites        ${homepage}files/
distname            ${name}-${version}-release

checksums           rmd160  5804b4cce64bc03fa20bac26c7391cd661cecc77 \
                    sha256  6662039f093314f896950519fa781bc87610f926f64b3d349229002f06ac41a9

if {${name} eq ${subport}} {
depends_lib         port:expat \
                    port:libiconv

post-extract {
    # Copy launchd plists to worksrcpath
    file copy ${filespath}/org.macports.${name}.plist ${worksrcpath}/org.macports.${name}.plist
}

post-patch {
    reinplace "s|@NAME@|${name}|g" ${worksrcpath}/org.macports.${name}.plist
    reinplace "s|@PREFIX@|${prefix}|g" ${worksrcpath}/org.macports.${name}.plist
}

configure.args      --datadir=${prefix}/share/doc \
                    --sysconfdir=${prefix}/etc/${name} \
                    --localstatedir=${prefix}/var/${name} \
                    --without-mysql \
                    --without-unixodbc

destroot.keepdirs   ${destroot}${prefix}/var/${name}/data \
                    ${destroot}${prefix}/var/${name}/log
post-destroot {
    file mkdir ${destroot}${prefix}/share/${name}
    copy ${worksrcpath}/api \
        ${destroot}${prefix}/share/${name}/api
    file mkdir ${destroot}${prefix}/var/${name}/data
    file mkdir ${destroot}${prefix}/var/${name}/log
}

post-activate {
    if {![file exists ${prefix}/etc/${name}/${name}.conf]} {
        copy ${prefix}/etc/${name}/${name}.conf.dist \
            ${prefix}/etc/${name}/${name}.conf
    }
}

startupitem.type        launchd
startupitem.create      no
startupitem.custom_file ${worksrcpath}/org.macports.${name}.plist

test.run            yes

variant postgresql91 conflicts postgresql92 postgresql93 postgresql94 postgresql95 postgresql96 description {Enable PostgreSQL 9.1 support} {
    depends_lib-append      port:postgresql91
    configure.args-append   --with-pgsql \
                            --with-pgsql-includes=${prefix}/include/postgresql91 \
                            --with-pgsql-libs=${prefix}/lib/postgresql91
}

variant postgresql92 conflicts postgresql91 postgresql93 postgresql94 postgresql95 postgresql96 description {Enable PostgreSQL 9.2 support} {
    depends_lib-append      port:postgresql92
    configure.args-append   --with-pgsql \
                            --with-pgsql-includes=${prefix}/include/postgresql92 \
                            --with-pgsql-libs=${prefix}/lib/postgresql92
}

variant postgresql93 conflicts postgresql91 postgresql92 postgresql94 postgresql95 postgresql96 description {Enable PostgreSQL 9.3 support} {
    depends_lib-append      port:postgresql93
    configure.args-append   --with-pgsql \
                            --with-pgsql-includes=${prefix}/include/postgresql93 \
                            --with-pgsql-libs=${prefix}/lib/postgresql93
}

variant postgresql94 conflicts postgresql91 postgresql92 postgresql93 postgresql95 postgresql96 description {Enable PostgreSQL 9.4 support} {
    depends_lib-append      port:postgresql94
    configure.args-append   --with-pgsql \
                            --with-pgsql-includes=${prefix}/include/postgresql94 \
                            --with-pgsql-libs=${prefix}/lib/postgresql94
}

variant postgresql95 conflicts postgresql91 postgresql92 postgresql93 postgresql94 postgresql96 description {Enable PostgreSQL 9.5 support} {
    depends_lib-append      port:postgresql95
    configure.args-append   --with-pgsql \
                            --with-pgsql-includes=${prefix}/include/postgresql95 \
                            --with-pgsql-libs=${prefix}/lib/postgresql95
}

variant postgresql96 conflicts postgresql91 postgresql92 postgresql93 postgresql94 postgresql95 description {Enable PostgreSQL 9.6 support} {
    depends_lib-append      port:postgresql96
    configure.args-append   --with-pgsql \
                            --with-pgsql-includes=${prefix}/include/postgresql96 \
                            --with-pgsql-libs=${prefix}/lib/postgresql96
}

variant mysql51 conflicts mysql55 mysql56 mysql57 mariadb description {Enable MySQL 5.1 support} {
    depends_lib-append      port:mysql51
    configure.args-delete   --without-mysql
    configure.args-append   --with-mysql=${prefix}/lib/mysql51
}

variant mysql55 conflicts mysql51 mysql56 mysql57 mariadb description {Enable MySQL 5.5 support} {
    depends_lib-append      port:mysql55
    configure.args-delete   --without-mysql
    configure.args-append   --with-mysql=${prefix}/lib/mysql55
}

variant mysql56 conflicts mysql51 mysql55 mysql57 mariadb description {Enable MySQL 5.6 support} {
    depends_lib-append      port:mysql56
    configure.args-delete   --without-mysql
    configure.args-append   --with-mysql=${prefix}/lib/mysql56
}

variant mysql57 conflicts mysql51 mysql55 mysql56 mariadb description {Enable MySQL 5.7 support} {
    depends_lib-append      port:mysql57
    configure.args-delete   --without-mysql
    configure.args-append   --with-mysql=${prefix}/lib/mysql57
}

variant mariadb conflicts mysql51 mysql55 mysql56 mysql57 description {Enable MariaDB support} {
    depends_lib-append      port:mariadb
    configure.args-delete   --without-mysql
    configure.args-append   --with-mysql=${prefix}/lib/mariadb
}

if {![variant_isset postgresql91] && ![variant_isset postgresql92] && ![variant_isset postgresql93] && ![variant_isset postgresql94] && ![variant_isset postgresql95] && ![variant_isset postgresql96] && ![variant_isset mysql51] && ![variant_isset mysql55] && ![variant_isset mysql56] && ![variant_isset mariadb]} {
    default_variants +mysql57
}

livecheck.type      regex
livecheck.url       ${homepage}downloads/release/
livecheck.regex     ${name}-(\[0-9.\]+)-release${extract.suffix}
} else {
    livecheck.type      none
}

subport libsphinxclient {
    license             LGPL-2
    
    description         C library to talk to the Sphinx full-text search engine
    
    long_description    {*}${description}
    
    worksrcdir          ${worksrcdir}/api/${subport}
    
    patchfiles-append   libsphinxclient.patch
    
    # build shared library too
    use_autoreconf      yes
    autoreconf.args     -fvi
}
