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

name                gr-specest
categories          science comms
maintainers         {michaelld @michaelld} openmaintainer
description         Provides spectral estimation blocks for GNU Radio.
long_description    ${description}
license             GPL-3
platforms           darwin

subport gr-specest-38 {}

if {${name} eq ${subport}} {

    github.setup kit-cel gr-specest 91a27336b19a65125483fe0424b16f31822e7c85
    version   20180115
    revision  6
    checksums rmd160 5b9614203006aa5ef497caccaa86dab2b40324b4 \
              sha256 3cdd50bc68a002509bb14d4ab0565736409c171b7fb443694dc2fbcecd6d4227 \
              size   562474

    # allow gr-specest to work with both gnuradio and gnuradio-devel ...

    depends_lib-append  path:lib/libgnuradio-runtime.dylib:gnuradio

    # ... but not with gnuradio-next

    pre-fetch {
        if {![catch {set installed [lindex [registry_active gnuradio-next] 0]}]} {
            # gnuradio-next is installed; this version of gr-specest does not work with gnuradio-next
            ui_msg "\nError: ${name} requires the gnuradio or gnuradio-devel port, and will not work with the gnuradio-next port.  deactivate gnuradio-next, and then install or activate gnuradio or gnuradio-devel.\n"
            return -code error "Invalid port dependency: gnuradio-next"
        }
    }

    # patches

    patchfiles-append   patch-fix_build.37.diff

} else {

    github.setup kit-cel gr-specest 4ac4c4a9492df60f9202a91680a7bbbea564a2e4
    version   20190520-[string range ${github.version} 0 7]
    revision  0
    checksums rmd160 3227c18ada41a7725a8457102a8f31f4052d00b3 \
              sha256 019a94a44be97e457ec73a4ed4971a1607431494228730ff742099ec306d643f \
              size   568667

    # gr-specest-38 requires gnuradio-next ...

    depends_lib-append port:gnuradio-next

    # patches

    patchfiles-append   patch-fix_build.38.diff

}

# require a fortran compiler
#compilers.choose    f77 f90
compilers.setup     require_fortran

depends_build-append port:pkgconfig \
                     port:swig-python

depends_lib-append  port:boost \
                    port:doxygen \
                    port:libxml2 \
                    port:armadillo \
                    port:fftw-3-single

depends_run-append  port:gr-osmosdr

# still require cppunit for testing; NOTE: cppunit is checked for
# during configure, so we need it to be in depends_lib or
# depends_build to be used correctly. Choose the latter since it's
# not required for runtime; just for build/test.
depends_build-append port:cppunit

# do VPATH (out of source tree) build

cmake.out_of_source yes

# remove top-level library path, such that internal libraries are used
# instead of any already-installed ones.

configure.ldflags-delete -L${prefix}/lib

# specify the Python dependencies

depends_lib-append \
    port:python27

# specify the Python version to use

configure.args-append \
    -DPYTHON_EXECUTABLE=${frameworks_dir}/Python.framework/Versions/2.7/bin/python2.7 \
    -DPYTHON_INCLUDE_DIR=${frameworks_dir}/Python.framework/Versions/2.7/Headers \
    -DPYTHON_LIBRARY=${frameworks_dir}/Python.framework/Versions/2.7/Python \
    -DGR_PYTHON_DIR=${frameworks_dir}/Python.framework/Versions/2.7/lib/python2.7/site-packages \
    -DCMAKE_MODULES_DIR=${prefix}/share/cmake

variant accelerate conflicts atlas openblas description {Use Apple Accelerate Libraries for BLAS} {
    configure.env-append BLA_VENDOR=Apple
}

variant atlas conflicts accelerate openblas description {Use MacPorts ATLAS Libraries} {
    depends_lib-append port:atlas
    configure.env-append BLA_VENDOR=ATLAS
}

variant openblas conflicts atlas accelerate description {Use MacPorts OpenBLAS Libraries} {
    depends_lib-append path:lib/libopenblas.dylib:OpenBLAS
    configure.env-append BLA_VENDOR=OpenBLAS
}

if {![variant_isset accelerate] &&
    ![variant_isset atlas] &&
    ![variant_isset openblas]} {
    default_variants +accelerate
}

if {![variant_isset accelerate] &&
    ![variant_isset atlas] &&
    ![variant_isset openblas]} {
    ui_msg "\nError: '${name} -accelerate' is an invalid option; please select one of the variants +accelerate, +atlas, or +openblas.\n"
    return -code error "Invalid variant selection"
}