# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 108389 2013-07-22 14:22:35Z michaelld@macports.org $

PortSystem          1.0
PortGroup           cmake 1.0
PortGroup           active_variants 1.1

name                gnuradio
maintainers         michaelld openmaintainer

description         GNU Radio Software Defined Radio (SDR)

categories          science comms
homepage            http://gnuradio.org/
license             GPL-3
platforms           darwin macosx

dist_subdir         gnuradio

if {${subport} == ${name}} {

    version         3.7.0
    revision        1

    long_description    ${description}: \
        This port is kept up with the GNU Radio release, currently ${version}, which is typically updated every few months.

    conflicts       gnuradio-legacy gnuradio-next gnuradio-devel

    master_sites.mirror_subdir gnuradio
    distname        gnuradio-${version}
    master_sites    http://gnuradio.org/releases/gnuradio gnu

    checksums \
        rmd160  6b899929b072edf6c3784efbff5836531c558f6a \
        sha256  c18e12f119df5ea49ea2ed8ccde3b13043d9c4adfbbb28ac3f15122c91e646a5

    livecheck.url   http://gnuradio.org/releases/gnuradio/?C=M&O=D
    livecheck.regex >LATEST-IS-(\[^<\]*)<

}

subport gnuradio-legacy {

    version         3.6.5.1
    revision        1

    long_description    ${description}: \
        This port is for GNU Radio ${version}, reflecting the final release in the 3.6 API series.  It is for legacy purposes only\; please consider updating your code to the GNU Radio 3.7 API.

    conflicts       gnuradio gnuradio-next gnuradio-devel

    master_sites.mirror_subdir gnuradio
    distname        gnuradio-${version}
    master_sites    http://gnuradio.org/releases/gnuradio gnu

    checksums \
        rmd160  66bdc05826e9130cf65e7bee355c01f4474c861b \
        sha256  0875d2f0a7da0f3bcc1771b528b0f98f79d9ab69aa1ef953651bbbe1f57b4621

    patchfiles      patch-path-order.diff
    patch.pre_args  -p1

    livecheck.type  none

}

subport gnuradio-devel {

    long_description    ${description}: \
        This port is kept up with the GNU Radio GIT 'master' branch, which is typically updated daily to weekly.  This version of GNU Radio generally contains fixes to, and its API is compatible with, the current GNU Radio release, and will be incorporated in an upcoming release.  This port may or not compile or function correctly, as it represents a work in progress.  If it does not work, check back in a few days.  Or try deactivating the currently active gnuradio port, cleaning any current builds, and trying again.

    version             3.7.1_20130720

    conflicts           gnuradio-legacy gnuradio gnuradio-next

    fetch.type          git
    git.url             http://git.gnuradio.org/git/gnuradio.git
    git.branch          e5d050b39ad09cbac30b3ee889c54080468b5457

    livecheck.url       http://gnuradio.org/cgit/gnuradio.git/log/?h=master
    livecheck.version   ${git.branch}
    livecheck.regex     id=(\[a-f0-9\]+).*>master<

}

subport gnuradio-next {

    long_description    ${description}: \
        This port is kept up with the GNU Radio GIT 'next' branch, which is typically updated daily to weekly.  This version of GNU Radio represents the next major release of GNU Radio, and hence its API is likely to be different than that provided by either gnuradio or gnuradio-devel.  This port may or not compile or function correctly, as it represents a work in progress.  If it does not work, check back in a few days.  Or try deactivating the currently active gnuradio port, cleaning any current builds, and trying again.

    version             3.8.0_20130720

    conflicts           gnuradio-legacy gnuradio gnuradio-devel

    fetch.type          git
    git.url             http://git.gnuradio.org/git/gnuradio.git
    git.branch          b5a3a6975ed96d71c70809fd98f87e092ea0ccaf

    livecheck.url       http://gnuradio.org/cgit/gnuradio.git/log/?h=next
    livecheck.version   ${git.branch}
    livecheck.regex     id=(\[a-f0-9\]+).*>next<

}

if {${subport} != "gnuradio-legacy"} {

    # GNU Radio 3.7 has requirements that 3.6 does not, and provides
    # features that 3.6 does not have.

    depends_lib-append  port:log4cpp

    variant ctrlport description {Enable control port enhancements (EXPERIMENTAL)} {}

    if {[variant_isset ctrlport]} {

        depends_lib-append port:zeroc-ice34
        configure.args-append -DENABLE_GR_CTRLPORT=ON

    } else {

        configure.args-append -DENABLE_GR_CTRLPORT=OFF

    }
}

