# -*- 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

name                libad9361-iio
categories          science comms
maintainers         {michaelld @michaelld} openmaintainer
description         ${name} is an IIO AD9361 library for filter design and handling, multi-chip sync, and more
long_description    {*}${description}. This is a simple library used for userspace, which manages multi-chip sync (on platforms \[FMCOMMS5\] where multiple AD9361 devices are use) can create AD9361 specific FIR filters on the fly. Provides the GIT master branch version, which is typically updated every few days to week.

license             LGPL-2+

github.setup        analogdevicesinc libad9361-iio 43643ab0ef8a3fbdb6c7595f42842f534a291664
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
version             20220908-[string range ${github.version} 0 7]
checksums           rmd160  84dd84d07298dde4edcf5ab4cdd4754db2b8e3f0 \
                    sha256  6721f5ac7e02e9cb769c4db1e1245e86a3b8047f78d2f3c95c5d21e656dc7ed3 \
                    size    179812
revision            0

# patch to fix install IIO header inclusion

patchfiles-append patch-fix_build.diff
patch.pre_args-replace  -p0 -p1

depends_lib-append path:lib/libiio.dylib:libiio

depends_build-append port:pkgconfig

# 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

# directory to install all CMake files; internal appends "uhd"

configure.args-append \
    -DOSX_PACKAGE=OFF \
    -DLIBIIO_INCLUDEDIR=${prefix}/include \
    -DLIBIIO_LIBRARIES=${prefix}/lib/libiio.dylib

post-destroot {
    # link from ad9361.framework to normal
    set ad9361_framework_version 0.2
    set ad9361_framework_top ${frameworks_dir}/ad9361.framework/Versions/${ad9361_framework_version}
    set ad9361_dr_framework_top ${destroot}${ad9361_framework_top}
    set ad9361_framework ${ad9361_framework_top}/ad9361

    # fix ad9361 library & link it into .../lib
    xinstall -m 755 -d ${destroot}${frameworks_dir}
    move ${destroot}${prefix}/lib/ad9361.framework ${destroot}${frameworks_dir}
    ln -s ${ad9361_framework} ${destroot}${prefix}/lib/libad9361.dylib
    system "install_name_tool -id ${ad9361_framework} ${destroot}${ad9361_framework}"

    # link includes into .../include
    xinstall -m 755 -d ${destroot}${prefix}/include
    foreach header [glob ${ad9361_dr_framework_top}/Headers/*] {
        ln -s [strsed ${header} "s@${destroot}@@"] ${destroot}${prefix}/include
    }
}
