# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           github 1.0
PortGroup           xcode 1.0

github.setup        lwouis fat-drive-sorter 1.4.0 v
github.tarball_from archive
name                FatDriveSorter
revision            0
categories          sysutils aqua
maintainers         {i0ntempest @i0ntempest} openmaintainer
license             GPL-3

description         Actually sort files on your FAT drives
long_description    FatDriveSorter is a graphical front end for fatsort and helps you \
                    actually sort files on your FAT12, FAT16, FAT32, and exFAT drives.

checksums           rmd160  1fcfa7ee3f6c354f5a8ef05ba74ffd78b4f4c03a \
                    sha256  0694aa8679aa9d8506623848743afb9c272550794657591cb34edf462db8e71e \
                    size    62261127

depends_run-append  port:fatsort

build.pre_args-append \
                    -workspace ${github.project}.xcworkspace \
                    -derivedDataPath ./DerivedData
xcode.target        ${github.project}
xcode.scheme        Release
xcode.configuration Release

# Possible Swift v6 bug: enabling optimization causes fatsort to return too many arguments
xcode.build.settings-append \
                    SWIFT_OPTIMIZATION_LEVEL=-Onone

if {${os.major} >= 22} {
    xcode.build.settings-append \
        CODE_SIGN_IDENTITY=-
} else {
    xcode.build.settings-append \
        CODE_SIGN_IDENTITY= CODE_SIGNING_REQUIRED=NO
}

# Use fatsort from MacPorts
patchfiles-append   patch-use_MP_fatsort.diff

post-patch {
    reinplace -E "s|@@PREFIX@@|${prefix}|g" ${worksrcpath}/${github.project}.xcodeproj/project.pbxproj
    reinplace -E "s|scripts/codesign/codesign_sparkle_embedded_apps.sh||g" ${worksrcpath}/${github.project}.xcodeproj/project.pbxproj
    # Disable Sparkle without messing with xib files
    system -W ${worksrcpath} "/usr/libexec/PlistBuddy -c \"Delete :SUFeedURL\" Info.plist"
    system -W ${worksrcpath} "/usr/libexec/PlistBuddy -c \"Set :SUEnableAutomaticChecks false\" Info.plist"
    # Remove AppCenter FeedbackToken (Release tarball does not include a token)
    system -W ${worksrcpath} "/usr/libexec/PlistBuddy -c \"Delete :FeedbackToken\" Info.plist"
    # Manually set version
    system -W ${worksrcpath} "/usr/libexec/PlistBuddy -c \"Set :CFBundleVersion ${version}\" Info.plist"
    system -W ${worksrcpath} "/usr/libexec/PlistBuddy -c \"Set :CFBundleShortVersionString ${version}\" Info.plist"
}

destroot {
    file copy ${worksrcpath}/build/${xcode.configuration}/${name}.app ${destroot}${applications_dir}
}
