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

name            ddrescueview
version         0.4.5
revision        1
categories      sysutils aqua
license         GPL-2
maintainers     {@kamischi web.de:karl-michael.schindler} openmaintainer
description     Graphical viewer for GNU ddrescue log files.

long_description \
                This small tool allows the user to graphically examine ddrescue's log \
                files in a user friendly GUI application. The Main window displays a \
                block grid with each block's color representing the block types it \
                contains. Many people know this type of view from defragmentation \
                programs. The program is written in Object Pascal using the Lazarus IDE.

homepage        https://sourceforge.net/projects/${name}
master_sites    sourceforge:${name}/Test%20builds/v${version}/
distname        ${name}-source-${version}
use_xz          yes

checksums       rmd160  aca84a816122891b4c824f02a27b2cf2da64908b \
                sha256  57383c394e62612ce2a799438b00c6e3c465c31f9ba940e077f624e2e7028465 \
                size    211184

depends_build   port:lazarus port:makeicns

set savedsrcdir ${worksrcpath}
worksrcdir      ${worksrcdir}/source

patchfiles-append \
                patch-deployment_target.patch

set proj_file   ddrescueview.lpi
post-patch {
    reinplace "s|@@DEPLOYMENT_TARGET@@|${macosx_deployment_target}|g" ${proj_file}
    # remove incorrect linux linker options
    if {${os.major} >= 23} {
        # ld segfaults on macOS 15.4 and later and reports unaligned pointer on 14.x
        # fall back to classic linker
        # See https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/41570
        reinplace "s|-z relro --as-needed|-ld_classic|g" ${proj_file}
    } else {
        reinplace "s|-z relro --as-needed||g" ${proj_file}
    }
}

use_configure   no

build.cmd       lazbuild
build.target    ddrescueview.lpi

pre-destroot {
    system -W ${worksrcpath} "makeicns -in ddrescueview.ico -out ddrescueview.icns"
    move ${worksrcpath}/ddrescueview.icns ${worksrcpath}/ddrescueview.app/Contents/Resources/
    delete ${worksrcpath}/ddrescueview.app/Contents/MacOS/ddrescueview
    move ${worksrcpath}/ddrescueview ${worksrcpath}/ddrescueview.app/Contents/MacOS/
    reinplace "s|English|English</string> <key>CFBundleIconFile</key> <string>ddrescueview|g" \
        ${worksrcpath}/ddrescueview.app/Contents/Info.plist
}

destroot {
    move ${worksrcpath}/ddrescueview.app ${destroot}${applications_dir}/
    xinstall -m 755 -d ${destroot}${prefix}/share/doc/ddrescueview
    xinstall -m 644 {*}[glob ${savedsrcdir}/*.txt] ${destroot}${prefix}/share/doc/ddrescueview
}

livecheck.distname ${name}-source
