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

github.setup        fastfetch-cli fastfetch 2.65.2
github.tarball_from archive
revision            0

description         \
    Fastfetch is a neofetch-like tool for fetching system information and \
    displaying them in a pretty way.

long_description    {*}${description}

categories          sysutils
installs_libs       no
license             MIT
maintainers         {gmail.com:herby.gillot @herbygillot} \
                    openmaintainer

checksums           rmd160  651b49cfea3fe1a34578e986f1455f700ce8cc3c \
                    sha256  d0b318c33cf6c8bbae1162325f91624762a040a60f748941cbf1b4b99a75fa30 \
                    size    1555551

set py_branch       3.14
set py_version      [string map {. ""} ${py_branch}]

depends_build-append \
                    path:bin/pkg-config:pkgconfig \
                    port:python${py_version}

depends_lib-append  port:chafa                  \
                    port:sqlite3                \
                    port:yyjson

# clock_gettime
legacysupport.newest_darwin_requires_legacy \
                    15

configure.args-append \
                    -DENABLE_SYSTEM_YYJSON=ON \
                    -DENABLE_VULKAN=OFF \
                    -DENABLE_OPENCL=OFF \
                    -DENABLE_LUA=OFF

compiler.c_standard     2011
compiler.cxx_standard   2017

patch.pre_args-replace  -p0 -p1

# https://trac.macports.org/ticket/70616
if {${os.platform} eq "darwin" \
    && (${os.major} > 10 && ${os.major} < 15)} {
    patchfiles-append \
                    1001-CMakeLists-disable-bluetooth-modules.patch
}

post-patch {
    reinplace "s|#!/usr/bin/env python3|#!${prefix}/bin/python${py_branch}|" {*}[glob ${worksrcpath}/scripts/*.py]
    reinplace "s|find_package(Python)|find_package(Python ${py_branch})|g" ${worksrcpath}/CMakeLists.txt
}

if {${os.platform} eq "darwin" && ${os.major} < 11} {
    # 2.29.0 with the patches below is a noticeable improvement
    # over the earlier versions: display, cursor, opengl modules
    # now work; physicalmemory, wallpaper are not disabled.
    # Consider this version pegged for now. There are a few things
    # which do not yet work but look fixable, those may be
    # addressed. It makes little sense however to keep updating
    # the app to every next version; added bells & whistles are
    # of no use for legacy systems, while the core functionality
    # remains the same. Rebasing patches requires a lot of work
    # due to unsettled API and the code changed for the sake
    # of irrelevant for us systems.
    github.setup    fastfetch-cli fastfetch 2.29.0
    revision        0
    checksums       rmd160  e6549efbe91eed77641468535bf3d5bbb86dc60d \
                    sha256  c3fcccf9502e41c76c30e89530820bf1c7719257e5624bfa5fa77e6627ecb602 \
                    size    1136647

    # https://github.com/fastfetch-cli/fastfetch/issues/942
    # https://github.com/fastfetch-cli/fastfetch/issues/943
    # https://github.com/fastfetch-cli/fastfetch/issues/944
    # https://github.com/fastfetch-cli/fastfetch/issues/1148
    # TODO: make physicalmemory module actually display the info.
    patchfiles-append \
                    0001-Support-hostinfo-for-PowerPC-Macs.patch \
                    0002-version.c-add-a-missing-macro-for-powerpc.patch \
                    0003-Support-PowerPC-CPU-detection.patch \
                    0004-gpu_apple.-fix-for-older-systems.patch \
                    0005-opengl_apple.c-fix-for-10.7.patch \
                    0006-memory_apple-fix-for-32-bit.patch \
                    0007-sound_apple.c-fix-for-10.8.patch \
                    0008-brightness_apple.c-add-a-missing-include.patch \
                    0009-yyjson-PowerPC-macros.patch \
                    0010-swap_fat_arch_64-does-not-exist-in-10.6.patch \
                    0011-disk_bsd-no-support-for-creation-time-on-ppc.patch \
                    0012-Misc-fixes-for-legacy-systems.patch

    # Leopard needs this at least due to physicaldisk_apple module,
    # which uses definitions from storage/IOStorageDeviceCharacteristics.h (IOKit framework);
    # those only appear in 10A222 build of 10.6. When building on 10.6, please use at least
    # that SDK version, or otherwise disable physicaldisk_apple (see the patch).
    if {${os.major} < 10} {
        patchfiles-append \
                    0013-Tiger-specific-adjustments-to-CMakeLists.patch
    }

    # To make sure OpenCL is not accidentally enabled.
    configure.args-append \
                    -DENABLE_LTO=OFF \
                    -DENABLE_OPENCL=OFF

    # https://trac.macports.org/ticket/59917
    configure.cflags-append \
                    -F/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks
}
