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

github.setup        EUA wxHexEditor 0.24 v
revision            0
categories          sysutils devel
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer

description         Free hex editor / disk editor
long_description    {*}${description}
license             GPL-2
homepage            https://www.wxhexeditor.org

checksums           rmd160  dfb5fd7030291b9cbebd8625408e6c57304c11aa \
                    sha256  6ad993ba13a0076b31fb95daa7a812eae3b613d86f5e6709021e4d3398afcf00 \
                    size    1699052
github.tarball_from archive

if {${os.platform} eq "darwin" && ${os.major} > 20} {
    wxWidgets.use   wxWidgets-3.2

    # https://github.com/EUA/wxHexEditor/commit/ebe2449fac22089825d124935a215fd1c0739403
    patchfiles-append \
                    0001-Fix-build-for-wxWidgets-v3.1.2.patch
} elseif {${os.platform} eq "darwin" && ${os.major} > 12} {
    wxWidgets.use   wxWidgets-3.0-cxx11
} else {
    # While it builds on older systems with wxWidgets-3.0-cxx11,
    # it does not work due to a bug in wxWidgets-3.0.
    wxWidgets.use   wxGTK-3.0-cxx11
}

post-patch {
    reinplace "s|= /usr|= ${prefix}|" ${worksrcpath}/Makefile
}

set py_ver          3.12
set py_ver_nodot    [string map {. {}} ${py_ver}]

depends_build-append \
                    port:autoconf \
                    port:automake \
                    port:gettext \
                    port:libtool \
                    port:pkgconfig \
                    port:python${py_ver_nodot}

depends_lib-append  port:gettext-runtime \
                    port:${wxWidgets.port}

configure.python        ${prefix}/bin/python${py_ver}

compiler.cxx_standard   2011
compiler.openmp_version 2.5

if {[string match macports-clang* ${configure.compiler}]} {
    configure.ldflags-append \
                    -L${prefix}/lib/libomp \
                    -lomp
}

# See: https://github.com/EUA/wxHexEditor/issues/211
platform macosx {
    build.target    mac
}

build.args-append   WXCONFIG=${wxWidgets.wxconfig}

destroot {
    move ${worksrcpath}/${name}.app ${destroot}${applications_dir}/${name}.app
}
