# -*- 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.4
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  080bed37454d3a7cafc18a374b4a175e2e87061f \
		    sha256  3e2ae08f40efa0c3701e54a954cefa08242de22a69f91a8ae44fc1e624ba309b \
		    size    441511

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

# regen configure script for implicit int fix
use_autoconf        yes

configure.ccache    no

# apr_passwd.c:73:20: error: missing binary operator before token "("
compiler.blacklist-append \
                    *gcc-4.* {clang < 421}

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

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

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

pre-build {
	if {[variant_exists universal] && [variant_isset universal]} {
		build.args	EXTRA_CFLAGS='${configure.universal_cflags}' \
				EXTRA_LDFLAGS='${configure.universal_ldflags}'
	} else {
        build.args  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}
