# -*- 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
PortGroup           select          1.0
PortGroup           wxWidgets       1.0

name                wxWidgets-2.8
version             2.8.12
revision            6
set branch          [join [lrange [split ${version} .] 0 1] .]
set wxpythonsubset  wxPython-2.8.12.1-MacPorts-subset

categories          graphics devel
platforms           darwin
license             LGPL-2+
maintainers         nomaintainer

description         C++ framework for cross-platform GUI development
long_description    wxWidgets ${branch} is an open-source cross-platform C++ \
                    GUI framework for Mac OS, Unix, Linux, Windows. \
                    Version 2.8 doesn't work with 64-bit Cocoa, so users \
                    can choose between native 32-bit Carbon-based wxWidgets-2.8 \
                    (requires SDK for 10.6 or lower) \
                    and X11-based wxgtk-2.8 which also works in 64-bit.\
                    The port is provided for compatibility reasons only \
                    and will be removed as soon as all dependencies \
                    start working with wxWidgets-3.0.

homepage            http://www.wxwidgets.org/
distname            wxWidgets
master_sites        sourceforge:project/wxwindows/${version} \
                    http://biolpc22.york.ac.uk/pub/${version}/ \
                    http://trac.macports.org/raw-attachment/ticket/19190/:trac

use_bzip2           yes

distfiles           ${distname}-${version}${extract.suffix} \
                    ${wxpythonsubset}${extract.suffix}:trac
dist_subdir         ${distname}/${version}

checksums           ${distname}-${version}${extract.suffix} \
                    rmd160  928e221abe1a00cd2d72d2a4fd3640ba639b9915 \
                    sha256  3b0ac1d2d017683851841501c8e1b744b97242d684a1668ded61809b0504f707 \
                    ${wxpythonsubset}${extract.suffix} \
                    rmd160  df824e5cd99cb2fc927194526edadd2f650a1c87 \
                    sha256  01d77736aca3d16d1c26aa1002748bf43cd8ad261802f35e9a8f7b75c2227e8a

subport wxgtk-2.8   {}

if {${name} eq ${subport}} {
    wxWidgets.use   wxWidgets-2.8
    set installname wxWidgets
    set wxtype      mac
} else {
    wxWidgets.use   wxGTK-2.8
    set installname wxGTK
    set wxtype      gtk2
}
set installtype     release
set contrib         "gizmos stc ogl"

depends_lib         path:include/turbojpeg.h:libjpeg-turbo \
                    port:tiff \
                    port:libpng \
                    port:zlib \
                    port:libiconv \
                    port:expat

depends_run         port:wxWidgets-common\
                    port:wxWidgets_select

# see https://trac.macports.org/ticket/57508
configure.env-append \
                    GREP=/usr/bin/grep

set selectdir       ${workpath}/select
select.group        wxWidgets
select.file         ${selectdir}/${subport}

worksrcdir          ${distname}-${version}/build

patchfiles          patch-chkconf.diff \
                    patch-configure.diff \
                    patch-sdl.diff \
                    patch-src-gtk-app.cpp.diff
patch.dir           ${workpath}/${distname}-${version}

post-patch {
    reinplace "s|@@ARCHS@@|[get_canonical_archflags]|g" ${patch.dir}/configure
    reinplace "s|@@PREFIX@@|${prefix}|g"                ${patch.dir}/configure

    file mkdir ${selectdir}
    system "echo \"${wxWidgets.wxdir}/wx-config\n${wxWidgets.wxdir}/wxrc-${branch}\" > ${select.file}"
}

configure.cmd       ../configure
configure.args      --prefix=${wxWidgets.prefix} \
                    --with-mac \
                    --with-libiconv-prefix=${prefix} \
                    --with-libjpeg \
                    --with-libtiff \
                    --with-libpng \
                    --with-zlib \
                    --with-opengl \
                    --without-sdl \
                    --disable-sdltest \
                    --enable-unicode \
                    --enable-display \
                    --enable-graphics_ctx \
                    --enable-universal_binary

if {${wxWidgets.sdk} eq ""} {
    configure.args-append   --with-macosx-sdk=no \
                            --with-macosx-version-min=no
} else {
    configure.args-append   --with-macosx-sdk=${wxWidgets.sdk} \
                            --with-macosx-version-min=${wxWidgets.macosx_version_min}
}

# wxgtk-2.8 (it doesn't work with Quartz)
if {${name} ne ${subport}} {
    depends_build-append    port:pkgconfig
    depends_lib-append      path:lib/pkgconfig/cairo.pc:cairo \
                            path:lib/pkgconfig/gtk+-2.0.pc:gtk2 \
                            port:libGLU \
                            port:mesa \
                            port:libsdl \
                            port:libsdl_mixer

    require_active_variants path:lib/pkgconfig/cairo.pc:cairo x11
    require_active_variants gtk2 x11

    configure.args-delete   --with-mac \
                            --without-sdl
    configure.args-append   --with-gtk \
                            --with-sdl
}

post-build {
    foreach c { ${contrib} } {
        system -W ${build.dir} "make -C contrib/src/${c}"
    }
    # remove -arch flags from `wx-config --libs`
    reinplace -E {s|-arch [a-z0-9_]+||g} lib/wx/config/${wxtype}-unicode-${installtype}-${branch}
}

post-destroot {
    foreach c { ${contrib} } {
        system -W ${build.dir} "make -C contrib/src/${c} install ${destroot.destdir}"
    }

    # copy a subset of wxPython to wxWidgets to prevent a conflict
    # between py2X-wxpython-2.8 and py2Y-wxpython-2.8
    copy ${workpath}/wxPython ${destroot}${wxWidgets.prefix}/include/wx-${branch}/wx/

    # copy a subset of documetation
    set destdocdir ${destroot}${wxWidgets.prefix}/share/doc/${distname}
    xinstall -d -m 755 ${destdocdir}
    xinstall -m 644 -W ${workpath}/${distname}-${version} \
    install-mac.txt readme-mac.txt \
    install-gtk.txt readme-gtk.txt ${destdocdir}

    # maybe not needed
    set confscript ${wxWidgets.prefix}/lib/wx/config/${wxtype}-unicode-${installtype}-${branch}
    ln -sf ${confscript} ${destroot}${wxWidgets.prefix}/bin/wx-config
}

variant aui description {add support for AUI docking library} {
    configure.args-append    --enable-aui
}

variant monolithic description {build only one library} {
    configure.args-append    --enable-monolithic
}

variant debug description {add debug info to libraries} {
    configure.args-append    --enable-debug
    set installtype debug
}


if {${subport} eq ${name}} {
    # when version 3.2 gets released, the livecheck might not be valid any more
    livecheck.type  regex
    livecheck.url   ${homepage}/downloads/
    livecheck.regex Previous Stable Release.*(2\\.8\\.\[0-9\]+)
} else {
    livecheck.type  none
}
