# $Id: Portfile 79338 2011-06-09 19:51:57Z and.damore@macports.org $

PortSystem          1.0
name                bitcoin
categories          finance crypto
version             0.3.22
platforms           darwin
license             MIT
maintainers         singingwolfboy openmaintainer
description         a peer-to-peer digital currency
long_description    \
    Bitcoin is a peer-to-peer digital currency. Peer-to-peer (P2P) means that \
    there is no central authority to issue new money or keep track of \
    transactions. Instead, these tasks are managed collectively by the nodes \
    of the network.

homepage            http://www.bitcoin.org/
master_sites        sourceforge
distname            ${name}-${version}-macosx
use_zip             yes
checksums           md5     5daa8d577e5ee081a4eae7cf4845f76c \
                    sha1    5798efd33d38d530428d22aa4edf37e99731072e \
                    rmd160  094c90358ed24be23feb66db6c68c6525e6234fc

depends_lib         port:boost \
                    port:openssl \
                    port:db48 \
                    port:wxWidgets-devel \
                    port:miniupnpc

supported_archs     x86_64
universal_variant   no
worksrcdir          ${name}-${version}/src
set makefile ${worksrcpath}/makefile.osx
configure {
    reinplace "s|^DEPSDIR=.*$|DEPSDIR=${prefix}|" ${makefile}
    reinplace "s|-I\"\$\(DEPSDIR\)\/include\"|-I${prefix}/include -I${prefix}/include/db48|" ${makefile}
    reinplace "s|lib/libdb_cxx-4.8.a|lib/db48/libdb_cxx-4.8.dylib|" ${makefile}
    reinplace "s|lib/libboost_thread.a|lib/libboost_thread-mt.dylib|" ${makefile}
    reinplace "s|\\\.a|.dylib|" ${makefile}
    reinplace "s|/miniupnpc/|/lib/|" ${makefile}

    # The QuickTime framework isn't actually needed, and it doesn't exist for
    # x86_64, but wx-config --libs spits it out anyway, so we'll filter it out
    # with sed.
    reinplace "s|wx-config --libs --static|wx-config --libs \\\| sed -e \"s/-framework QuickTime//\"|g" ${makefile}

    # Building with i386 support seems to make everything explode, so we'll 
    # remove it.
    reinplace "s|-arch i386||" ${makefile}
}
build.args          -f ${makefile}
build.target-append bitcoind
destroot {
    xinstall -m 755 -W ${worksrcpath} \
        bitcoin bitcoind ${destroot}${prefix}/bin

    set docdir ${destroot}${prefix}/share/doc/${name}
    xinstall -d ${docdir}
    xinstall -m 444 -W ${worksrcpath}/.. readme.txt license.txt ${docdir}
 
    file copy ${worksrcpath}/../Bitcoin.app ${destroot}${applications_dir}/
}

# Tweak the Sourceforge livechecking
livecheck.regex     {/bitcoin-(\d+(?:\.\w+)+)/README}
