# -*- 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
PortGroup           cmake                        1.1
PortGroup           compiler_blacklist_versions  1.0
PortGroup           github                       1.0
PortGroup           legacysupport                1.1

github.setup        xrootd xrootd 5.7.3 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            0

checksums           rmd160  35b1667e54301459177c3ac045f3bec9b2239e4e \
                    sha256  b1679f21dc633f98bd5f5532e8f4d76d678af146db496a742173d5755e835fcc \
                    size    6879918

categories          science
maintainers         {jonesc @cjones051073} openmaintainer

description         Generic suite for fast, low-latency and scalable data access.
long_description    {*}${description}

license             LGPL-3+

homepage            http://xrootd.org/

depends_build-append port:cctools \
                     port:pkgconfig

depends_lib-append  port:curl \
                    port:libxml2 \
                    port:json-c \
                    port:swig \
                    port:tinyxml \
                    path:lib/libuuid.dylib:ossp-uuid \
                    port:zlib

default_variants    +ssl +readline +kerberos

cmake.out_of_source yes

# Force a compatible compiler
compiler.blacklist-append *gcc-4.* {clang < 900} {macports-clang-3.[0-9]} {macports-clang-[4-5].0}
# Blacklist Xcode clang on 10.12
# error: template argument for template template parameter must be a class template or type alias template
compiler.blacklist-append {clang < 1000}

configure.cxxflags-append -std=c++14
compiler.cxx_standard  2014

configure.args-append -DENABLE_CRYPTO=False \
                      -DENABLE_READLINE=False \
                      -DENABLE_KRB5=False \
                      -DENABLE_FUSE=False \
                      -DENABLE_PYTHON=FALSE \
                      -DENABLE_PERL=FALSE \
                      -DCMAKE_BUILD_TYPE="Release" \
                      -DCMAKE_CXX_FLAGS="${configure.cxxflags}" \
                      -DCMAKE_INSTALL_MANDIR="share/man"

set python_vs        {3.8 3.9 3.10 3.11 3.12 3.13}
set variant_set      no
set selected_py_v    3.13
foreach python_v ${python_vs} {
    set python_v_nodot  [string map {. {}} $python_v]
    variant python${python_v_nodot} description "Enable python ${python_v} bindings" { }
    if {[variant_isset python${python_v_nodot}]} {
        set variant_set    yes
        set selected_py_v  ${python_v}
    }
}
if { ${variant_set} eq no} {
    default_variants-append +python[string map {. {}} $selected_py_v]
}
proc setup_py_variants {} {
    global python_vs prefix configure.python selected_py_v
    set selected_py_v_nodot [string map {. {}} ${selected_py_v}]
    if {[variant_isset python${selected_py_v_nodot}]} {
        configure.python        ${prefix}/bin/python${selected_py_v}
        depends_lib-append      port:python${selected_py_v_nodot}
        depends_build-append    port:py${selected_py_v_nodot}-setuptools \
                                port:py${selected_py_v_nodot}-setuptools_scm \
                                port:py${selected_py_v_nodot}-pip
        configure.args-replace -DENABLE_PYTHON=FALSE  -DENABLE_PYTHON=TRUE
        configure.args-append  -DPython_EXECUTABLE=${configure.python}
        post-extract {
            # Fix python install location
            set python_framework ${frameworks_dir}/Python.framework/Versions/${selected_py_v}
            reinplace "s|\${CMAKE_INSTALL_PREFIX}|${python_framework}|g" ${worksrcpath}/bindings/python/CMakeLists.txt
        }
        post-configure {
            # Do not attempt to remove old pip installs
            reinplace "s|pip\ install|pip\ install\ \-I|g" ${workpath}/build/bindings/python/cmake_install.cmake
        }
    }
}
port::register_callback setup_py_variants

variant readline description {Build with Readline Support} {
    configure.args-delete   -DENABLE_READLINE=False
    configure.args-append   -DENABLE_READLINE=True -DREADLINE_ROOT_DIR="${prefix}"
    depends_lib-append      port:readline
}

variant ssl description {Build with OpenSSL Support} {
    PortGroup openssl         1.0
    # Build configuration does not properly respect custom openssl
    # location and opportunistically finds and uses the shim openssl
    # port includes instead. Use compiler wrap option to fix this.
    openssl.configure-append  compiler_wrap
    configure.args-replace    -DENABLE_CRYPTO=False  -DENABLE_CRYPTO=True
}

variant kerberos description {Build with Kerberos 5 Support} {
    configure.args-delete   -DENABLE_KRB5=False
    configure.args-append   -DENABLE_KRB5=True -DKERBEROS5_ROOT_DIR="${prefix}"
    depends_lib-append      port:kerberos5
}

# Exclude pre-release candidates
github.livecheck.regex  {([0-9.]+)}
