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

github.setup        BIC-MNI libminc 2.4.06 release-
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            3

categories          science
maintainers         nomaintainer
# The MINC package itself and most of the associated tools are licensed under a modified BSD license.
license             BSD

description         Library handling the MINC file format
long_description    {*}${description}, which is a highly flexible medical image \
                    file format built on the HDF5 generalized data format. \
                    The format is simple, self-describing, extensible, \
                    portable and N-dimensional, with programming interfaces \
                    for both low-level data access and high-level volume \
                    manipulation. On top of the libraries is a suite of generic \
                    image-file manipulation tools. The format, libraries and \
                    tools are designed for use in a medical-imaging research \
                    environment: they are simple and powerful and make no \
                    attempt to provide a pretty interface to users.

homepage            https://www.bic.mni.mcgill.ca/ServicesSoftware/MINC

checksums           rmd160  e7087e895a5b59402c35e7b317c954e8b3094cd7 \
                    sha256  929213cfd27f6a22c0f37a70cd833854d2077f36e2f5f71e950cd1f42779050d \
                    size    813938

depends_lib-append  port:hdf5 \
                    port:libaec \
                    port:netcdf \
                    port:nifticlib \
                    port:zlib

pre-configure {
    # Figure out HDF5's mpi include directory
    set mpl_include_dir ""
    if {![catch {set result [active_variants hdf5 openmpi]}]} {
        if {$result} {
            set mpl_include_dir "-I${prefix}/include/openmpi-mp"
        }
    }
    if {![catch {set result [active_variants hdf5 mpich]}]} {
        if {$result} {
            set mpl_include_dir "-I${prefix}/include/mpich-mp"
        }
    }
    if {$mpl_include_dir ne ""} {
        configure.cflags-append ${mpl_include_dir}
    }
}

patchfiles          patch-cmake.diff

configure.args-append \
                    -DLIBMINC_BUILD_SHARED_LIBS=ON \
                    -DLIBMINC_MINC1_SUPPORT=ON \
                    -DLIBMINC_USE_SYSTEM_NIFTI=ON

post-destroot {
    file mkdir ${destroot}${prefix}/lib/cmake/LIBMINC
    move {*}[glob ${destroot}${prefix}/lib/cmake/*.cmake] ${destroot}${prefix}/lib/cmake/LIBMINC
}
