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

name            gtk-osx-application
conflicts       ige-mac-integration
version         2.0.8
license         LGPL-2.1
set branch      [join [lrange [split ${version} .] 0 1] .]
categories      devel
maintainers     elelay openmaintainer

description	Mac OS X menu bar integration library for GTK2 quartz

long_description \
		A simple library whose purpose is to \
		allow GTK quartz applications to integrate with \
		the Mac OS X menu bar. Requires gtk2 or gtk3 and its \
		dependencies to be built with variant +quartz

homepage        https://wiki.gnome.org/Projects/GTK%2B/OSX/Integration

platforms       darwin

set myname      gtk-mac-integration
master_sites    gnome:sources/gtk-mac-integration/${branch}/
distname        ${myname}-${version}
use_xz          yes

# sha256 from upstream, rmd160 computed locally
checksums       sha256    74fce9dbc5efe4e3d07a20b24796be1b1d6c3ac10a0ee6b1f1d685c809071b79 \
                rmd160    53fd44172a3fa076e4401b6aac1adb10b76a5b7c


depends_build   port:pkgconfig

set gtk_version gtk2

pre-configure {

  if {${name} eq ${subport}} {
    ui_error "
The gtk-osx-application port has been replaced by 'gtk-osx-application-gtk2'
and 'gtk-osx-application-gtk3'.
Please `sudo port deactivate gtk-osx-application`
followed by `sudo port upgrade -u outdated` or another command to update.
Then if all works as intended `sudo port uninstall gtk-osx-application`
"
    return -code error
  }

  if {![active_variants $gtk_version quartz ""]} {
    ui_error "
${subport} is meant to be used only in a GTK quartz
development environment but your version of GTK does not
support quartz.  Please make sure that port $gtk_version and all its
dependencies are built with variants +quartz and try again.
"
    error "$gtk_version +quartz not installed."
  }
}

# py27-gtk-osx-application-gtk3 is not needed (only gir matters).
# If a python gtk3 program requires gtk-osx-application, add
#    depends_lib-append port:gtk-osx-application-gtk3 \
#                       port:py27-gobject3

subport py27-gtk-osx-application-gtk2 {
    set gtk_version gtk2

    depends_lib-append port:py27-pygtk \
                       port:gtk-osx-application-gtk2
    
    set python_prefix           ${frameworks_dir}/Python.framework/Versions/2.7

    configure.python            ${python_prefix}/bin/python2.7
    configure.env-append        PYGTK_CODEGEN=${python_prefix}/bin/pygtk-codegen-2.0
    configure.env-append        PYGOBJECT_CODEGEN=${python_prefix}/bin/pygobject-codegen-2.0
    configure.pkg_config_path   ${python_prefix}/lib/pkgconfig/
    configure.pre_args          --prefix=${python_prefix}


    configure.args-append --with-gtk2 --without-gtk3 --disable-introspection

    # enable-python defaults to all, but it must be set to
    # 'yes' otherwise pygtk bindings are not built.
    # By the way, I had no success configuring with --python=all
    # as per README (configure rejected the option).
    # So no gir for gtk2 variant
    configure.args-append --enable-python=yes
    
    post-destroot {
        delete ${destroot}${prefix}/include
        delete ${destroot}${prefix}/lib
        delete ${destroot}${prefix}/share
    }
}

subport gtk-osx-application-gtk3 {
    set gtk_version gtk3
    
    depends_lib-append port:gtk3 \
                       path:include/gtkmacintegration/gtk-mac-bundle.h:gtk-osx-application-common-gtk3

    
    # force gtk version
    configure.args-append --with-gtk3 --without-gtk2

    configure.args-append --enable-python=no

    post-destroot {
        delete ${destroot}${prefix}/include
        delete ${destroot}${prefix}/lib/pkgconfig/gtk-mac-integration.pc
        delete ${destroot}${prefix}/share/strings
    }
}

subport gtk-osx-application-common-gtk3 {
    set gtk_version gtk3
    
    depends_lib-append port:gtk3

    
    # force gtk version
    configure.args-append --with-gtk3 --without-gtk2

    configure.args-append --enable-python=no

    post-destroot {
        delete ${destroot}${prefix}/lib
        delete ${destroot}${prefix}/share/gir-1.0
    }
}

subport gtk-osx-application-gtk2 {
    set gtk_version gtk2

    depends_lib-append port:gtk2 \
                       path:include/gtkmacintegration/gtk-mac-bundle.h:gtk-osx-application-common-gtk2

    # force gtk version to 2.0
    configure.args-append --with-gtk2 --without-gtk3  --disable-introspection

    configure.args-append --enable-python=no

    post-destroot {
        delete ${destroot}${prefix}/include
        delete ${destroot}${prefix}/lib/pkgconfig/gtk-mac-integration.pc
        delete ${destroot}${prefix}/share/strings
    }
}

subport gtk-osx-application-common-gtk2 {
    set gtk_version gtk2

    depends_lib-append port:gtk2

    # force gtk version to 2.0
    configure.args-append --with-gtk2 --without-gtk3 --disable-introspection

    configure.args-append --enable-python=no

    post-destroot {
        delete ${destroot}${prefix}/lib
    }
}

configure.ccache        no
configure.cmd-append    --libdir=${prefix}/lib --includedir=${prefix}/include

patchfiles-append       patch-bindings-python-gtkmacintegration-Makefile-in.diff \
                        patch-bindings-python-gtk_osxapplication-Makefile-in.diff

livecheck.type          gnome
livecheck.name          ${myname}