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

PortSystem          1.0
PortGroup           kde4   1.1

name                kdelibs4
version             4.14.3
categories          kde kde4
maintainers         nicos
license             LGPL-2+ GPL-2+ BSD
description         KDE4 core libraries
long_description    Core libraries for KDE4 applications to function
platforms           darwin
homepage            http://www.kde.org
master_sites        kde:stable/${version}/src/
use_xz              yes
distname            kdelibs-${version}

checksums           rmd160  f0dd628eec72c52f4dd8426a2de47d75e629ff31 \
                    sha256  f8206da1106184ef0bd031b82701c4910b8dade331c4cdaf1cd9c6c5208cfd9e

#No binary links to openssl libraries, apart from libkio.dylib at
#runtime if required. As libkio.dylib code is purely LGPL, there is no
#conflict with openssl license
license_noconflict  openssl

depends_build-append port:flex port:gmake port:docbook-xsl-ns

depends_lib-append  port:bzip2 port:zlib \
                    port:soprano \
                    port:strigi port:gettext \
                    port:pcre port:shared-mime-info \
                    port:giflib \
                    port:jpeg port:libpng \
                    port:jasper port:openexr \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    port:openssl port:enchant \
                    port:aspell port:aspell-dict-en \
                    port:attica port:xz \
                    port:avahi port:qca \
                    port:libxml2 port:libxslt \
                    port:dbusmenu-qt port:docbook-xml \
                    port:docbook-xsl port:grantlee \
                    port:kerberos5 port:bison \
                    port:shared-desktop-ontologies \
                    port:perl5

# the aspell dictionaries are just files
depends_skip_archcheck aspell-dict-en

#workaround-kdeinit4-crash: Mac-specific patch developed by Macports to circumvent some crashes.
#default-kde4-xdg-menu-prefix: solves a conflict with a file from gnome-menus (see ticket #18914)
#add-bundles-to-path: improve support for KIO slaves by adding a search path
#kapplications-raster: ensures that kde applications start in raster (faster) mode, but also provides a switch for non-working applications
#removeFindFlex: remove FindFlex.cmake which may hide the working one of cmake (ticket #44119)
#cmake-modules-FindKDE4-Internal.cmake: Fixes zlib detection (see ticket #24128)
#nativeDialogs: Use native mac dialogs (see https://reviewboard.kde.org/r/119243/)
#KdePreferences: Handles menus to be closer to standard Mac layout (see https://reviewboard.kde.org/r/120149/)

patchfiles           workaround-kdeinit4-crash.patch \
                     default-kde4-xdg-menu-prefix.patch \
                     add-bundles-to-path.patch \
                     patch-kapplications-raster.diff \
                     patch-removeFindFlex.diff \
                     patch-cmake-modules-FindKDE4-Internal.cmake.diff \
                     patch-KdePreferences.diff
#Deactivated as of ticket #45373
#                     patch-nativeDialogs.diff

patch.pre_args      -p1

# explicitly define certain headers and libraries, to avoid
# conflicts with those installed into system paths by the user.
configure.args-append   -DWITH_ENCHANT=ON \
                        -DWITH_Soprano=ON \
                        -DWITH_Avahi=ON \
                        -DKDE_DEFAULT_HOME=Library/Preferences/KDE \
                        -DWITH_HSPELL=OFF \
                        -DWITH_FAM=OFF \
                        -DKDE4_AUTH_BACKEND_NAME="OSX"

if { [file exists ${destroot}${prefix}/lib/kde4/kspell_aspell.so] } {
    notes "
Only the English dictionary has been installed.
You will need to install extra dictionaries to
get support for spell checking other languages.
The command 'port search aspell-dict' will show
you the currently available dictionary options.
"
}

set startup_root ""

pre-configure {
    #The FindFlex.cmake file is not working and may conflict with the one provided by cmake (ticket #44119)
    delete file ${worksrcpath}/cmake/modules/FindFlex.cmake
}

pre-activate {
    if {![catch {set vers [lindex [registry_active kde4-runtime] 0]}]
        && [vercmp [lindex $vers 1] 4.8.1] < 0} {
        registry_deactivate_composite kde4-runtime "" [list ports_nodepcheck 1]
    }
}

post-destroot {
    xinstall -d ${destroot}${prefix}/include/nepomuk
    eval xinstall -m 644 [glob ${worksrcpath}/nepomuk/core/*.h] \
        ${destroot}${prefix}/include/nepomuk
    eval xinstall -m 644 [glob ${worksrcpath}/nepomuk/types/*.h] \
        ${destroot}${prefix}/include/nepomuk
    eval xinstall -m 644 [glob ${worksrcpath}/nepomuk/nepomuk_export.h] \
        ${destroot}${prefix}/include/nepomuk    

    xinstall -d -m 755 ${destroot}${prefix}/Library/LaunchAgents
    xinstall -m 644 ${filespath}/org.macports.kdecache.plist \
        ${destroot}${prefix}/Library/LaunchAgents
    reinplace "s|%PREFIX%|${prefix}|g" \
        ${destroot}${prefix}/Library/LaunchAgents/org.macports.kdecache.plist
    reinplace "s|%APPLICATIONS_DIR%|${applications_dir}|g" \
        ${destroot}${prefix}/Library/LaunchAgents/org.macports.kdecache.plist
    
    # The startupitem.install keyword does not exist in MacPorts < 2.1.
    if {![info exists startupitem.install]} {
        set startupitem.install yes
    }
    if { ${startupitem.install} != "no" } {
        xinstall -d -m 755 ${destroot}${startup_root}/Library/LaunchAgents
        ln -s ${prefix}/Library/LaunchAgents/org.macports.kdecache.plist ${destroot}${startup_root}/Library/LaunchAgents
    }
}

post-activate {
    if { ![variant_isset no_root] } {
        file attributes ${prefix}/Library/LaunchAgents/org.macports.kdecache.plist -owner root -group wheel 
    }
}

notes-append "An agent to provide communication between KDE programs must be started.
To start it run the following command:
 launchctl load -w ${startup_root}/Library/LaunchAgents/org.macports.kdecache.plist"

#patch-authBackends: make possible to use OS X keychain through kwallet (see https://git.reviewboard.kde.org/r/119838/, shipped)
variant osxkeychain description {kwallet uses the OSX KeyChain} {
    configure.args-append   -DMAC_USE_OSXKEYCHAIN:BOOL=ON
}

variant no_root description {Run the kde cache agent as MacPorts install user.} {
    pre-fetch {
        if { ${install.user}=="root" || ${install.group}=="wheel" } {
            ui_error "The kde cache agent should not be run as root with no_root variant."
            error "Please do not use this variant with your MacPorts configuration."
        }
    }

    set startup_root  [join [lrange [exec /usr/bin/dscl . -read Users/${install.user} NFSHomeDirectory] 1 end]]
    # Files are installed into user's startup directory.
    destroot.violate_mtree  yes
}

livecheck.url       http://kde.mirrors.hoobly.com/stable/
livecheck.regex     (\\d+(\\.\\d+)+)