# -*- 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
# $Id: Portfile 78717 2011-05-19 02:28:40Z michaelld@macports.org $

PortSystem          1.0
PortGroup           cmake 1.0

name                uhd
version             003.001.000
categories          science
maintainers         michaelld
description         Universal Hardware Driver for Ettus Research products
long_description    ${description}
license             GPL-3+

homepage            https://ettus-apps.sourcerepo.com/redmine/ettus/projects/uhd/wiki
platforms           darwin

fetch.type          git
git.url             http://github.com/EttusResearch/UHD-Mirror.git
git.branch          release_[strsed ${version} {g/\./_/}]

worksrcdir          ${name}-${version}

depends_lib-append	port:boost

# do VPATH build
post-extract { file mkdir ${workpath}/build }

default configure.post_args {../${worksrcdir}/host}
default configure.dir       {${workpath}/build}
default build.dir           {${workpath}/build}

configure.args-append \
    -DENABLE_USB=OFF \
    -DENABLE_EXAMPLES=OFF \
    -DENABLE_TESTS=OFF \
    -DENABLE_MANUAL=OFF \
    -DENABLE_DOXYGEN=OFF

variant tests description {enable tests} {
    configure.args-delete -DENABLE_TESTS=OFF
    configure.args-append -DENABLE_TESTS=ON
    test.run yes
}

variant examples description {enable examples} {
    configure.args-delete -DENABLE_EXAMPLES=OFF
    configure.args-append -DENABLE_EXAMPLES=ON
}

variant libusb description {enable USB support via libusb version 1.0} {
    depends_lib-append port:libusb
    configure.args-delete -DENABLE_USB=OFF
    configure.args-append -DENABLE_USB=ON
}

# 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 ${chosen_python_suffix} ""] "."]
    set i [lsearch -exact ${pythons_ports} ${p}]
    set c [lreplace ${pythons_ports} ${i} ${i}]
    eval [subst {
        variant ${p} description "Build UHD for Python ${v}" \
            conflicts ${c} {

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

            # specify that Python version to use
            configure.args-append \
                -DPYTHON_EXECUTABLE=${prefix}/bin/python${v}
        }
    }]
}

# if no python variant is set, default to 2.7
if {![variant_isset python26] &&
    ![variant_isset python27]} {
    default_variants +python27
}

# make sure -python27 was not used alone
if {![variant_isset python26] &&
    ![variant_isset python27]} {
    return -code error "Exactly one Python variant must be selected."
}

variant docs description {build documentation} {
    depends_lib-append \
        port:doxygen
    configure.args-delete \
        -DENABLE_DOXYGEN=OFF
    configure.args-append \
        -DENABLE_DOXYGEN=ON
}

variant manual description {build manual} {
    set v [join [split ${chosen_python_suffix} ""] "."]
    depends_lib-append \
        port:py${chosen_python_suffix}-docutils
    configure.args-delete \
        -DENABLE_MANUAL=OFF
    configure.args-append \
        -DENABLE_MANUAL=ON \
        -DRST2HTML_EXECUTABLE=${prefix}/bin/rst2html-${v}.py
}

#livecheck.type      regex
#livecheck.url       http://gitorious.org/dbusmenu/${name}/trees/master
#livecheck.regex     >(\\d+(\\.\\d+)+)<
