# -*- 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
revision                1
categories              devel
license                 zlib
platforms               darwin macosx

maintainers             nomaintainer
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"
}

pre-patch {
    reinplace "s/\r$//" ${worksrcpath}/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm
}

# fix missing SEvent.MouseInput Shift and Control values
patchfiles-append       patch-r5869.diff

# fix an errant typecast in one file, but not on 10.9
if {${os.platform} eq "darwin" && ${os.major} != 13 } {
patchfiles-append       patch-r5690.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

# port builds again in destroot phase - no need to build twice
build                   {}

# fix build with Xcode 10
if {${os.platform} eq "darwin" && ([vercmp $xcodeversion 10.0] > 0)} {
    destroot.pre_args       -derivedDataPath ./DerivedData
    xcode.scheme            ${xcode.target}
}

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}${frameworks_dir}/IrrFramework.framework/Versions/A/Headers
	}

    # add  traditional paths for software that expects to find irrlicht in the headers & libs folders
    ln -s ${frameworks_dir}/IrrFramework.framework/Versions/A/Headers ${destroot}${prefix}/include/irrlicht
    ln -s ${frameworks_dir}/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

}