# -*- coding: utf-8; mode: tcl; tab-width: 4; truncate-lines: t; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4

PortSystem          1.0

fetch.type          git
git.url             https://invent.kde.org/system/qtcurve.git

name                QtCurve
set qtc_version     1.9.0
if {${subport} eq "${name}-gtk2"} {
    # the GTk2 branch barely evolves at all so QtCurve-gtk2 doesn't need to
    # be updated every time the Qt version evolves.
    git.branch      9cd0f0eb740f26b7e03244be64491da2c3f56569
    version         ${qtc_version}.8
} else {
    git.branch      2bb3e383c12f46f0ad599386edc51972effc5930
    version         ${qtc_version}.27
}
epoch               2


description         A set of widget styles for Qt4/KDE4, Qt5/KF5 and/or GTk2 based apps.

categories          kde
platforms           darwin linux
license             LGPL-2+
maintainers         {gmail.com:rjvbertin @RJVB}

homepage            http://kde-look.org/content/show.php?content=40492
master_sites        http://quickgit.kde.org/?p=qtcurve.git

livecheck.type      none

worksrcdir          ${name}-${qtc_version}

if {${subport} ne "${name}-extra"} {
    PortGroup       muniversal 1.0
}

test.run            yes

compiler.cxx_standard   2011

subport ${name}-qt5 {}
# Safeguard against installing a port variant for the still uncommitted KF5 ports
if {${subport} eq "${name}-qt5"} {
    if {![variant_isset qtonly]} {
        default_variants +qtonly
    }
}

subport ${name}-gtk2 {
    PortGroup               cmake 1.1
    long_description        The GTk2 version of the highly configurable QtCurve widget style for Qt

    post-patch {
        # QtCurve-gtk2 has pure and optional runtime dependencies on KDE4 (and KF5)
        reinplace "s|kde4-config|${prefix}/bin/kde4-config|g" \
                            ${worksrcpath}/gtk2/style/qt_settings.cpp
    }

    # standard post-arg, where to find the primary CMakeLists.txt file.
    default configure.post_args {../${worksrcdir}}
    default configure.dir       {${workpath}/build}
    default build.dir           {${workpath}/build}

    variant LTO description {Build with Link-Time Optimisation (LTO)} {
        configure.cflags-append             -flto
        configure.cxxflags-append           -flto
        configure.objcflags-append          -flto
        configure.objcxxflags-append        -flto
        configure.ldflags-append            -flto
        # assume any compiler not clang will be gcc
        if {![string match "*clang*" ${configure.compiler}]} {
            configure.cflags-append         -fuse-linker-plugin -ffat-lto-objects
            configure.cxxflags-append       -fuse-linker-plugin -ffat-lto-objects
            configure.objcflags-append      -fuse-linker-plugin -ffat-lto-objects
            configure.objcxxflags-append    -fuse-linker-plugin -ffat-lto-objects
            configure.ldflags-append        -fuse-linker-plugin
        }
    }
    depends_build-append    port:pkgconfig
    depends_lib-append      path:lib/pkgconfig/gtk+-2.0.pc:gtk2
    depends_run-append      port:perl5
    configure.args-delete   -DQTC_ENABLE_X11:BOOL=OFF
    configure.args-append   -DENABLE_GTK2:BOOL=ON -DQTC_ENABLE_X11:BOOL=ON \
                            -DENABLE_QT4:BOOL=OFF -DENABLE_QT5:BOOL=OFF \
                            -DQTC_QT4_ENABLE_KDE:BOOL=OFF -DQTC_QT5_ENABLE_KDE:BOOL=OFF \
                            -DQTC_UTILSLIB_INFIX:STRING="-gtk2"
    post-destroot {
        # impose Mac-like defaults
        xinstall -m 644 ${filespath}/kdeglobals ${destroot}${prefix}/share/themes/QtCurve/gtk-2.0/kdeglobals
    }
}

subport ${name}-extra {
    long_description        Installs the Mac-specific default configuration plus additional \
                            configuration presets and colour palettes for QtCurve
    version                 ${qtc_version}
    use_configure           no
    installs_libs           no
    supported_archs         noarch
    platforms               any
    depends_run-append      port:ciment-icons
    fetch.type              standard
    distfiles
    build {}
    destroot {
        xinstall -m 755 -d ${destroot}${prefix}/share/apps/kstyle/themes
        xinstall -m 755 -d ${destroot}${prefix}/share/apps/color-schemes
        xinstall -m 755 -d ${destroot}${prefix}/etc/xdg/qtcurve
        xinstall -m 644 ${filespath}/stylerc ${destroot}${prefix}/etc/xdg/qtcurve/
        xinstall -m 644 ${filespath}/qtc_qtcurve-rjvb.themerc ${destroot}${prefix}/share/apps/kstyle/themes/
        xinstall -m 644 ${filespath}/qtc_qtcurve-osx.themerc ${destroot}${prefix}/share/apps/kstyle/themes/
        xinstall -m 644 ${filespath}/qtc_qtcurve-osxgraphite.themerc ${destroot}${prefix}/share/apps/kstyle/themes/
        xinstall -m 644 ${filespath}/QtCurveOSX.colors ${destroot}${prefix}/share/apps/color-schemes/
        xinstall -m 644 ${filespath}/OxygenOSXGraphite.colors ${destroot}${prefix}/share/apps/color-schemes/
    }
}

