# -*- 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           compilers 1.0
PortGroup           conflicts_build 1.0
PortGroup           gitlab 1.0
PortGroup           muniversal 1.0

name                libxc5
set my_name         libxc
version             5.2.3
revision            5
gitlab.setup        libxc libxc ${version}

categories          science
license             {MPL-2 LGPL-2.1+}
maintainers         {mascguy @mascguy} openmaintainer

description         Exchange-correlation functionals for DFT
long_description    Libxc is a library of exchange-correlation functionals \
                    for density-functional theory. The aim is to provide \
                    a portable, well tested and reliable set of exchange \
                    and correlation functionals that can be used by all \
                    the ETSF codes and also other codes.

dist_subdir         ${my_name}

# stealth update; remove for next version
dist_subdir         ${dist_subdir}/${version}_1

checksums           rmd160  74e48cd9509d4636933404e6fc91202f3ba0611f \
                    sha256  851a45aee9ddaafea49f684fe3e3ab2fbd79f1c1289b8c1cea216330b27e887b \
                    size    38874263

# Avoid linking to 'libxc', if installed
conflicts_build-append \
                    libxc

compilers.choose    fc
compilers.setup     require_fortran -g95
# g95 cannot handle F2003 here

compiler.c_standard 1999

# gcc-4.2 builds port, but doesn't support -march=native and Fortran
compiler.blacklist-append \
                    *gcc-4.* {clang < 421}

set port_ver_major  [lindex [split ${version} .] 0]
set port_prefix     ${prefix}/libexec/${name}
set port_bin        ${port_prefix}/bin

configure.pre_args-delete \
                    --prefix=${prefix}
configure.pre_args-append \
                    --prefix=${port_prefix}

configure.args-append \
                     --disable-silent-rules \
                     --enable-shared \
                     --enable-static \
                     --program-suffix=-${port_ver_major}

post-destroot {
    # Create bin symlinks
    set port_bin_list \
        [glob -type f -directory ${destroot}${port_bin} *]
    foreach f ${port_bin_list} {
        set fname [file tail ${f}]
        ui_info "Symlinking bin: ${prefix}/bin/${fname} -> ${port_bin}/${fname}"
        ln -s ${port_bin}/${fname} ${destroot}${prefix}/bin/${fname}
    }
}

variant tests description {Enable Tests} {
    depends_test-append \
                    port:bash \
                    port:bzip2

    test.run        yes
    test.target     check
}

if { ![variant_isset tests] } {
    # Regenerate everything, as we patch configure.ac, etc.
    use_autoreconf  yes
    autoreconf.args -fvi

    patchfiles-append \
                    patch-tests-disable.diff
}

gitlab.livecheck.regex "(${port_ver_major}\.\[0-9\.\]+)"
