# -*- 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               github 1.0

github.setup            mmp pbrt-v2 e6f6334f3c26ca29eba2b27af4e60fec9fdc7a8d
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from     tarball
name                    pbrt2
version                 20190104
revision                4
homepage                https://www.pbrt.org

categories              graphics
license                 BSD
maintainers             {mcalhoun @MarcusCalhoun-Lopez} openmaintainer

description             a photorealistic rendering system
long_description        Source code for pbrt, the renderer described in the second edition of \
                        \"Physically Based Rendering: From Theory To Implementation\", \
                        by Matt Pharr, Wenzel Jakob, and Greg Humphreys.

checksums               rmd160  5640cbb10226d83f34335bcfb3e1592aafcfb6eb \
                        sha256  ccd8084fff96eaac71a6d24314a391a22fd218d84dea2adaa1c6ccd04968bca3 \
                        size    14349299

conflicts               pbrt3

use_configure           no

depends_build-append    path:bin/pkg-config:pkgconfig

depends_lib-append      port:openexr \
                        port:tiff

patchfiles-append       patch-Makefile.diff \
                        null-conversion.patch

# openexr headers require C++11
compiler.cxx_standard   2011
configure.cxxflags-append \
                        -std=c++11

build.dir               ${worksrcpath}/src
build.target
build.pre_args-append                                           \
    CC="${configure.cc} ${configure.cflags}"                    \
    CXX="${configure.cxx} ${configure.cxxflags}"                \
    EXR_INCLUDES="\$(pkg-config OpenEXR --cflags-only-I)"       \
    EXRLIBS="\$(pkg-config OpenEXR --libs)"                     \
    HAVE_LIBTIFF=1                                              \
    TIFF_INCLUDES="\$(pkg-config libtiff-4 --cflags-only-I)"    \
    TIFF_LIBDIR="\$(pkg-config libtiff-4 --libs-only-L)"        \
    OPT=

post-patch {
    reinplace "s|__PREFIX__|${prefix}|g" ${worksrcpath}/src/Makefile

    # Disable silent rules
    reinplace {/^\t@echo/d;s/^\t@/\t/} ${build.dir}/Makefile
}

pre-configure {
    build.pre_args-append MARCH="[get_canonical_archflags cc]"
}

destroot {
    xinstall -m 0755 {*}[glob ${worksrcpath}/src/bin/*]        ${destroot}${prefix}/bin
    xinstall -m 0755 {*}[glob ${worksrcpath}/src/objs/*.dylib] ${destroot}${prefix}/lib
    ln -s            libpbrt.2.dylib                           ${destroot}${prefix}/lib/libpbrt.dylib
}

variant universal {}

platform darwin {
    depends_lib-append  port:zlib
}
