# -*- 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           compilers 1.0
PortGroup           github 1.0

name                fortran-stdlib
github.setup        fortran-lang stdlib 0.7.0 v
revision            0
epoch               1
categories-append   lang fortran devel science
conflicts           fortran-stdlib-devel
license             MIT
maintainers         nomaintainer
description         Fortran Standard Library
long_description    {*}${description}
checksums           rmd160  7b737a35727c4b9067694ac15ee7864e5d60a25e \
                    sha256  07615b1fd0d9c78f04ec5a26234d091cb7e359933ba2caee311dcd6f58d87af0 \
                    size    3669255
github.tarball_from archive

subport fortran-stdlib-devel {
    github.setup    fortran-lang stdlib 336901354e97510fbaf33de683b22f19f31e61e7
    version         2024.11.09
    conflicts       fortran-stdlib
    checksums       rmd160  b7dab2ef8a559e46b69dc2e0099b52758f11ad7b \
                    sha256  da9a115b52555e4318ccd5c9b21cd3000815d62cc91e113d35f30ab962fbb73f \
                    size    3712658
    github.tarball_from archive
}

cmake.generator     Ninja

set py_ver          3.11
set py_ver_nodot    [string map {. {}} ${py_ver}]
depends_build-append \
                    port:py${py_ver_nodot}-fypp \
                    port:python${py_ver_nodot}

platform darwin {
    if {${os.major} < 13} {
        depends_build-append    path:bin/git:git
        git.cmd                 ${prefix}/bin/git
    }
}

# Installation uses compiler-specific paths,
# so we should not use a generic gfortran.
# https://github.com/fortran-lang/stdlib/issues/846
compilers.setup     require_fortran -g95 -gfortran
compiler.blacklist-append \
                    {*gcc-[34].*} {macports-gcc-[58]} {clang < 500}
# Notice that this port requires ieee_arithmetic support in gfortran,
# which may not be available for some targets.
# https://github.com/fortran-lang/stdlib/issues/690
# Darwin PowerPC got ieee_arithmetic support in gcc15.
# https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=1cfe4a4d0d4447b364815d5e5c889deb2e533669
# PowerPC-specific version of gcc14 with backported patch is available at
# https://github.com/macos-powerpc/powerpc-ports/tree/main/lang/gcc14

configure.args-append \
                    -DPython_EXECUTABLE=${prefix}/bin/python${py_ver} \
                    -DFYPP=${prefix}/bin/fypp-${py_ver} \
                    -DCMAKE_BUILD_TYPE=NoConfig \
                    -DCMAKE_MAXIMUM_RANK:String=7 \
                    -DBUILD_SHARED_LIBS=ON \
                    -DBUILD_TESTING=OFF

platform darwin powerpc {
    # See: https://github.com/fortran-lang/stdlib/issues/694
    configure.args-append \
                    -DWITH_XDP=OFF
}

variant tests description "Enable testing" {
    configure.pre_args-replace \
                    -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON \
                    -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=OFF
    configure.args-replace \
                    -DBUILD_TESTING=OFF \
                    -DBUILD_TESTING=ON
    test.run        yes
    test.cmd        ctest
}
