# -*- 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 115379 2014-01-01 05:34:31Z jeremyhu@macports.org $

PortSystem          1.0
PortGroup           muniversal 1.0

name                lensfun
version             0.2.8
revision            1
categories          graphics
platforms           darwin
maintainers         gmail.com:julians37
license             GPL-3 LGPL-3

description         Library for fixing lens geometry distortion

long_description    Provides a database of photographic lenses and a library \
                    that allows advanced access to the database including \
                    functions to correct images based on intimate knowledge \
                    of lens characteristics and calibration data.

homepage            http://lensfun.berlios.de/
master_sites        http://download.berlios.de/lensfun/
use_bzip2           yes

checksums           rmd160  527b4ca0e9ce40f514e7340548d0d0635bdc875e \
                    sha256  f88f97fbc78259a2b2edddef295caf50770901107c8469e54bb5e9699faa1a48

depends_build       port:pkgconfig bin:makedep:gccmakedep

depends_lib         path:lib/pkgconfig/glib-2.0.pc:glib2

# Ensure lensfun.pc is created
patchfiles          patch-pkgconfig.diff

# Set the correct library install_name and current_version
patchfiles-append   patch-build-tibs-target-mac-mak.diff
post-patch {
    reinplace "s|@VERSION@|${version}|g" ${worksrcpath}/build/tibs/target/mac.mak
}

# TODO: Simplify once MacPorts 2.3 is released
set cxx_stdlibflags {}
if {[info exists configure.cxx_stdlib] && ${configure.cxx_stdlib} ne {} && [string match *clang* ${configure.cxx}]} {
    set cxx_stdlibflags -stdlib=${configure.cxx_stdlib}
}

configure.args      -v
configure.env       LD="${configure.cxx} ${cxx_stdlibflags}"

platform darwin 8 {
    # lensfun requires make >= 3.81; Tiger comes with 3.80
    depends_build-append port:gmake
    # fix configure script check which is hardcoded to using "make"
    post-extract {
        xinstall -d ${workpath}/bin
        ln -s ${prefix}/bin/gmake ${workpath}/bin/make
    }
    configure.env PATH=${workpath}/bin:$env(PATH)
    # fix build and destroot
    build.cmd ${prefix}/bin/gmake
}

if {[variant_isset universal]} {
    foreach arch ${configure.universal_archs} {
        set merger_host($arch) ""
    }
    set merger_configure_args(ppc64)  "--target=mac.powerpc64.G5 --vectorization=''"
    set merger_configure_args(ppc)    "--target=mac.powerpc.powerpc --vectorization=''"
    set merger_configure_args(i386)   "--target=mac.x86.i686"
    set merger_configure_args(x86_64) "--target=mac.x86_64.generic"
} elseif {${build_arch} eq "ppc64"} {
    configure.args-append --target=mac.powerpc64.G5 --vectorization=''
} elseif {${build_arch} eq "ppc"} {
    configure.args-append --target=mac.powerpc.powerpc --vectorization=''
} elseif {${build_arch} eq "i386"} {
    configure.args-append --target=mac.x86.i686
} elseif {${build_arch} eq "x86_64"} {
    configure.args-append --target=mac.x86_64.generic
}

configure.universal_args-delete --disable-dependency-tracking

build.args          V=1 GCC.LD="${configure.cxx} ${cxx_stdlibflags}"

livecheck.type      regex
livecheck.url       http://developer.berlios.de/project/showfiles.php?group_id=9034
livecheck.regex     "lensfun-(\\d+(?:\\.\\d+)*).tar"
