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

PortSystem          1.0
PortGroup           github 1.0
PortGroup           legacysupport 1.0

name                osmocore
maintainers         {michaelld @michaelld} openmaintainer
description         ${name} provides a set of C-language libraries that form the core infrastructure of many Osmocom Open Source Mobile Communications projects.
long_description    {*}${description}

categories          science comms
license             GPL-2+
platforms           darwin macosx

epoch               1

compiler.c_standard 2011

subport osmocore-devel {}

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

    # release
    github.setup osmocom libosmocore 1.3.0
    # Change github.tarball_from to 'releases' or 'archive' next update
    github.tarball_from tarball
    checksums rmd160 b225cad23edc006bf26c7d1680aba034dad1cf6a \
              sha256 cc36bfff7ca362b72dc2977e89493cd63597e70e8f999adeaa4de8203d41a9fb \
              size   1287754
    revision  1
    platform darwin 20 {
        revision    2
    }

    # fix 'timer_clockgettime.c' to work with OSs that don't provide
    # the function 'clock_gettime' and/or its various options.

    patchfiles-append patch-fix_clock_gettime.release.diff

    # fix use of Python2, part 1

    patchfiles-append patch-fix-python.release.diff

    # temporary patch to fix library target name; remove at next release

    patchfiles-append patch-src_usb_Makefile.am.diff

} else {

    # devel
    github.setup osmocom libosmocore 89c04288252f1a50bbba5680c2f884a95f0eba2d
    # Change github.tarball_from to 'releases' or 'archive' next update
    github.tarball_from tarball
    version   20200121-[string range ${github.version} 0 7]
    checksums rmd160 4ef1a67ed3b1ac9004bdbb7e174128a936f6bc4f \
              sha256 9e0d56a53f931c491fb802c3f3d835d43f71bcafac0afe94b5da9f6ed22ac71d \
              size   1288521
    revision  1
    platform darwin 20 {
        revision    2
    }

    # fix 'timer_clockgettime.c' to work with OSs that don't provide
    # the function 'clock_gettime' and/or its various options.

    patchfiles-append patch-fix_clock_gettime.devel.diff

    # fix use of Python2, part 1

    patchfiles-append patch-fix-python.devel.diff

}

depends_build-append \
    port:automake \
    port:autoconf \
    path:bin/doxygen:doxygen \
    port:libtool \
    port:pkgconfig

depends_lib-append \
    path:lib/pkgconfig/libusb-1.0.pc:libusb \
    path:lib/pkgconfig/gnutls.pc:gnutls \
    port:python27 \
    port:talloc

patch.pre_args-replace  -p0 -p1

# update configure.ac to current automake standards

patchfiles-append patch-configure.ac.diff

# fix header variable declaration to be "extern" even though it should
# not technically be necessary.

patchfiles-append patch-include_osmocom_coding_gsm0503_parity.h.diff

# fix use of Python2, part 2, for both release and devel

post-patch {
    reinplace "s|@PYTHON_EXECUTABLE@|${frameworks_dir}/Python.framework/Versions/2.7/bin/python2.7|g" \
        ${worksrcpath}/include/Makefile.am \
        ${worksrcpath}/src/gsm/Makefile.am \
        ${worksrcpath}/tests/Makefile.am \
        ${worksrcpath}/utils/conv_codes_gsm.py \
        ${worksrcpath}/utils/conv_gen.py \
        ${worksrcpath}/utils/gsmtap.py \
        ${worksrcpath}/utils/gsmtap_logread.py \
        ${worksrcpath}/contrib/struct_endianess.py \
        ${worksrcpath}/contrib/fsm-to-dot.py
}

# use autotools to get ready to configure

pre-configure		{
    system -W ${worksrcpath} "${prefix}/bin/glibtoolize -v -i -W all && ${prefix}/bin/aclocal -I m4 && ${prefix}/bin/autoheader && ${prefix}/bin/autoconf && ${prefix}/bin/automake -a --gnu"
}

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

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

# set c11
configure.cflags-append -std=gnu11
configure.ldflags-append -std=gnu11

configure.args-append \
                    --disable-pcsc \
                    --disable-pseudotalloc \
                    --disable-silent-rules \
                    --disable-libsctp
