# -*- 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               xcode 1.0
PortGroup               github 1.0

github.setup            JohnCoates Aerial 3.2.3 v

categories              aqua
license                 MIT
platforms               macosx
maintainers             {danchr @danchr} openmaintainer

description             Apple TV Aerial Screensaver for Mac

long_description        Aerial is a Mac screensaver based on the new \
                        Apple TV screensaver that displays the Aerial \
                        movies Apple shot over New York, San \
                        Francisco, Hawaii, China, etc.

github.tarball_from     archive

# OAuthSwift is used a Git submodule and not included in the archive
distfiles-append        OAuthSwift${extract.suffix}:OAuthSwift
master_sites-append \
                        https://github.com/OAuthSwift/OAuthSwift/archive/refs/tags/2.0.0${extract.suffix}?dummy=:OAuthSwift

checksums           [lindex ${distfiles} 0] \
                    rmd160  4187c85fd4ec3c4fdee7f7921a9b23b34274b676 \
                    sha256  665ed295a44c6c301c76ab5e9993adac2a79d8d44b970c557edd8b637dbbb420 \
                    size    1323983 \
                    OAuthSwift.tar.gz \
                    rmd160  62f8add3f3f305e26a9cd4b423a3375dd27fb2ab \
                    sha256  1f4c4bfd9057d1b305d70fd7c4fe36520bb62a4bbe1842dffc513dd4a7f3d46b \
                    size    1221906

patchfiles          patch-apisecrets.diff

# although the binary works on 10.9 and later, it doesn't build on
# anything earlier than 10.15
if {${os.major} == 19} {
    patchfiles-append  patch-tintconfiguration.diff
} elseif {${os.major} < 19} {
    known_fail         yes

    pre-fetch {
        ui_error "${name} ${version} cannot build on macOS 10.14 and earlier."
        return -code error "incompatible macOS version"
    }
}

if {[vercmp $xcodeversion 12.0] < 0} {
    patchfiles-append  patch-explicit-self.diff
}

post-extract {
    delete ${worksrcpath}/Extern/OAuthSwift
    ln -s ${workpath}/OAuthSwift-2.0.0 ${worksrcpath}/Extern/OAuthSwift
}

# this port installs a symlink into "/Library/Screen Savers"
destroot.violate_mtree  yes

set screen_saver_dir    "/Library/Screen Savers"

# build settings
xcode.scheme            Aerial
xcode.configuration     Release
xcode.build.settings-append \
                        SDKROOT=macosx \
                        DEVELOPMENT_TEAM= \
                        CODE_SIGN_IDENTITY= \
                        CODE_SIGNING_REQUIRED=NO
build.pre_args-append   -derivedDataPath ${workpath}/derived-data

destroot {
    xinstall -d "${destroot}${prefix}${screen_saver_dir}"
    xinstall -d "${destroot}${screen_saver_dir}"

    file copy ${worksrcpath}/build/${xcode.configuration}/${name}.saver "${destroot}${prefix}${screen_saver_dir}"
    ln -s "${prefix}${screen_saver_dir}/${name}.saver" "${destroot}${screen_saver_dir}"
}
