# -*- 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 91906 2012-04-13 04:18:25Z jmr@macports.org $

PortSystem      1.0

name            sword
version         1.6.2
revision        3
set branch      [join [lrange [split ${version} .] 0 1] .]
categories      textproc
maintainers     nomaintainer
license         GPL-2
description     cross-platform API/library for Bible software
long_description    The SWORD Project is an open source, cross-platform \
                    (Linux, Windows, Solaris, etc.) API/library for \
                    Bible software with a constantly growing list of \
                    front-ends (GUI, textmode, web-based, etc.) and a \
                    library of over 200 text modules.
homepage        http://www.crosswire.org/${name}/index.jsp
master_sites    http://www.crosswire.org/ftpmirror/pub/${name}/source/v${branch}/
checksums       md5     a7dc4456e20e915fec46d774b690e305 \
                sha1    d4f3b924ba6f78b436a33d4819c76f766e4551f8 \
                rmd160  e85230c007782c526157a5650f3e5c1c27b60ea6
platforms       darwin

depends_build   port:autoconf \
                port:automake \
                port:libtool \
                port:pkgconfig
depends_lib     port:curl \
                port:icu \
                port:openssl \
                port:zlib

# fails to build with clang, probably incorrect code
# ../include/multimapwdef.h:22:7: error: use of undeclared identifier 'find'
# llvm-gcc-4.2 actually hangs
if {${configure.compiler} == "clang" || ${configure.compiler} == "llvm-gcc-4.2"} {
    configure.compiler gcc-4.2
    if {![file executable ${configure.cc}]} {
        depends_build-append port:apple-gcc42
        configure.compiler apple-gcc-4.2
    }
}

pre-configure {
    system "cd ${worksrcpath} && env LTIZE=${prefix}/bin/glibtoolize ./autogen.sh"
}
configure.args  --with-zlib --with-conf --with-curl \
                --with-icu --without-clucene

use_parallel_build yes

destroot.keepdirs ${destroot}${prefix}/share/${name}/mods.d \
                  ${destroot}${prefix}/share/${name}/modules
post-destroot {
    xinstall -d -m 0755 ${destroot}${prefix}/share/${name}/mods.d
    xinstall -d -m 0755 ${destroot}${prefix}/share/${name}/modules

    xinstall -d -m 0755 ${destroot}${prefix}/share/doc/${name}
    xinstall -m 0644 -W ${worksrcpath} README INSTALL LICENSE ${destroot}${prefix}/share/doc/${name}
    copy ${worksrcpath}/samples ${destroot}${prefix}/share/doc/${name}/
    delete ${destroot}${prefix}/share/${name}/mods.d/globals.conf
    move ${destroot}${prefix}/etc/sword.conf ${destroot}${prefix}/etc/sword.conf.sample
}

post-activate {
    if {![file exists ${prefix}/share/${name}/mods.d/globals.conf]} {
        copy ${prefix}/share/doc/${name}/samples/mods.d/globals.conf ${prefix}/share/${name}/mods.d/
    }
    if {![file exists ${prefix}/etc/sword.conf]} {
        copy ${prefix}/etc/sword.conf.sample ${prefix}/etc/sword.conf
    }
}

livecheck.type  regex
livecheck.url   http://www.crosswire.org/sword/software/swordapi.jsp
livecheck.regex {SWORD Engine / API v([0-9\.]+)}