if {${subport} ne "${name}-extra"} {
    depends_run-append      port:${name}-extra

    patchfiles-append       patch-systemconfig-support.diff
    # deactivate config page(s) that don't make sense on OS X and/or don't work properly anywhere
    patchfiles-append       patch-deactivate-config-page.diff
    post-patch {
        reinplace -W ${worksrcpath} "s|@@PREFIX@@|${prefix}|g" \
                            qt5/common/config_file.cpp \
                            qt4/common/config_file.cpp \
                            gtk2/common/config_file.cpp
    }
}

if {(${subport} ne "${name}-gtk2") && (${subport} ne "${name}-extra")} {
    patchfiles-append       patch-qtc-no-qtc-activewin-events.diff
    # https://bugs.kde.org/show_bug.cgi?id=374224
    patchfiles-append       patch-simpler-translucent-menus.diff

    # https://trac.macports.org/ticket/66864
    patchfiles-append       patch-qtcurve-qpainterpath.diff

    if {${subport} eq "${name}-qt5"} {

        categories              kde kf5 qt5

        if {![variant_isset qtonly]} {
            PortGroup               kf5 1.1
            long_description        A highly configurable widget style for Qt5/KF5
            depends_build-append    port:gettext \
                                    ${kf5::pythondep}
            kf5.depends_frameworks  karchive kconfig kconfigwidgets \
                                    ki18n kdelibs4support kguiaddons kio \
                                    kiconthemes kwidgetsaddons kwindowsystem \
                                    kxmlgui frameworkintegration

            configure.args-append   -DPYTHON_EXECUTABLE=${prefix}/bin/python${kf5::pyversion} \
                                    -DQTC_QT5_ENABLE_KDE:BOOL=ON
            if {![variant_isset devel]} {
                kf5.allow_apidocs_generation no
            }
            platform darwin {
                notes-append        "Install port:kf5-osx-integration and set KDE_SESSION_VERSION to 5 \
                                    (launchctl setenv KDE_SESSION_VERSION 5 and the equivalent expr. in your login script) \
                                    in order to use this or any other KDE theme automatically in Qt5 and KF5 \
                                    applications."
            }
            platform linux {
                configure.args-append \
                                    -DQTC_QT5_ENABLE_KWIN:BOOL=ON
            }
        } else {
            PortGroup               cmake 1.1
            # Prefer port:qt5-kde if the user hasn't installed a Qt5 port yet.
            # This *is* a KDE style after all.
            set qt5.prefer_kde      1
            PortGroup               qt5 1.0
            long_description        A highly configurable widget style for Qt5
            cmake.install_rpath-prepend \
                                    ${qt_libs_dir}
            configure.args-append   -DQTC_QT5_ENABLE_KDE:BOOL=OFF
        }
        qt5.depends_component   qtsvg

        # CMake will look for automoc4, but will of course not use it.
        configure.args-append   -DENABLE_QT4:BOOL=OFF -DENABLE_QT5:BOOL=ON \
                                -DQTC_QT4_ENABLE_KDE:BOOL=OFF \
                                -DQTC_UTILSLIB_INFIX:STRING="-qt5"
    } else {

        categories              kde kde4 qt4

        if { [variant_isset qtonly] } {
            PortGroup           qt4 1.0
            PortGroup           cmake 1.1
            long_description    A highly configurable widget style for Qt4
        } else {
            PortGroup           kde4 1.1
            depends_lib-append  port:kdelibs4
            long_description    A highly configurable widget style for Qt4/KDE4
        }

        configure.args-append   -DENABLE_QT4:BOOL=ON -DENABLE_QT5:BOOL=OFF \
                                -DQTC_QT5_ENABLE_KDE:BOOL=OFF -DQTC_UTILSLIB_INFIX:STRING="-qt4"

        notes-append "To access QtCurve and other KDE styles from pure Qt4 applications, execute
         ln -s ${prefix}/lib/kde4/plugins/styles ${qt_plugins_dir}
         with the appropriate privileges"
    }

    configure.args-append       -DQTC_QT4_STYLE_SUPPORT:BOOL=OFF -DQTC_QT4_ENABLE_KWIN:BOOL=OFF \
                                -DQTC_INSTALL_PO:BOOL=ON -DENABLE_GTK2:BOOL=OFF
    if {${os.platform} eq "darwin"} {
        configure.args-append   -DQTC_ENABLE_X11:BOOL=OFF
    }

    variant qtonly description {Build only Qt style support, for installations without KDE} {}

    if { [variant_isset qtonly] } {
        configure.args-append   -DQTC_QT4_ENABLE_KDE:BOOL=OFF -DQTC_QT5_ENABLE_KDE:BOOL=OFF
        configure.args-delete   -DQTC_QT4_ENABLE_KDE:BOOL=ON -DQTC_QT5_ENABLE_KDE:BOOL=ON
    } else {

        post-destroot {
            if {${subport} eq "${name}-qt5"} {
            } else {
                if {[file exists ${qt_plugins_dir}] && ![file exists ${qt_plugins_dir}/styles]} {
                    xinstall -d -m 755 ${destroot}${qt_plugins_dir}
                    ln -s ${prefix}/lib/kde4/plugins/styles ${destroot}${qt_plugins_dir}
                }
            }
        }

    }
}

# never strip binaries for more useful backtraces
configure.args-append           -DCMAKE_STRIP:FILEPATH=/bin/echo

if {${os.platform} eq "darwin" && ${os.major} < 13 && ${subport} ne "${name}-extra"} {
    long_description-append \n\
        This port requires the libc++ conversion but should also build with GCC 4.7 or later (configure.compiler=macports-gcc-4.7).
}

# kate: backspace-indents true; indent-pasted-text true; indent-width 4; keep-extra-spaces true; remove-trailing-spaces modified; replace-tabs true; replace-tabs-save true; syntax Tcl/Tk; tab-indents true; tab-width 4;