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

github.setup        libimobiledevice idevicerestore 1.0.0
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            2

categories          devel

license             LGPL-3
maintainers         {i0ntempest @i0ntempest} openmaintainer

description         A command-line application to restore firmware files to iOS devices.

long_description    The idevicerestore application is a full reimplementation of all granular steps which \
                    are performed during the restore of a firmware to a device. In general, upgrades and \
                    downgrades are possible, however subject to availability of SHSH blobs from Apple for \
                    signing the firmare files. Some key features are:\
                    \n* Restore: Update firmware on iOS devices\
                    \n* Firmware: Use official IPSW firmware archive file or a directory as source\
                    \n* Update: Allows updating the device by default or erasing all data\
                    \n* Download: On demand download of latest available firmware for a device\
                    \n* Cache: Downloaded firmware files are cached locally\
                    \n* Custom Firmware: Restore custom firmware files (requires bootrom exploit)\
                    \n* Baseband: Allows you to skip NOR/Baseband upgrade\
                    \n* SHSH: Fetch TSS records and save them as ".shsh" files\
                    \n* DFU: Put devices in pwned DFU mode (limera1n devices only)\
                    \n* AP Ticket: Use custom AP ticket from a file\
                    \n* Cross-Platform: Tested on Linux, macOS, Windows and Android platforms\
                    \n* History: Developed since 2010

homepage            https://www.libimobiledevice.org/

checksums           rmd160  f774ac598099e965bf4e9dcad53078e6dab66479 \
                    sha256  76ee2570745f9e876f89acf82ad91edf6e9083e08ceea429985a480cae1ddd67 \
                    size    106889

if {${subport} eq ${name}} {
    patchfiles          patch-postrelease-fixes.diff
}

depends_build-append \
                    port:autoconf \
                    port:automake \
                    port:libtool \
                    port:pkgconfig

depends_lib-append  path:lib/pkgconfig/libusb-1.0.pc:libusb \
                    port:curl \
                    port:libimobiledevice \
                    port:libirecovery \
                    port:libplist \
                    port:libzip \
                    port:readline \
                    port:zlib

configure.cmd       ./autogen.sh

subport idevicerestore-devel {
    github.setup    libimobiledevice idevicerestore 74e3bd9286d16fc1290abde061ee00831d5b36f8
    github.tarball_from archive
    version         20251123
    revision        0

    checksums       rmd160  f2d117810a893659c6ff65c70ab6c680716de12a \
                    sha256  cf1c2fdeca346d3d36348d0e6347978e68eca066d0610c1dda75d56478057656 \
                    size    122940

    depends_lib-replace port:libimobiledevice \
                        port:libimobiledevice-devel
    depends_lib-replace port:libplist port:libplist-devel
    depends_lib-replace port:libirecovery port:libirecovery-devel
    depends_lib-replace port:libtatsu port:libtatsu-devel

    conflicts       idevicerestore

    post-extract {
        system -W ${worksrcpath} "echo ${version} > .tarball-version"
    }

    # Consider applying to both ports when a new official release is made
    # See: https://trac.macports.org/wiki/WimplicitFunctionDeclaration#strchr
    configure.checks.implicit_function_declaration.whitelist-append strchr

    post-destroot {
        xinstall -d ${destroot}${prefix}/share/doc/${name}
        xinstall -m 644 -W ${worksrcpath} COPYING AUTHORS ${destroot}${prefix}/share/doc/${name}/
    }

    livecheck.url   ${github.homepage}/commits/${github.livecheck.branch}.atom
}

if {${subport} eq ${name}} {
    conflicts       idevicerestore-devel
}
