# -*- 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        apr-util
version     1.6.5
revision    0
categories  devel
maintainers {geeklair.net:dluke @danielluke}
license     Apache-2
description utilities built with the apache group's portability library
long_description \
            ${name} is a library of useful utilities built with \
            and intended to be used with the Apache Portable Runtime.

homepage        https://apr.apache.org
master_sites    apache:apr
use_bzip2       yes
checksums       rmd160  9f3b12133f954b49f440999db238c5c3bd39172a \
                sha256  96de1dd6f6a0476d2d2e7964926d8c1ddc3bb0e210e1b1812d3ba5a454a392e2 \
                size    442045

# TODO: apr-util builds fine with Apple gcc, but if it is built with gcc-16, it is broken:
# `svn --version` crashes on check_sbcs with Illegal instruction. Cause is unknown at the moment.

depends_lib port:apr \
            port:db48 \
            port:expat \
            port:libiconv \
            port:sqlite3

# https://trac.macports.org/wiki/UsingTheRightCompiler
patchfiles-append \
            patch-using_the_right_compiler.diff \
            patch-apr_passwd.c.diff

# regen configure script for implicit int fix
use_autoreconf      yes

configure.ccache    no

# Use the right pre-processor as well:
configure.env-append \
            CPP=${configure.cpp}

set extralibs "-L${prefix}/lib/db48"

pre-configure {
    reinplace "s|^Libs: |Libs: ${extralibs} |" $worksrcpath/apr-util.pc.in
}

configure.args-append \
            --with-apr=${prefix}/bin/apr-1-config \
            --with-berkeley-db=${prefix}/include:${prefix}/lib/db48 \
            --with-expat=${prefix} \
            --with-iconv=${prefix} \
            --with-sqlite3=${prefix} \
            --without-mysql \
            --without-odbc \
            --without-pgsql \
            --without-sqlite2

pre-build {
    if {[variant_exists universal] && [variant_isset universal]} {
        build.args-append \
                    EXTRA_CFLAGS='${configure.universal_cflags}' \
                    EXTRA_LDFLAGS='${configure.universal_ldflags}'
    } else {
        build.args-append \
                    EXTRA_CFLAGS='${configure.cc_archflags}' \
                    EXTRA_LDFLAGS='${configure.ld_archflags}'
    }
}

variant no_bdb description "Build without BerkeleyDB support" {
    depends_lib-delete port:db48
    configure.args-delete --with-berkeley-db=${prefix}/include:${prefix}/lib/db48
    configure.args-append --without-berkeley-db
}

variant no_sqlite description "Build without sqlite support" {
    depends_lib-delete port:sqlite3
    configure.args-delete --with-sqlite3=${prefix}
    configure.args-append --without-sqlite3
}

variant openldap description "Build with OpenLDAP support" {
    depends_lib-append path:lib/libldap.dylib:openldap
    configure.args-append --with-ldap \
        --with-ldap-include=${prefix}/include \
        --with-ldap-lib=${prefix}/lib
}

variant postgresql16 description "Build with postgres support (using postgresql v16)" {
    depends_lib-append port:postgresql16
    configure.args-delete --without-pgsql
    configure.args-append --with-pgsql=yes
}

variant mysql51 conflicts mysql55 mysql56 mariadb description "Enable MySQL 5.1 support" {
    depends_lib-append port:mysql51
    configure.args-replace --without-mysql --with-mysql
    configure.env-append MYSQL_CONFIG=${prefix}/lib/mysql51/bin/mysql_config
}

variant mysql55 conflicts mysql51 mysql56 mariadb description "Enable MySQL 5.5 support" {
    depends_lib-append port:mysql55
    configure.args-replace --without-mysql --with-mysql
    configure.env-append MYSQL_CONFIG=${prefix}/lib/mysql55/bin/mysql_config
}

variant mysql56 conflicts mysql51 mysql55 mariadb description "Enable MySQL 5.6 support" {
    depends_lib-append port:mysql56
    configure.args-replace --without-mysql --with-mysql
    configure.env-append MYSQL_CONFIG=${prefix}/lib/mysql56/bin/mysql_config
}

variant mariadb conflicts mysql51 mysql55 mysql56 description "Enable MariaDB (MySQL) support" {
    depends_lib-append port:mariadb
    configure.args-replace --without-mysql --with-mysql
    configure.env-append MYSQL_CONFIG=${prefix}/lib/mariadb/bin/mysql_config
}

test.run    yes
test.target check
test.env    DYLD_LIBRARY_PATH=${worksrcpath}/.libs
pre-test {
    use_parallel_build	no
}

livecheck.type  regex
livecheck.url   https://apr.apache.org/
livecheck.regex {APR-util (\d+(?:\.\d+)*), released}
