# -*- 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
PortGroup               xcode 1.0

name                    irrlicht
version                 1.8.4
categories              devel
license                 zlib
platforms               darwin macosx

maintainers             {kencu @kencu} openmaintainer
description             lightening fast realtime 3D game engine
long_description        ${description}
homepage                http://irrlicht.sourceforge.net/

set branch              [join [lrange [split ${version} .] 0 1] .]
master_sites            sourceforge:project/irrlicht/Irrlicht%20SDK/${branch}/${version}/

checksums               sha256  f42b280bc608e545b820206fe2a999c55f290de5c7509a02bdbeeccc1bf9e433 \
                        rmd160  275eb79193a330b3924166e9cac8d74d37990256

use_zip                 yes

# fix build on case-sensitive file systems
# can change this to a simple move command once base is updated
post-extract {
    system "mv ${worksrcpath}/source/Irrlicht/MacOSX/irrFramework-Info.plist ${worksrcpath}/source/Irrlicht/MacOSX/IrrFramework-Info.plist"
}

# fix an errant typecast in one file, but not on 10.9
if {${os.platform} eq "darwin" && ${os.major} != 13 } {
patchfiles-append       patch-irrlicht-cirrdevice.diff
}

# patch out test to exclude older zlib versions that fails on some mac systems like 10.6
patchfiles-append       patch-pngpriv-zlib-test.diff

xcode.project           ./source/Irrlicht/MacOSX/MacOSX.xcodeproj
xcode.configuration     Release
xcode.destroot.type     framework
xcode.target            IrrFramework

post-destroot {
    # the xcode project does not install all the include files
    set flist [glob ${worksrcpath}/include/*.h]
    foreach f $flist {
        file copy -force $f ${destroot}${prefix}/Library/Frameworks/IrrFramework.framework/Versions/A/Headers
	}

    # add  traditional paths for software that expects to find irrlicht in the headers & libs folders
    ln -s ${prefix}/Library/Frameworks/IrrFramework.framework/Versions/A/Headers ${destroot}${prefix}/include/irrlicht
    ln -s ${prefix}/Library/Frameworks/IrrFramework.framework/Versions/A/IrrFramework ${destroot}${prefix}/lib/libIrrlicht.dylib

    # copy in documentation
    xinstall -d ${destroot}${prefix}/share/${name}
    copy ${worksrcpath}/doc ${destroot}${prefix}/share/${name}/
    delete ${destroot}${prefix}/share/${name}/doc/docu

}