# -*- 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               cmake 1.1
PortGroup               github 1.0
PortGroup               legacysupport 1.1

# clock_gettime
legacysupport.newest_darwin_requires_legacy 16

github.setup            lcompilers lpython 0.22.0 v
revision                0
categories              lang python
maintainers             {@barracuda156 macos-powerpc.org:barracuda} openmaintainer
license                 BSD
description             High-performance typed Python compiler
long_description        LPython aggressively optimizes type-annotated \
                        Python code. It has several backends, including LLVM, \
                        C, C++ and WASM. LPython’s primary tenet is speed.
homepage                https://lpython.org

checksums               rmd160  d12384ff89beb5531b33e20b00b1b32466a68b53 \
                        sha256  72779cb7789deb2e501971cb80b8915ce244dda0b8e7532402b194d4dff3672b \
                        size    1360298
github.tarball_from     archive

set libfmt_v            11
cmake.prefix_path-append \
                        ${prefix}/lib/libfmt${libfmt_v}/cmake

depends_build-append    port:bash \
                        port:bison \
                        port:re2c
depends_lib-append      port:libfmt${libfmt_v} \
                        path:lib/pkgconfig/RapidJSON.pc:rapidjson \
                        port:zlib

set py_ver              3.12
set py_ver_nodot        [string map {. {}} ${py_ver}]
depends_lib-append      port:python${py_ver_nodot}

patchfiles-append       0001-stacktrace.cpp-include-syslimits.h-for-PATH_MAX.patch \
                        0002-UserOverride.cmake-fix-native-optflag-for-PowerPC.patch \
                        0003-Install-libs-into-a-sane-location.patch \
                        0004-patch-build0.sh.patch \
                        0005-patch-version.patch

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

post-patch {
    reinplace "s|@VERSION@|${version}|" ${worksrcpath}/ci/version.sh
    reinplace "s|@PYTHON@|${configure.python}|g" ${worksrcpath}/build0.sh
    reinplace "s|/usr/bin/env python|${configure.python}|" ${worksrcpath}/run_tests.py
}

compiler.cxx_standard   2017

# TODO: add support for LLVM for x86 and aarch64, as it is done for lfortran,
# once it gets fixed: https://github.com/lcompilers/lpython/issues/2462

configure.args-append   -DLPYTHON_BUILD_ALL=YES \
                        -DLPYTHON_STATIC_BIN=NO \
                        -DWITH_FMT=YES \
                        -DWITH_INTRINSIC_MODULES=NO \
                        -DWITH_JSON=YES \
                        -DWITH_LCOMPILERS_FAST_ALLOC=YES \
                        -DWITH_LLVM=NO \
                        -DWITH_MACHO=YES \
                        -DWITH_RUNTIME_LIBRARY=YES \
                        -DWITH_STACKTRACE=NO \
                        -DWITH_UNWIND=NO \
                        -DWITH_ZLIB=YES

pre-configure {
    system -W ${worksrcpath} "sh ./build0.sh"
}

# CMake Error at CMakeLists.txt:23 (message): CMAKE_BUILD_TYPE
# must be one of: Debug, Release (current value: 'MacPorts')
cmake.build_type        Release

platform powerpc {
    # Since no buildbot for PowerPC, we use -mtune=native,
    # and just in case force a local build:
    archive_sites
}

test.run                yes