use_parallel_build  yes

depends_lib-append  \
    port:boost \
    port:cppunit \
    port:fftw-3-single \
    port:pkgconfig

# do VPATH build

set vpath           ${workpath}/build
pre-configure       { file mkdir ${vpath} }
configure.dir       ${vpath}
build.dir           ${vpath}

# VOLK compiles best with GCC of some type;
# print a warning if using clang

pre-configure {
    if {${configure.compiler} == "clang"} {
        ui_msg "WARNING: GNU Radio's VOLK component (which handles vector optimized instructions and routines) compiles best when using GCC.  The selected compiler is CLANG, which will result in a fully functioning GNU Radio install but the VOLK component will not utilize the CPU's capabilities."
    }
}

# let CMake figure out some flags

configure.ldflags
configure.cppflags

# always enable VOLK, with or without orc

configure.args-append -DENABLE_VOLK=ON

# set last configure argument to the reletive path
# to the top-level cmake source

configure.post_args ../${worksrcdir}

# be verbose when building, for debugging purposes

build.post_args VERBOSE=1

# shortcut to installing all variants except Python

variant full \
    requires docs grc qtgui wxgui uhd orc wavelet jack portaudio swig sdl \
    description {Enable all variants except +debug and +universal (and, for next, except +ctrlport)} {}

# set Python variants

set pythons_suffixes {26 27}
global chosen_python_suffix
set chosen_python_suffix ""

set pythons_ports {}
foreach s ${pythons_suffixes} {
    lappend pythons_ports python${s}
}

foreach s ${pythons_suffixes} {
    set p python${s}
    set v [join [split ${s} ""] "."]
    set i [lsearch -exact ${pythons_ports} ${p}]
    set c [lreplace ${pythons_ports} ${i} ${i}]
    eval [subst {
        variant ${p} description "Build GNU Radio using Python ${v}" \
            conflicts ${c} {

            set chosen_python_suffix ${s}

            # specify the Python dependencies

            depends_lib-append \
                port:${p} \
                port:py${s}-numpy \
                port:py${s}-cheetah

            depends_run-append \
                port:py${s}-opengl \
                port:py${s}-scipy

            # specify the Python version to use

            configure.args-append \
                -DPYTHON_EXECUTABLE=${prefix}/bin/python${v} \
                -DPYTHON_INCLUDE_DIR=${prefix}/Library/Frameworks/Python.framework/Versions/${v}/Headers \
                -DPYTHON_LIBRARY=${prefix}/Library/Frameworks/Python.framework/Versions/${v}/Python \
                -DGR_PYTHON_DIR=${frameworks_dir}/Python.framework/Versions/${v}/lib/python${v}/site-packages

            # check for variants that require Python

            if {[variant_isset docs]} {

                depends_lib-append \
                    port:py${s}-sphinx

                configure.args-append \
                    -DSPHINX_EXECUTABLE=${prefix}/bin/sphinx-build-${v}

            }

            if {[variant_isset grc]} {

                depends_lib-append \
                    port:py${s}-lxml \
                    port:py${s}-pygtk

            }

            if {[variant_isset qtgui]} {

                depends_lib-append \
                    port:py${s}-pyqt4
                depends_run-append \
                    port:py${s}-pyqwt

            }

            if {[variant_isset wxgui]} {

                depends_lib-append \
                    port:py${s}-wxpython-devel

            }

            if {[variant_exists ctrlport] && \
                    [variant_isset ctrlport]} {

                depends_lib-append port:py${s}-zeroc-ice34

            }
        }
    }]
}

# Python is required; default to 2.7

if {![variant_isset python26] && ![variant_isset python27]} {
    default_variants +python27
}

# Make sure -python27 was not specified alone

if {![variant_isset python26] && ![variant_isset python27]} {
    ui_error "GNU Radio requires a Python to be selected; you cannot use -python27 as a variant alone."
    return -code error "Invalid variant selection"
}

variant docs description "Install GNU Radio documentation" {

    depends_lib-append \
        port:doxygen \
        path:bin/dot:graphviz \
        port:xmlto

    configure.args-append \
        -DENABLE_DOXYGEN=ON \
        -DENABLE_SPHINX=ON

}

