# -*- 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
# $Id: Portfile 108291 2013-07-17 22:55:36Z cal@macports.org $

PortSystem      1.0
PortGroup       xcode 1.0
PortGroup       github 1.0

github.setup    ridiculousfish HexFiend 2.1.2 v
checksums       rmd160  c36371fb1a54312952601ddf2a35f021af4da6ef \
                sha256  ba78d047b7bb5394ec444cd3b86565b7d4754869544a656f7b6b2fc79eb7f37c

epoch           1
# MEMO: increasing version and setting dist_subdir due to stealth_update, remove them on next version upgrade
revision        1
dist_subdir     ${name}/${version}_1
categories      editors aqua
maintainers     dweber cal openmaintainer
license         BSD

# required to build on < Lion
patchfiles      framework-sources-HFByteArrayEditScript.m.patch
platform darwin 11 {
    patchfiles-delete \
                framework-sources-HFByteArrayEditScript.m.patch
}

long_description \n\
    * Insert, delete, rearrange. Hex Fiend is not limited to in-place changes like some hex editors.\n\
    * Work with huge files. Hex Fiend can handle as big a file as you're able to create. It's been tested on files as \
      large as 118 GB.\n\
    * Small footprint. Hex Fiend does not need to keep your files in memory. You won't dread launching or working with \
       Hex Fiend even on low-RAM machines.\n\
    * Fast. Open a huge file, scroll around, copy and paste, all instantly. Find what you're looking for with fast \
       searching.\n\
    * Smart saving. Hex Fiend knows not to waste time overwriting the parts of your files that haven't changed.\n\
    * Data inspector. Interpret data as integer or floating point, signed or unsigned, big or little endian...\n\
    * Smooth scrolling. No separate pages - scroll like any text document.

if {${subport} eq ${name}} {
    description     HexFiend is a fast and clever hex editor

    post-patch {
        # this is required for builds on 32 bit systems, because NSTag is
        # a signed integer and these values (NSUTF16BigEndianStringEncoding and
        # NSUTF16LittleEndianStringEncoding) both have the MSB set making them
        # not representable in signed 32 bit integers.
        # Applying these on 64 bit systems is safe, too, because the leading
        # 4 bytes will be cut off by a cast.
        reinplace "s/2415919360/-1879047936/g" ${worksrcpath}/English.lproj/MainMenu.xib
        reinplace "s/2483028224/-1811939072/g" ${worksrcpath}/English.lproj/MainMenu.xib
    }

    xcode.target        HexFiend_2
    xcode.configuration Release

    destroot {
        copy "${worksrcpath}/build/Release/Hex Fiend.app" ${destroot}${applications_dir}
        xinstall -d ${destroot}${prefix}/share/doc/${name}
        xinstall -m 644 ${worksrcpath}/License.txt ${destroot}${prefix}/share/doc/${name}
    }
}

subport HexFiend-framework {
    description         The HexFiend Framework is an embeddable Cocoa hex editor component from the HexFiend editor

    xcode.target        HexFiend_Framework
    xcode.configuration Release

    destroot {
        copy "${worksrcpath}/build/Release/HexFiend.framework" ${destroot}${frameworks_dir}
        set framework_lib ${frameworks_dir}/HexFiend.framework/Versions/A/HexFiend
        system "install_name_tool -id ${framework_lib} ${destroot}${framework_lib}"
    }
}
