# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           legacysupport 1.1
#PortGroup           makefile 1.0

name                micropython
version             1.28.0
revision            0
categories          devel lang
maintainers         {i0ntempest @i0ntempest} openmaintainer
license             GPL-2

description         Python implementation for microcontrollers and constrained systems
long_description    The MicroPython project aims to put an implementation of Python 3.x on \
                    microcontrollers and small embedded systems. \
                    MicroPython implements the entire Python 3.4 syntax (including exceptions, \
                    with, yield from, etc., and additionally async/await keywords from Python 3.5). \
                    The following core datatypes are provided: str (including basic Unicode support), \
                    bytes, bytearray, tuple, list, dict, set, frozenset, array.array, \
                    collections.namedtuple, classes and instances. Builtin modules include sys, time, \
                    and struct, etc. Select ports have support for _thread module (multithreading). \
                    Note that only a subset of Python 3 functionality is implemented for the data types and modules.

use_xz              yes

checksums           rmd160  021fd5bff33a334d25f16b4c304eeac6497a7c89 \
                    sha256  4e43c59657b8da33b4bc503509a827cc3ea6cb66c446475c57776cf4467ba215 \
                    size    109206752

homepage            https://micropython.org/
master_sites        ${homepage}resources/source/
livecheck.url       ${homepage}download/

# clock_gettime
legacysupport.newest_darwin_requires_legacy 15

use_configure       no
#makefile.override-append \
                    PREFIX

# mpconfig.h: error: #error endianness not defined and cannot detect it
compiler.blacklist-append \
                    *gcc-4.0 *gcc-4.2
# error: cannot compile this unexpected cast lvalue yet on macOS < 10.10
compiler.blacklist-append \
                    {clang < 700}

build.env-append    CC=${configure.cc}
build.args-append   V=1
destroot.env-append PREFIX=${prefix}

set python_branch   3.14
depends_build-append \
                    port:python[string map {. ""} ${python_branch}]

# These can be applied to both subports.
post-patch {
    reinplace "s|PYTHON = python3|PYTHON = ${prefix}/bin/python${python_branch}|" ${worksrcpath}/py/mkenv.mk
    reinplace "s|PREFIX = /usr/local|PREFIX ?= /usr/local|g" ${worksrcpath}/ports/unix/Makefile
    # https://trac.macports.org/ticket/70707
    reinplace "s|CC = clang|CC = ${configure.cc}|" ${worksrcpath}/ports/unix/Makefile ${worksrcpath}/mpy-cross/Makefile
    reinplace "s|-Werror||g" ${worksrcpath}/ports/unix/Makefile ${worksrcpath}/mpy-cross/Makefile
}

if {${name} eq ${subport}} {
    depends_build-append \
                    path:bin/pkg-config:pkgconfig
    depends_run-append  \
                    port:mpy-cross

    build.dir       ${worksrcpath}/ports/unix

    post-destroot {
        set docdir ${prefix}/share/doc/${subport}
        xinstall -d ${destroot}${docdir}
        xinstall -m 0644 -W ${worksrcpath} \
            README.md LICENSE ACKNOWLEDGEMENTS CONTRIBUTING.md CODECONVENTIONS.md CODEOFCONDUCT.md \
            ${destroot}${docdir}
    }

    variant preview_v2 description {Preview features in version 2.x} {
        build.args-append \
                        MICROPY_PREVIEW_VERSION_2=1
    }
}

subport mpy-cross {
    categories-delete   lang
    categories-append   cross
    description         MicroPython cross compiler utility
    long_description    ${subport} is the MicroPython cross compiler utility, used to pre-compile \
                        python files into bytecode suitable for running on your target.

    build.dir           ${worksrcpath}/${subport}

    destroot {
        xinstall -m 755 ${build.dir}/build/${subport} ${destroot}${prefix}/bin
        set docdir ${prefix}/share/doc/${subport}
        xinstall -d ${destroot}${docdir}
        xinstall -m 0644 -W ${build.dir} \
            README.md \
            ${destroot}${docdir}
    }
    livecheck.type      none
}
