# -*- 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           github 1.0
PortGroup           qmake5 1.0

github.setup        GPSBabel gpsbabel 1_7_0 gpsbabel_
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
# some tricks because version at github is x_y_z
version             [join [lrange [split ${version} _] 0 2] .]
revision            1

categories          textproc comms
license             GPL-2+
maintainers         nomaintainer
description         GPSBabel converts/uploads GPS waypoints, tracks, and routes
long_description    GPSBabel converts GPS waypoints, tracks, and routes \
                    from one format to another, whether that format is a \
                    common mapping format like Delorme, Streets and \
                    Trips, or even a serial upload or download to a GPS \
                    unit such as those from Garmin and Magellan.
homepage            https://www.gpsbabel.org

checksums           rmd160  dd41329723a41749a6ef929e0766fba708509116 \
                    sha256  a5ef3b1744488d86d438291df2d65135cb04c435680fe7f64f5a94a3814ebea4 \
                    size    16720596

compiler.cxx_standard   2014

qt5.min_version         5.9

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

    # configure with qmake
    # see https://github.com/GPSBabel/gpsbabel/pull/611
    patchfiles-append patch-pr611.diff
    patch.pre_args-replace  -p0 -p1

    depends_lib-append  \
        path:lib/pkgconfig/libusb-1.0.pc:libusb  \
        port:shapelib   \
        port:zlib

    configure.args-append \
          WITH_LIBUSB=pkgconfig \
          WITH_SHAPELIB=pkgconfig \
          WITH_ZLIB=pkgconfig

    test.run        yes
    test.cmd        make
    test.target     check

    post-destroot {
        xinstall -m 755 -d ${destroot}${prefix}/share/doc/${name}
        xinstall -m 644 -W ${worksrcpath} \
            AUTHORS COPYING README.contrib README.igc \
            README.mapconverter README.xmapwpt \
            ${destroot}${prefix}/share/doc/${name}
        xinstall -m 755 -W ${worksrcpath} \
            ${name} \
            ${destroot}${prefix}/bin/${name}
    }
}

subport ${name}-app {

    worksrcdir ${worksrcdir}/gui

    # allow the selection of qtwebkit
    patchfiles-append patch-webengine_or_webkit.diff
    # by default, do not report statistics
    patchfiles-append patch-no_report.diff
    # use search path to find translation files
    # This was selected from changes in
    # see https://github.com/GPSBabel/gpsbabel/pull/622
    patchfiles-append patch-mainwindow.diff

    depends_lib-append port:${name}
    qt5.depends_build_component qttools

    post-extract {
        # copied from Makefile.in in ${worksrcdir}/..
        xinstall -m 0644 ${filespath}/makefile_macports_install ${build.dir}
            }

    variant qtwebkit description {use Webkit instead of WebEngine} {
        configure.args-append CONFIG+=MACPORTS_USE_WEBKIT

        qt5.depends_component \
            qtwebkit
        }
    if {![variant_isset qtwebkit]} {
        supported_archs x86_64

        qt5.depends_component  \
            qtdeclarative      \
            qtlocation         \
            qtwebchannel       \
            qtwebengine
    }

    destroot.args                            \
        -f makefile_macports_install         \
        PREFIX=${prefix}                     \
        APPLICATION_DIR=${applications_dir}  \
        LRELEASE=${qt_lrelease_cmd}          \
        LUPDATE=${qt_lupdate_cmd}
}
