# -*- 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           conflicts_build 1.0
PortGroup           github 1.0
PortGroup           muniversal 1.0
PortGroup           boost 1.0

# From vfe/unix/syspovconfig.h: "With `boost/tr1/*.hpp` unavailable, we're
# currently blindly relying on the compiler to be compliant with C++11."
compiler.cxx_standard   2011
configure.cxxflags-append -std=c++11

github.setup        POV-Ray povray 3.7.0.8 v
revision            5
checksums           rmd160  5d3a261f07187bd799ebc946a25c4e9725674209 \
                    sha256  e86427f83b9bc356e6694bd053eb23b310aa0f942ac9215860c86f0035865ce2 \
                    size    52885333

set branch          [join [lrange [split ${version} .] 0 1] .]
categories          graphics
platforms           darwin
license             AGPL-3
maintainers         nomaintainer

description         Persistence Of Vision RAYtracer

long_description    POVRAY is a free and popular Ray Tracer available for \
                    many platforms (including UNIX). This is a port of the \
                    UNIX version, not the graphical macOS version.

homepage            http://www.povray.org/

depends_build       port:autoconf \
                    port:automake \
                    port:pkgconfig

depends_lib         path:include/turbojpeg.h:libjpeg-turbo \
                    port:libpng \
                    port:libsdl \
                    port:openexr2 \
                    port:tiff \
                    port:xorg-libsm \
                    port:xpm \
                    port:zlib

pre-configure {
    # There is no pre-generated configure script included in the download.
    # https://github.com/POV-Ray/povray/issues/1
    system -W ${worksrcpath}/unix "./prebuild.sh"

    # ../version:1:1: error: expected unqualified-id
    # https://github.com/POV-Ray/povray/issues/403
    delete          ${worksrcpath}/VERSION \
                    ${worksrcpath}/libraries/tiff/VERSION \
                    ${worksrcpath}/unix/VERSION
}

conflicts_build-append \
                    openexr
configure.pkg_config_path-append \
                    ${prefix}/libexec/openexr2/lib/pkgconfig

configure.env       "COMPILED_BY=MacPorts <https://www.macports.org/>"
configure.libs      -lboost_system-mt -lboost_thread-mt
configure.args      --disable-optimiz-arch \
                    --with-boost=[boost::install_area] \
                    --with-boost-thread \
                    --with-libjpeg=${prefix}/lib \
                    --with-libpng=${prefix}/lib \
                    --with-libsdl=${prefix}/lib \
                    --with-libtiff=${prefix}/lib \
                    --with-openexr=${prefix}/libexec/openexr2/lib \
                    --with-zlib=${prefix}/lib

set conf_files      {povray.conf povray.ini}

post-destroot {
    foreach f ${conf_files} {
        move ${destroot}${prefix}/etc/povray/${branch}/${f} \
             ${destroot}${prefix}/etc/povray/${branch}/${f}.sample
    }
}

post-activate {
    foreach f ${conf_files} {
        if {![file exists ${prefix}/etc/povray/${branch}/${f}]} {
            copy ${prefix}/etc/povray/${branch}/${f}.sample \
                 ${prefix}/etc/povray/${branch}/${f}
        }
    }
}

test.run            yes
test.target         check

# Unable to cross compile, so we need to be able to run the built code
merger_must_run_binaries    yes

variant native description {Enable CPU-specific optimizations} {
    configure.args-delete --disable-optimiz-arch
}

platform darwin {
    patchfiles-append   patch-lseek64.diff \
                        patch-vfe-uint.diff

    set merger_host(x86_64) x86_64-apple-${os.platform}${os.major}
    set merger_host(i386) i686-apple-${os.platform}${os.major}
    set merger_host(ppc64) powerpc64-apple-${os.platform}${os.major}
    set merger_host(ppc) powerpc-apple-${os.platform}${os.major}
    foreach arch ${configure.universal_archs} {
        if {[info exists merger_host(${arch})]} {
            set merger_configure_args(${arch}) --build=$merger_host(${arch})
        }
    }
    if {(!${universal_possible} || ![variant_isset universal]) && [info exists merger_configure_args(${configure.build_arch})]} {
        configure.args-append --host=$merger_host(${configure.build_arch}) $merger_configure_args(${configure.build_arch})
    }
}

github.livecheck.regex  {([0-9.]+)}