if {![variant_isset docs]} {

    configure.args-append \
        -DENABLE_DOXYGEN=OFF \
        -DENABLE_SPHINX=OFF

}

variant grc requires swig description "Install GNU Radio Companion" {

    configure.args-append \
        -DENABLE_GRC=ON

}

if {![variant_isset grc]} {

    configure.args-append \
        -DENABLE_GRC=OFF

}

variant qtgui description "Install GNU Radio with support for Qt GUI" {

    depends_lib-append \
        port:qt4-mac \
        path:lib/libqwt.dylib:qwt52 \
        port:qwtplot3d

    configure.args-append \
        ENABLE_GR_QTGUI=ON \
        -DQT_QMAKE_EXECUTABLE=${prefix}/bin/qmake

}

if {![variant_isset qtgui]} {

    configure.args-append \
        -DENABLE_GR_QTGUI=OFF \
        -DQT_QMAKE_EXECUTABLE=

}

variant wxgui description "Install GNU Radio with support for Wx GUI" {

    depends_lib-append \
        port:wxWidgets-devel

    configure.args-append \
        -DENABLE_GR_WXGUI=ON

}

if {![variant_isset wxgui]} {

    configure.args-append \
        -DENABLE_GR_WXGUI=OFF

}

variant uhd description "Install GNU Radio with support for UHD" {

    depends_lib-append \
        path:lib/libuhd.dylib:uhd

    configure.args-append \
        -DENABLE_GR_UHD=ON \
        -DUHD_INCLUDE_DIRS=${prefix}/include \
        -DUHD_LIBRARIES=${prefix}/lib/libuhd.dylib

}

if {![variant_isset uhd]} {

    configure.args-append \
        -DENABLE_GR_UHD=OFF \
        -DUHD_INCLUDE_DIRS= \
        -DUHD_LIBRARIES=

}

variant orc description "Install GNU Radio Volk with support for ORC" {

    depends_lib-append \
        port:orc

    configure.args-append \
        -DORCC_EXECUTABLE=${prefix}/bin/orcc

}

if {![variant_isset orc]} {

    configure.args-append \
        -DORCC_EXECUTABLE=

}

variant wavelet description "Install GNU Radio Wavelet component" {

    depends_lib-append \
        port:gsl

    configure.args-append \
        ENABLE_GR_WAVELET=ON

}

if {![variant_isset wavelet]} {

    configure.args-append \
        -DENABLE_GR_WAVELET=OFF

}

variant jack description "Install GNU Radio with support for JACK audio" {

    depends_lib-append \
        port:jack

    configure.args-append \
        -DJACK_INCLUDE_DIR=${prefix}/include \
        -DJACK_LIBRARY=${prefix}/lib/libjack.dylib

}

if {![variant_isset jack]} {

    configure.args-append \
        -DJACK_INCLUDE_DIR= \
        -DJACK_LIBRARY=

}

variant portaudio description "Install GNU Radio with support for portaudio audio" {

    depends_lib-append \
        port:portaudio

    configure.args-append \
        -DPORTAUDIO_INCLUDE_DIRS=${prefix}/include \
        -DPORTAUDIO_LIBRARIES=${prefix}/lib/libportaudio.dylib

}

if {![variant_isset portaudio]} {

    configure.args-append \
        -DPORTAUDIO_INCLUDE_DIRS= \
        -DPORTAUDIO_LIBRARIES=

}

variant swig description "Install GNU Radio with support for SWIG-base Python bindings" {

    depends_lib-append \
        port:swig-python

    configure.args-append \
        -DSWIG_EXECUTABLE=${prefix}/bin/swig

}

if {![variant_isset swig]} {

    configure.args-append \
        -DSWIG_EXECUTABLE=

}

variant sdl description "Install GNU Radio with support for SDL-based video" {

    depends_lib-append \
        port:libsdl

    configure.args-append \
        -DENABLE_GR_VIDEO_SDL=ON \
        -DSDLMAIN_LIBRARY=${prefix}/lib/libSDLmain.a \
        -DSDL_INCLUDE_DIR=${prefix}/include/SDL

}

if {![variant_isset sdl]} {

    configure.args-append \
        -DENABLE_GR_VIDEO_SDL=OFF \
        -DSDLMAIN_LIBRARY= \
        -DSDL_INCLUDE_DIR=

}
