# -*- 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.67.1
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  d77078e99f86c8dc6133955dc0a726d9fc0bff44 \
                    sha256  52489550d1fdeac8bde8b3442064e3bc78d28fda752a171dc46a6cd97454f237 \
                    size    1573878
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-CMakeLists-relax-warnings-as-errors-and-trim-Apple-f.patch \
                    0002-yyjson-detect-PowerPC-as-big-endian.patch \
                    0003-osascript-Apple-define-POOLSTART-POOLEND-autorelease.patch \
                    0004-osascript-Apple-wrap-in-NSAutoreleasePool-and-drop-A.patch \
                    0005-smc_temps-Apple-define-ntohll-manually-for-PowerPC.patch \
                    0006-version-Apple-use-non-ARC-only-plist-loading-and-NSA.patch \
                    0007-binary-Apple-define-FAT_MAGIC_64-fat_arch_64-fallbac.patch \
                    0008-kmod-Apple-stub-out-kext-detection-before-10.7.patch \
                    0009-networking-drop-connectx-fast-path-on-Apple-always-u.patch \
                    0010-processing-Apple-guard-proc_pidpath-libproc.h-behind.patch \
                    0011-bluetooth-Apple-wrap-detection-in-NSAutoreleasePool-.patch \
                    0012-brightness-Apple-add-ApplicationServices-include-for.patch \
                    0013-camera-Apple-guard-AVFoundation-import-behind-10.7-a.patch \
                    0014-codec-Apple-dlopen-VideoToolbox-instead-of-linking-i.patch \
                    0015-CPU-add-PowerPC-cpusubtype-to-name-mapping.patch \
                    0016-CPU-declare-ffCPUApplePPCCodeToName.patch \
                    0017-CPU-Apple-detect-PowerPC-via-hw.cpusubtype-sysctl.patch \
                    0019-disk-BSD-Apple-skip-st_birthtimespec-lookup-before-m.patch \
                    0020-displayserver-define-CG_LEGACY_API-for-pre-10.6-Powe.patch \
                    0021-displayserver-add-ffdsParseRefreshRate-for-CG_LEGACY.patch \
                    0022-displayserver-Apple-use-legacy-CGS-mode-API-under-CG.patch \
                    0023-font-Apple-wrap-detection-in-NSAutoreleasePool-on-pr.patch \
                    0024-gpu-Apple-skip-IORegistryEntryGetRegistryEntryID-bef.patch \
                    0025-gpu-Apple-guard-Metal-driver-version-device-detectio.patch \
                    0026-host-Apple-guard-IOPlatformExpertDevice-lookup-behin.patch \
                    0027-host-add-PowerBook-and-PowerMac-model-name-mappings.patch \
                    0028-memory-Apple-fall-back-to-32-bit-host_statistics-on-.patch \
                    0029-opengl-Apple-request-a-legacy-double-buffered-pixel-.patch \
                    0030-os-Apple-use-non-ARC-only-plist-loading-and-NSAutore.patch \
                    0031-physicalmemory-Apple-use-legacy-NSPropertyListSerial.patch \
                    0032-sound-Apple-alias-kAudioObjectPropertyScope-Input-Ou.patch \
                    0033-swap-Apple-don-t-gate-vm.compressor_mode-check-on-ma.patch \
                    0034-terminalfont-Apple-use-dictionaryWithContentsOfFile-.patch \
                    0035-version-also-recognize-__POWERPC__-for-FF_ARCHITECTU.patch \
                    0036-wallpaper-Apple-restrict-Sonoma-wallpaper-store-look.patch \
                    0037-wm-Apple-stub-out-plugin-version-detection-before-ma.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 \
                    0038-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
}
