# -*- 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           xcodeversion 1.0


if {${os.major} > 17} {
    version             3.4.21
    revision            0
    checksums           rmd160  00cc53ced493db0be593d730f518f56ba0ebe5a3 \
                        sha256  175b03c9ab41b7c3a5c62967c442fa306639effb5641554c5f6ae739198e0be3 \
                        size    28781228
    patchfiles          patch-Makefile-XC10.diff \
                        patch-remove-sparkle-3.4.diff \
                        patch-nsur.diff \
                        patch-xcode12.diff
} elseif {${os.major} > 16} {
    version             3.3.12
    revision            2
    checksums           rmd160  37d4204f97ac42431c5774a943ca0ab8f9a4c669 \
                        sha256  6eeeb3215d6725aa789d39108a8ebedbe1aa9f6d058dd33056d72471ecd02e14 \
                        size    20602868
    patchfiles          patch-Makefile-XC10.diff \
                        patch-remove-sparkle.diff \
                        patch-nsur.diff
} else {
    version             3.2.0
    revision            1
    checksums           rmd160  07915ff5db0545c0c059f47e7f71761e023a26e1 \
                        sha256  017aff348352369abcc994caaca0f6112e1f17c4d65041acdb9f19830b2b96bd \
                        size    11969144
    patchfiles          patch-Makefile.diff \
                        patch-nsur.diff
}

github.setup        gnachman iTerm2 ${version} v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
categories          aqua shells
platforms           {darwin >= 17}
maintainers         {mark @markemer} openmaintainer
license             GPL-2+
supported_archs     x86_64 arm64
use_xcode           yes

description         Enhanced terminal emulator program, successor to iTerm
long_description    \
    iTerm2 is a replacement for Terminal and the successor to iTerm. Its focus is on \
    performance, internationalization, and supporting innovative features \
    that make your life better.

homepage            https://iterm2.com/

livecheck.url       https://raw.githubusercontent.com/gnachman/iterm2-website/master/source/appcasts/final_modern.xml
livecheck.regex     {sparkle:version="([\d\.]+)"}

post-patch {
    # patch the python script out since it does not set the correct version and may cause trouble
    reinplace "s|exec tools/updateVersion.py|exec /usr/bin/true|g" ${worksrcpath}/iTerm2.xcodeproj/project.pbxproj
    # macOS 13/Xcode 14 seems to be requiring code signing (macOS 12 with XC14 now requires the same)
    if {${os.major} >= 21} {
        reinplace "s|CODE_SIGN_IDENTITY = \".*\";|CODE_SIGN_IDENTITY = \"-\";|g" ${worksrcpath}/iTerm2.xcodeproj/project.pbxproj
    } else {
        reinplace "s|CODE_SIGN_IDENTITY = \".*\";|CODE_SIGN_IDENTITY = \"\";|g" ${worksrcpath}/iTerm2.xcodeproj/project.pbxproj
    }
    reinplace "s|enableUBSanitizer = \"YES\"||g" ${worksrcpath}/iTerm2.xcodeproj/xcshareddata/xcschemes/iTerm2.xcscheme
    # Fix version number; see iTerm2/tools/updateVersion.py for version keys
    foreach {key} {CFBundleGetInfoString CFBundleShortVersionString CFBundleVersion} {
        system "/usr/libexec/PlistBuddy -c \"Set :${key} ${version}\" ${worksrcpath}/plists/iTerm2.plist"
    }
}

compiler.cpath
compiler.library_path

use_configure       no

build.target        prod

destroot.destdir    APPS=${destroot}${applications_dir}

minimum_xcodeversions {16 9.0 17 10.0 18 11.0}
