# -*- coding: utf-8; mode: tcl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=2:ts=2:sts=2
# $Id: Portfile 116066 2014-01-17 09:32:02Z mojca@macports.org $

PortSystem          1.0
PortGroup           active_variants 1.1
PortGroup           python          1.0
PortGroup           wxWidgets       1.0

name                py-wxpython-2.8
version             2.8.12.1
set branch          [join [lrange [split ${version} .] 0 1] .]
categories-append   graphics devel
license             wxwidgets-3.1
platforms           darwin
maintainers         jwa mojca

description         Python interface to the wxWidgets ${branch} cross platform GUI
long_description    wxPython is a GUI toolkit for the Python programming \
                    language. It allows Python programmers to create \
                    programs with a robust, highly functional graphical \
                    user interface, simply and easily. It is implemented \
                    as a Python extension module (native code) that wraps \
                    the wxWidgets cross platform GUI library, written in C++. \
                    Version 2.8 is provided for compatibility reasons only. \
                    See description of wxWidgets-2.8 for further details.

homepage            http://www.wxpython.org/
master_sites        sourceforge:wxpython

distname            wxPython
use_bzip2           yes

checksums           rmd160  94eae06087bdd930e21bf90cc6672f93a1f5a17a \
                    sha256  1f3f153d9f1504c6ce2d2c4b23e940b8f58b81f4cba35cda1a5bb31142243cd0

python.versions     24 25 26 27
python.default_version 27

distfiles           ${distname}-src-${version}${extract.suffix}
dist_subdir         ${distname}/${version}
worksrcdir          ${distname}-src-${version}/wxPython

# extract just the docs and wxPython subdir
extract.post_args   "| tar -xf - ${worksrcdir} ${distname}-src-${version}/docs"

if {${name} ne ${subport}} {
    conflicts               py${python.version}-wxpython-3.0
    patchfiles              patch-config.py.diff

    variant carbon conflicts gtk description {use 32-bit carbon-based wxWidgets} {
        wxWidgets.use       wxWidgets-2.8
        depends_lib-append  port:${wxWidgets.port}
        # TODO: the following line would end up with --no-user-cfg
        #build.args         WX_CONFIG="${wxWidgets.wxconfig}"
        build.cmd           ${python.bin} setup.py WXPORT="mac" WX_CONFIG="${wxWidgets.wxconfig}"
        destroot.cmd        ${python.bin} setup.py WXPORT="mac" WX_CONFIG="${wxWidgets.wxconfig}"

        # TODO: test if this works on 10.7
        post-patch {
            reinplace       "s|# @@FLAGS1@@|cflags.extend(\[\"-arch\", \"[join [get_canonical_archs] {\", \"-arch\", \"}]\"\])|" ${worksrcpath}/config.py
            reinplace       "s|# @@FLAGS2@@|lflags.extend(\[\"-arch\", \"[join [get_canonical_archs] {\", \"-arch\", \"}]\"\])|" ${worksrcpath}/config.py
            if {${wxWidgets.sdk} ne ""} {
                reinplace   "s|# @@FLAGS3@@|cflags.extend(\[\"-isysroot\", \"${wxWidgets.sdk}\"\])|" ${worksrcpath}/config.py
            }
        }
        post-destroot {
            delete          ${destroot}${wxWidgets.prefix}
        }
    }

    variant gtk conflicts carbon description {use wxGTK} {
        wxWidgets.use       wxGTK-2.8
        # not sure if/what other dependencies should be listed here
        depends_build       port:pkgconfig
        depends_lib-append  path:lib/pkgconfig/cairo.pc:cairo \
                            port:gtk2 \
                            port:${wxWidgets.port}
        require_active_variants path:lib/pkgconfig/cairo.pc:cairo x11
        require_active_variants gtk2  x11

        build.cmd           ${python.bin} setup.py WXPORT="gtk2" WX_CONFIG="${wxWidgets.wxconfig}"
        destroot.cmd        ${python.bin} setup.py WXPORT="gtk2" WX_CONFIG="${wxWidgets.wxconfig}"

        post-patch {
            reinplace       "s|# @@FLAGS1@@|cflags.extend(\[\"-arch\", \"[join [get_canonical_archs] {\", \"-arch\", \"}]\"\])|" ${worksrcpath}/config.py
            reinplace       "s|# @@FLAGS2@@|lflags.extend(\[\"-arch\", \"[join [get_canonical_archs] {\", \"-arch\", \"}]\"\])|" ${worksrcpath}/config.py
        }
        post-destroot {
            delete          ${destroot}${wxWidgets.prefix}
        }
    }

    if {![variant_isset carbon] && ![variant_isset gtk]} {
        # gtk will be the default variant
        # using +carbon is possible on <= 10.6 (or 10.7 with an old Xcode version)
        default_variants-append +gtk
    }

    livecheck.type  none
} else {
    # Once upon a time this would install the documentation,
    # however the python PortGroup disables all steps including fetching & extracting
    # which makes it a bit inconvenient to do things like this.
    # If anyone is missing the docs badly enough, you are welcome to fix this
    # in both py-wxpython-2.8 and py-wxpython-3.0.
    #
    # post-destroot {
    #     xinstall -d -m 755 ${destroot}${prefix}/share/doc/
    #     file copy ${worksrcpath}/docs ${destroot}${prefix}/share/doc/${name}
    #     file copy ${worksrcpath}/samples ${destroot}${prefix}/share/doc/${name}/examples
    # }

    livecheck.type  regex
    livecheck.url   ${homepage}
    livecheck.regex wxPython(?: | \\(classic\\) )(2\\.8\\.\[0-9\]+\\.\[0-9\]+)
}
