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

github.setup        fastfetch-cli fastfetch 2.66.0
revision            0
categories          sysutils
installs_libs       no
license             MIT
maintainers         {gmail.com:herby.gillot @herbygillot} \
                    {@barracuda156 macos-powerpc.org:barracuda} \
                    openmaintainer
description         Fastfetch is a neofetch-like tool for fetching system information \
                    and displaying them in a pretty way.
long_description    {*}${description}
checksums           rmd160  b73f21c3bed20f582c699d6b99d113fe9d6a8e73 \
                    sha256  547883c2f0dbc85a4545d4533f5b812fbc4c8ffe1271056de18b51994acbf474 \
                    size    1559549
github.tarball_from archive

set py_v            3.14
set py_v_nodot      [string map {. {}} ${py_v}]

depends_build-append \
                    path:bin/pkg-config:pkgconfig

depends_lib-append  port:chafa \
                    port:ImageMagick \
                    port:python${py_v_nodot} \
                    port:sqlite3 \
                    port:yyjson \
                    port:zlib

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

configure.args-append \
                    -DENABLE_APPLE_MEMSIZE_USABLE=OFF \
                    -DENABLE_CHAFA=ON \
                    -DENABLE_IMAGEMAGICK6=ON \
                    -DENABLE_IMAGEMAGICK7=OFF \
                    -DENABLE_LTO=OFF \
                    -DENABLE_LUA=OFF \
                    -DENABLE_OPENCL=OFF \
                    -DENABLE_QUICKJS=OFF \
                    -DENABLE_SQLITE3=ON \
                    -DENABLE_SYSTEM_YYJSON=ON \
                    -DENABLE_VULKAN=OFF \
                    -DENABLE_ZLIB=ON \
                    -DPython_EXECUTABLE=${configure.python}

compiler.c_standard     2011
compiler.cxx_standard   2017

patch.pre_args-replace  -p0 -p1

# 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.
# TODO: see if Cocoa-related fallbacks can be improved.

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 \
                    0013-wm_apple-unbreak.patch \
                    0014-unbreak-common-networking.patch \
                    0015-fix-ntohll.patch

# TODO: does this still work for 10.4 or it needs a fallback?

# 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.platform} eq "darwin" && ${os.major} < 10} {
    patchfiles-append \
                    0016-Tiger-specific-adjustments-to-CMakeLists.patch
}

# https://trac.macports.org/ticket/59917
if {${os.platform} eq "darwin" && ${os.major} < 13} {
    configure.cflags-append \
                    -F/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks
}

variant lto description "Build with LTO enabled" {
    configure.args-replace \
                    -DENABLE_LTO=OFF \
                    -DENABLE_LTO=ON
}

if {${os.platform} ne "darwin" || ${os.major} > 8} {
    default_variants    +lto
}
