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

perl5.branches      5.28 5.30 5.32 5.34
perl5.link_binaries no
perl5.setup         PDL 2.084 ../../authors/id/E/ET/ETJ
revision            2
license             {Artistic-1 GPL}
maintainers         {peculier.com:mgrimes @mvgrimes} openmaintainer
description         Perl Data Language - scientific computing capability for perl
long_description    The perlDL project aims to turn perl into an efficient numerical \
                    language for scientific computing. The PDL module gives standard perl \
                    the ability to COMPACTLY store and SPEEDILY manipulate the large \
                    N-dimensional data sets which are the bread and butter of scientific \
                    computing.

platforms           darwin

checksums           rmd160  cfe3e3cbb1e6f3552604a7a86e27464551026ab9 \
                    sha256  96256439f3a2501ffa93b3cc7c8cadbf91aabf6cb5f874624917833656006468 \
                    size    3064351

#
# support options
#
# plotting support using pgplot (PDL::Graphics::PGPLOT) is always enabled
# plotting support using plplot (PDL::Graphics::PLplot) has been removed from the PDL distribution, available as a separate module if desired
# plotting support using gnuplot is available via separate module PDL::Graphics::Gnuplot
# 3D plotting support (PDL::Graphics::TriD) is disabled by default due to dependency issues, use +trid to enable
# hdf4 support (PDL::IO::HDF) is enabled by default, use -hdf4 to disable (#46304)
# hdf5 support is available via separate module PDL::IO::HDF5
# image io support using the gd library (PDL::IO::GD) is enabled by default, use -gd to disable
# projection transform support using the Proj library (PDL::GIS::Proj) is always enabled
# coordinate transform support using the Proj library (PDL::Transform::Proj4) is always enabled
# fft support via PDL::FFT and PDL::Slatec::fft is always enabled
# alternate fft support using the fftw library is available via separate module PDL::FFTW3
#

variant gd description {Enable support for the GD image library} {}
variant hdf4 description {Enable support for the HDF4 SD library} {}
variant trid description {Enable support for 3D plotting} {}

default_variants    +hdf4 +gd

if {${perl5.major} != ""} {
    PortGroup       compiler_blacklist_versions 1.0

    # see https://trac.macports.org/ticket/67506
    # clang: error: unable to execute command: Segmentation fault: 11
    compiler.blacklist-append {clang < 1200}

    depends_build-append \
                    port:p${perl5.major}-devel-checklib \
                    port:p${perl5.major}-extutils-depends \
                    port:p${perl5.major}-extutils-makemaker \
                    port:p${perl5.major}-file-path \
                    port:p${perl5.major}-test-exception \
                    port:p${perl5.major}-test-warn

    depends_lib-append \
                    port:freeglut \
                    port:gsl \
                    path:include/turbojpeg.h:libjpeg-turbo \
                    port:netpbm \
                    port:p${perl5.major}-alien-hdf4 \
                    port:p${perl5.major}-alien-proj \
                    port:p${perl5.major}-astro-fits-header \
                    port:p${perl5.major}-data-dumper \
                    port:p${perl5.major}-devel-repl \
                    port:p${perl5.major}-extutils-f77 \
                    port:p${perl5.major}-file-map \
                    port:p${perl5.major}-file-which \
                    port:p${perl5.major}-filter \
                    port:p${perl5.major}-filter-simple \
                    port:p${perl5.major}-inline \
                    port:p${perl5.major}-inline-c \
                    port:p${perl5.major}-math-complex \
                    port:p${perl5.major}-pgplot \
                    port:p${perl5.major}-term-readkey \
                    port:p${perl5.major}-term-readline-gnu \
                    port:p${perl5.major}-text-balanced \
                    port:pgplot \
                    port:slatec \
                    port:xorg-libXi \
                    port:xorg-libXmu

    # our p5-pod-parser is only required on perl 5.32+
    if {${perl5.major} > 5.30} {
        depends_lib-append \
                    port:p${perl5.major}-pod-parser
    }

    set enable_gd     0
    set enable_hdf4   0
    set enable_trid   0

    if {[variant_isset gd]} {
        set enable_gd 1
        depends_lib-append \
                    port:p${perl5.major}-gd
    }

    if {[variant_isset hdf4]} {
        set enable_hdf4 1
        depends_lib-append \
                    port:hdf4
    }

    if {[variant_isset trid]} {
        set enable_trid 1
        depends_lib-append \
                    port:p${perl5.major}-opengl \
                    port:p${perl5.major}-opengl-glut
    }

    # pgplot is not universal
    universal_variant no
    use_parallel_build no

    patchfiles      patch-perldl.conf.diff \
                    patch-implicit-declaration-gsl_set_error_handler_off.diff

    post-patch {
        reinplace "s|^#!.*|#!${perl5.bin}|" ${worksrcpath}/Perldl2/pdl2
        reinplace "s|__WITH_GD__|${enable_gd}|" ${worksrcpath}/perldl.conf
        reinplace "s|__WITH_HDF__|${enable_hdf4}|" ${worksrcpath}/perldl.conf
   }

   post-build {
       # Create the pdldoc.db file for the help system
       exec ${perl5.bin} -I ${worksrcpath}/blib/arch \
           -I ${worksrcpath}/blib/lib \
           ${worksrcpath}/Doc/scantree.pl ${worksrcpath}/blib/lib \
           ${worksrcpath}/pdldoc.db \
           ${worksrcpath}/blib/lib/PDL/Index.pod \
           >/dev/null 2>/dev/null

       # Rewrite the paths in the pdldoc.db file. scantree will have the
       # ${worksrcpath}/blib/lib paths, we need ${perl5.archlib}.
       exec ${perl5.bin} ${filespath}/fix-pdldocdb.pl \
           ${worksrcpath}/pdldoc.db \
           ${worksrcpath}/blib/lib/PDL/pdldoc.db \
           "${worksrcpath}/blib/lib" \
           "${perl5.archlib}"
   }
}
