# -*- 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
PortGroup           ocaml 1.1

name                ocaml-dune
github.setup        ocaml dune 3.14.0
categories          ocaml devel
license             MIT
maintainers         {landonf @landonf} openmaintainer

description         Composable build system for OCaml
long_description    Dune is a build system for OCaml and Reason.

checksums           rmd160  7784eb82f95314e2366f44de43832beade706d4a \
                    sha256  6307ba1bc47946f8d437153cb1a5e8145e47aedce26af4064a7cd0af7a439cce \
                    size    2936923
github.tarball_from archive

if { ${subport} eq ${name} } {
    depends_lib         port:ocaml-findlib
    configure.pre_args
    configure.args      --bindir ${prefix}/bin \
                        --datadir ${prefix}/share/${name} \
                        --docdir ${prefix}/share/doc \
                        --etcdir ${prefix}/etc \
                        --libdir ${ocaml.package_dir} \
                        --mandir ${prefix}/share/man \
                        --sbindir ${prefix}/sbin

    # See: https://github.com/ocaml/dune/issues/8941
    if {${os.major} < 11} {
        build.cmd-prepend \
                        DUNE_CONFIG__COPY_FILE=portable
    }
    build.target        release
}

# See: https://trac.macports.org/ticket/68463
# Fix suggested by upstream: https://github.com/ocaml/dune/issues/8941
patchfiles-append       patch-copyfile_stubs.c-define-COPYFILE_CLONE.diff

subport ocaml-dune-configurator {
    # https://github.com/ocaml/dune/issues/6156
    post-extract {
        file delete -force ${worksrcpath}/vendor
    }
    ocaml.build_type    dune
    depends_lib-append  port:ocaml-csexp
}

subport ocaml-dune-build-info {
    ocaml.build_type    dune
}

subport ocaml-xdg {
    ocaml.build_type    dune
}
