# -*- 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               github         1.0
PortGroup               mpi            1.0
PortGroup               linear_algebra 1.0
PortGroup               muniversal     1.0

github.setup            cburstedde libsc 2.8.6 v
revision                0
categories              science math devel
maintainers             {mcalhoun @MarcusCalhoun-Lopez} openmaintainer
license                 GPL-2+
homepage                https://www.p4est.org

description             provides support for parallel scientific applications
long_description        The SC Library provides support for parallel scientific applications.

checksums               rmd160  f4fdd1d64ab6f26fb743fb84faf852a6abb29c87 \
                        sha256  3371e108e103171afe63baa9e810eddf9cfcf175bfcac44eca932db3f88ba8fc \
                        size    436045
github.tarball_from     archive

mpi.setup               default require_fortran

use_autoconf            yes
autoconf.cmd            ./bootstrap
autoconf.args

# need for autoconf
depends_build-append    port:autoconf \
                        port:automake \
                        port:libtool \
                        path:bin/pkg-config:pkgconfig

depends_lib-append      port:lua \
                        port:zlib

if {[mpi_variant_isset]} {
    configure.args-append --enable-mpi
} else {
    configure.args-append --enable-mpi=no
}

post-extract {
    set fl [open "${worksrcpath}/.tarball-version" w 0644]
    puts ${fl} ${version}
    close ${fl}
}

pre-configure {
    configure.args-append --with-blas="-L${prefix}/lib ${linalglib}" \
                          --with-lapack=""
}

post-destroot {
    # avoid conflict with autoconf-archive
    foreach fl {ax_prefix_config_h.m4 ax_split_version.m4} {
        delete ${destroot}${prefix}/share/aclocal/${fl}
    }
}

if {!${universal_possible} || ![variant_isset universal]} {
    # remove arch flags
    post-destroot {
        reinplace -E {s|-arch [a-z0-9_]+||g} ${destroot}${prefix}/etc/Makefile.sc.mk
        #reinplace -E {s|-m[0-9]+||g}         ${destroot}${prefix}/etc/Makefile.sc.mk
    }
} else {
    # remove arch flags
    merger-post-destroot {
        foreach arch ${configure.universal_archs} {
            reinplace -E {s|-arch [a-z0-9_]+||g} ${destroot}-${arch}${prefix}/etc/Makefile.sc.mk
            #reinplace -E {s|-m[0-9]+||g}         ${destroot}-${arch}${prefix}/etc/Makefile.sc.mk
        }
    }
}
