# -*- 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 107821 2013-07-06 08:26:24Z ryandesign@macports.org $

PortSystem          1.0
PortGroup           github 1.0

github.setup        OpenNI openni 1.5.2.23 Stable-
categories          graphics
platforms           darwin
maintainers         ryandesign openmaintainer
license             LGPL-3+
supported_archs     i386 x86_64

description         APIs for natural interaction devices

long_description    The OpenNI framework provides a set of APIs for accessing \
                    natural interaction devices, including support for voice \
                    and voice command recognition, hand gestures, and body \
                    motion tracking.

checksums           rmd160  ecf46e11a82752388bb394562dfbbec1e018c40b \
                    sha256  7f097f6b7e304dab75afd23ce73cbe3dcefec62b6a8f843fa6bdf2f6b1d81e99

depends_build       port:doxygen \
                    path:bin/dot:graphviz

depends_lib         port:libusb

pre-fetch {
    if {${os.platform} eq "darwin" && ${os.major} < 10} {
        ui_error "${name} ${version} requires OS X 10.6 or greater."
        return -code error "incompatible OS X version"
    }
}

build.dir           ${worksrcpath}/Platform/Linux/CreateRedist

post-extract {
    file attributes ${build.dir}/RedistMaker -permissions a+x
    # DOS to UNIX line endings so we can patch.
    reinplace "s|\r||g" ${worksrcpath}/Source/OpenNI/XnOpenNI.cpp
}

patchfiles          patch-Platform-Linux-Build-Common-CommonCppMakefile.diff \
                    patch-Platform-Linux-Build-Common-Platform.x86.diff \
                    patch-Platform-Linux-CreateRedist-install.sh.diff \
                    patch-Source-OpenNI-XnOpenNI.cpp.diff

post-patch {
    reinplace "s|@PREFIX@|${prefix}|g"  ${build.dir}/install.sh \
                                        ${worksrcpath}/Platform/Linux/Build/Common/CommonCppMakefile \
                                        ${worksrcpath}/Source/OpenNI/XnOpenNI.cpp
}

use_configure       no

variant universal {}

build.cmd           ./RedistMaker
build.env           CXX="${configure.cxx} [get_canonical_archflags cxx]"
build.target

pre-destroot {
    destroot.dir    [glob ${worksrcpath}/Platform/Linux/Redist/*]
}
destroot.cmd        ./install.sh
destroot.target
destroot.destdir    -c ${destroot}
destroot.keepdirs   ${destroot}${prefix}/var/lib/ni

set libs {libnimMockNodes.dylib libnimCodecs.dylib libnimRecorder.dylib}

post-activate {
    foreach lib ${libs} {
        system "${prefix}/bin/niReg -r ${prefix}/lib/${lib}"
    }
}

pre-deactivate {
    foreach lib ${libs} {
        system "${prefix}/bin/niReg -u ${prefix}/lib/${lib}"
    }
}
