# -*- 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$
# Copyright (c) 2015, 2016 R.J.V. Bertin

PortSystem          1.0

set kf5.project     rkward-binary
set kf5.virtualPath applications
set kf5.category    education
PortGroup           kf5 1.1
# kf5.use_latest      applications-not-yet

maintainers         hhu.de:meik.michalke gmail.com:rjvbertin mk openmaintainer

fetch.type          git
git.url             https://anongit.kde.org/rkward.git
worksrcdir          ${kf5.project}-5

installs_libs       no

description         KF5 extensible IDE/GUI for the R statistics language
long_description    RKWard is an easy to use and easily extensible IDE/GUI for R. \
                    It aims to combine the power of the R-language with the ease of use of commercial statistics tools.
conflicts           port:rkward rkward-devel rkward-binary rkward-devel-binary kf5-rkward

homepage            https://rkward.kde.org/

subport ${name}-devel {
    description     ${description}
    long_description \
                    ${long_description}
}

############
# configure R to use Mac binaries by default
# you must first install the OS X packages of CRAN R, as we'll link against them
if {${subport} eq "${name}-devel"} {
    conflicts-append \
                    ${name}
    git.branch      master
    version         0.7.0z
    distname        ${kf5.project}-5
} else {
############
# stable release, subport used for binary bundles
    conflicts-append \
                    ${name}-devel
    description     ${description}
    long_description \
                    ${long_description}
    use_xz          yes
#    checksums       rmd160  0 \
#                    sha256  0
    version             0.7.0b
    git.branch          releases/0.7.0
}

configure.args-delete \
        -DR_EXECUTABLE=${frameworks_dir}/R.framework/Resources/R

configure.args-append \
        -DRKVERSION_NUMBER=${version} \
        -DUSE_BINARY_PACKAGES=1 \
        -DR_EXECUTABLE=/Library/Frameworks/R.framework/Resources/R \
        -DR_LIBDIR=${frameworks_dir}/R.framework/Resources/library \
        -DBUNDLE_INSTALL_DIR=${applications_dir}

# create libdir if it doesn't exist
file mkdir ${frameworks_dir}/R.framework/Resources/library

kf5.depends_qt5_components \
                    qtscript qtwebkit
kf5.depends_frameworks \
                    kconfig kcoreaddons kcrash kdewebkit \
                    kdoctools ki18n knotifications kparts \
                    ktexteditor kwidgetsaddons kwindowsystem kxmlgui

depends_lib-append \
                    port:gettext \
                    port:kf5-osx-integration-devel \
                    port:ciment-icons

depends_lib-delete \
                    port:R

depends_run-append  ${kf5::osx-integration_dep}

kf5.allow_apidocs_generation no

patch.pre_args      -Np1

post-extract {
        file mkdir ${worksrcpath}/build
        # need to fetch the plugin translations first
        if [file exists ${worksrcpath}/i18n/po] {
            system "cd ${worksrcpath}/i18n/po && git pull --rebase"
        } else {
            system "cd ${worksrcpath}/i18n && git clone http://anongit.kde.org/scratch/tfry/rkward-po-export po"
        }
}

configure.dir       ${worksrcpath}/build

configure.post_args ..

build.dir           ${worksrcpath}/build

post-destroot {
    kf5.add_app_wrapper rkward5 rkward
    platform linux {
        file rename ${destroot}${kf5.libexec_dir}/rkward.rbackend ${destroot}${kf5.libexec_dir}/rkward.rbackend.bin
        xinstall -m 755 ${filespath}/rkward.rbackend.sh ${destroot}${kf5.libexec_dir}/rkward.rbackend
        reinplace "s|@QTLIBDIR@|${qt_libs_dir}|g" ${destroot}${kf5.libexec_dir}/rkward.rbackend
    }
}

pre-pkg {
        file copy -force -- ${worksrcpath}/macports/postinstall ${package.scripts}/postinstall
        file attributes ${package.scripts}/postinstall -permissions 0755
}
