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

# openat family and fdopendir need legacy-support on < 10.10,
# arc4random_buf on < 10.7.
legacysupport.newest_darwin_requires_legacy 13

name                ocaml-eio
github.setup        ocaml-multicore eio 1.4 v
revision            0
categories          ocaml devel
maintainers         {@barracuda156 macos-powerpc.org:barracuda} openmaintainer
license             ISC
description         Effect-based direct-style IO API
long_description    {*}${description} for OCaml.
use_bzip2           yes
extract.suffix      .tbz
distname            eio-${version}
checksums           rmd160  7221c290f4430e912d3eb3fac01c6203824053b6 \
                    sha256  ba11ad486f492130dbb486f2b3bdc4905643f10016806ddf86e9a34e4346aaa5 \
                    size    316011
github.tarball_from releases

# preadv/pwritev only exist on macOS 11+, ptsname_r on 10.13.4+,
# O_CLOEXEC on 10.7+; provide fallbacks.
patchfiles          patch-old-darwin.diff

if {${os.platform} eq "darwin" && ${os.major} < 14} {
    patchfiles-append \
                    patch-legacy-support.diff

    dune.build.env-append \
                   C_INCLUDE_PATH=${prefix}/include/LegacySupport \
                   CPLUS_INCLUDE_PATH=${prefix}/include/LegacySupport
}

if {${subport} eq ${name}} {
    depends_lib-append \
                    port:ocaml-bigstringaf \
                    port:ocaml-cstruct \
                    port:ocaml-domain-local-await \
                    port:ocaml-fmt \
                    port:ocaml-hmap \
                    port:ocaml-lwt-dllist \
                    port:ocaml-mtime \
                    port:ocaml-optint \
                    port:ocaml-psq
}

subport ocaml-eio_main {
    description     Effect-based direct-style IO mainloop for OCaml

    depends_lib     port:ocaml-eio_posix
}

subport ocaml-eio_posix {
    description     Eio implementation for POSIX systems

    depends_lib     port:ocaml-eio \
                    port:ocaml-fmt \
                    port:ocaml-iomux
}

ocaml.build_type    dune
