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

# remember to bump version of wxWidgets-common
github.setup        wxWidgets wxWidgets 3.2.8.1 v
github.tarball_from releases
revision            2
name                wxWidgets-3.2
wxWidgets.use       wxWidgets-3.2

set wxtype          osx_cocoa

set branch          [join [lrange [split ${version} .] 0 1] .]

categories          graphics devel
license             wxwidgets-3.1
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.

homepage            http://www.wxwidgets.org/

distname            wxWidgets-${version}
use_bzip2           yes

checksums           rmd160  5c2a2cd68e82541a5a7d3dd93211c8f4077ae74f \
                    sha256  ad0cf6c18815dcf1a6a89ad3c3d21a306cd7b5d99a602f77372ef1d92cb7d756 \
                    size    27449383

# see https://trac.macports.org/ticket/62087
platforms           {darwin >= 16}
if {${os.platform} eq "darwin" && [vercmp ${macosx_deployment_target} >= 15.0]} {
    macosx_deployment_target 14.0
}

dist_subdir         wxWidgets/${version}
worksrcdir          ${distname}/build
patch.dir           ${worksrcpath}/..

patchfiles          configure.patch \
                    dd3f2509499e0e6aac4ebf8dab72b5d496c5bfbc.patch

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

compiler.c_standard   2011
compiler.cxx_standard 2011

depends_build       port:pkgconfig

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

depends_run         port:wxWidgets-common \
                    port:wxWidgets_select

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

post-patch {
    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-libiconv-prefix=${prefix} \
                    --with-libjpeg \
                    --with-libtiff \
                    --with-libpng \
                    --with-zlib \
                    --with-opengl \
                    --with-cocoa \
                    --without-sdl \
                    --enable-aui \
                    --with-libcurl \
                    --disable-sdltest \
                    --enable-display \
                    --enable-xrc \
                    --enable-graphics_ctx \
                    --with-macosx-sdk=no \
                    --with-macosx-version-min=no \
                    --disable-compat30 \
                    --enable-cxx11 \
                    --disable-tests \
                    --enable-unicode \
                    --enable-display \
                    --enable-geometry \
                    --enable-optimise \
                    --enable-debugreport \
                    --enable-uiactionsim \
                    --enable-autoidman \
                    --enable-aui \
                    --enable-html \
                    --disable-stl \
                    --enable-richtext \
                    --enable-webview \
                    --enable-repro-build

if { ${os.platform} eq "darwin" && ${os.major} == 11 } {
    # https://trac.macports.org/ticket/58040
    configure.args-replace --with-macosx-sdk=no \
                           --with-macosx-sdk=${developer_dir}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk
    configure.args-replace --with-macosx-version-min=no \
                           --with-macosx-version-min=${macosx_deployment_target}
}

post-destroot {
    set confscript ${wxWidgets.prefix}/lib/wx/config/${wxtype}-unicode-${branch}
    ln -sf ${confscript} ${destroot}${wxWidgets.prefix}/bin/wx-config
}

# during the test period we could afford to disable compatibility to 3.0
# to detect the problems earlier
#
# for the moment provide a variant to allow testing *with* compatibility turned on
variant compat30 description {enable wxWidgets 3.0 compatibility (will become default)} {
    configure.args-replace \
                    --disable-compat30 \
                    --enable-compat30
}

# TODO: --disable-precomp-headers should hopefully no longer be needed (try building wxGTK with universal)
#       in both 3.0 branch and master
variant universal {
    set archs [join ${configure.universal_archs} ,]
    # --disable-precomp-headers is automatically selected with cocoa, but not with gtk
    # http://trac.wxwidgets.org/ticket/15454
    configure.args-append   --enable-universal_binary=${archs} \
                            --disable-precomp-headers
}

# Remove the default universal flags, universal is handled above
configure.universal_ldflags
configure.universal_cflags
configure.universal_cxxflags
configure.universal_cppflags

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

variant stdlib description {add support for various standard library features} {
    configure.args-append   --enable-stl \
                            --enable-std_containers \
                            --enable-std_iostreams \
                            --enable-std_string \
                            --enable-std_string_conv_in_wxstring
}

default_variants +compat30

github.livecheck.regex  {(3.2.[0-9.]+)}
