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

name                libxc6
set my_name         libxc
version             6.2.2
revision            4
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  08c672e0d1326a76071f80e8fcae167584fbc297 \
                    sha256  f72ed08af7b9dff5f57482c5f97bff22c7dc49da9564bc93871997cbda6dacf3 \
                    size    50278761

# 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\.\]+)"
