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

set my_name     pygtk
name            py-${my_name}
conflicts       py-${my_name}-devel
version         2.24.0
revision        7
set branch      [join [lrange [split ${version} .] 0 1] .]

python.versions 27

categories-append \
                x11

license         LGPL-2.1+
maintainers     {mascguy @mascguy} openmaintainer
description     PyGTK is the Python binding to GTK+ 2.x

long_description \
                PyGTK contains modules that allow you to use gtk in Python programs. \
                At present, it is a fairly complete set of bindings.

homepage        http://www.pygtk.org/
master_sites    gnome:sources/${my_name}/${branch}/
distname        ${my_name}-${version}
dist_subdir     py-${my_name}
use_bzip2       yes

checksums       rmd160  33f597def646261483cbbf5491aeb27bf0d22ea6 \
                sha256  cd1c1ea265bd63ff669e92a2d3c2a88eb26bcd9e5363e0f82c896e649f206912 \
                size    2361097

build.cmd       make
build.target    all

destroot.cmd    make

if {${name} ne ${subport}} {
    conflicts       py${python.version}-${my_name}-devel

    depends_build-append \
                    port:pkgconfig
    depends_lib-append \
                    port:atk \
                    path:lib/pkgconfig/gtk+-2.0.pc:gtk2 \
                    port:libglade2 \
                    port:py${python.version}-cairo \
                    port:py${python.version}-gobject \
                    port:py${python.version}-numpy

    patchfiles-append \
                    patch-configure.ac-automake-config-headers.diff \
                    patch-configure.ac-gtk-quartz.diff \
                    patch-configure.ac-pyexecdir.diff \
                    patch-pango.override-private-interface.diff \
                    patch-pango-find_shaper.diff

    compiler.c_standard         2011
    compiler.cxx_standard       2011

    use_autoreconf              yes
    autoreconf.post_args        "-I m4"

    use_configure   yes
    configure.python ${python.bin}
    configure.pre_args-delete   --prefix=${prefix}
    configure.pre_args-append   --prefix=${python.prefix}
    configure.cflags-append     -I${python.prefix}/include \
                                -Wno-deprecated-declarations \
                                -Wno-int-conversion
    configure.ldflags-append    -L${python.prefix}/lib
    configure.pkg_config_path   ${python.prefix}/lib/pkgconfig

    platform darwin 9 {
        post-patch {
            reinplace "s| -export-symbols-regex.*||g" \
                ${worksrcpath}/Makefile.in \
                ${worksrcpath}/gtk/Makefile.in
        }
    }

    # Fix build errors on 10.4 and 10.5, caused by outdated 'nm'
    # Issue: https://trac.macports.org/ticket/60286
    if {${os.platform} eq "darwin" && ${os.major} < 10} {
        depends_build-append port:cctools
        configure.env-append NM=${prefix}/bin/nm
        configure.args-append lt_cv_path_NM=${prefix}/bin/nm
    }

    destroot.destdir "DESTDIR=${destroot}"

    post-destroot {
        set docdir ${prefix}/share/doc/${subport}
        xinstall -d ${destroot}${docdir}
        xinstall -m 0644 -W ${worksrcpath} AUTHORS COPYING ChangeLog NEWS README \
            ${destroot}${docdir}
        xinstall -d ${destroot}${prefix}/share/gtk-doc/html
        ln -s ${python.prefix}/share/${my_name} ${destroot}${prefix}/share/${my_name}${python.branch}
        # devhelp requires gtk-doc directory name  and .devhelp file name (less the .devhelp) to match
        file rename ${destroot}${python.prefix}/share/gtk-doc/html/${my_name}/${my_name}.devhelp \
                    ${destroot}${python.prefix}/share/gtk-doc/html/${my_name}/${my_name}${python.branch}.devhelp
        file rename ${destroot}${python.prefix}/share/gtk-doc/html/${my_name} \
                    ${destroot}${prefix}/share/gtk-doc/html/${my_name}${python.branch}
    }

    variant quartz conflicts x11 {
        require_active_variants gtk2 quartz
    }
    variant x11 conflicts quartz {
        require_active_variants gtk2 x11
    }
    if {![variant_isset x11] && ![variant_isset quartz]} {
        default_variants +x11
    }

    livecheck.type  none
} else {
    livecheck.type  gnome
    livecheck.name  ${my_name}
}
