# -*- 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

name                libnewt
version             0.52.25
revision            0
checksums           rmd160  5d302883cae1635792426e593f8201e414a5f1ef \
                    sha256  ef0ca9ee27850d1a5c863bb7ff9aa08096c9ed312ece9087b30f3a426828de82 \
                    size    176729

categories          devel
maintainers         {ryandesign @ryandesign} openmaintainer
license             GPL-2

description         text-mode widget-based user interface library
set libnewt_desc    ${description}

long_description    Newt is a programming library for color text-mode, \
                    widget-based user interfaces. Newt can be used to add \
                    stacked windows, entry widgets, checkboxes, radio \
                    buttons, labels, plain text fields, scrollbars, etc., \
                    to text mode user interfaces.

homepage            https://pagure.io/newt
master_sites        https://releases.pagure.org/newt/

distname            newt-${version}

depends_build-append \
                    port:gettext

depends_lib-append  port:gettext-runtime \
                    port:popt \
                    port:slang2

patchfiles          patch-Makefile.in.diff \
                    patch-configure.ac.diff

# We are patching configure.ac and Makefile.in.
use_autoreconf      yes

configure.args      --without-python \
                    --without-tcl

# configure: WARNING: unrecognized options: --disable-dependency-tracking
# gcc-4.2: -E, -S, -save-temps and -M options are not allowed with multiple -arch flags
universal_variant   no

if {${subport} eq ${name}} {
    revision                0

    livecheck.type          regex
    livecheck.url           [lindex ${master_sites} 0]
    livecheck.regex         {newt-([0-9.]+)\.tar}
} else {
    depends_lib-append      port:${name}

    # Don't build libnewt again; link with the one that's already installed.
    build.args              LIBNEWTSH=
    destroot.args           LIBNEWTSH=

    livecheck.type          none
}

subport whiptcl {
    revision                0

    description             tcl bindings for ${name}

    long_description        ${subport} provides {*}${description}, a \
                            ${libnewt_desc}.

    depends_lib-append      port:tcl

    configure.args-replace  --without-tcl --with-tcl
    # It can't find tclConfig.sh unless libdir is expanded
    # https://pagure.io/newt/issue/5
    configure.args-append   --libdir=${prefix}/lib

    build.target            whiptcl.so

    destroot.target         install-tcl
}

set python_versions [list 3.10 3.11 3.12 3.13]

foreach pv ${python_versions} {
    set pv_no_dot [string map {. {}} ${pv}]
    subport py${pv_no_dot}-${name} {
        revision            0

        description         python ${pv} bindings (the \"snack\" module) for \
                            ${name}

        long_description    {*}${description}, a ${libnewt_desc}.

        categories-append   python

        depends_lib-append  port:python${pv_no_dot}

        configure.args-replace \
                            --without-python --with-python=python${pv}

        build.target        _snack.so

        destroot.target     install-py
    }
}
