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

# When updating ocaml, also update ocaml-camlp4 and camlp5 to compatible
# versions (c.f. #26769, #20219, #18292) or increase their revisions to
# rebuild them.

name                ocaml
epoch               1
version             5.5.0
revision            0
set major_vers      [join [lrange [split ${version} .] 0 1] .]
maintainers         {pmetzger @pmetzger} {@barracuda156 macos-powerpc.org:barracuda} \
                    openmaintainer
categories          lang ocaml
license             LGPL
homepage            https://ocaml.org
master_sites        http://caml.inria.fr/pub/distrib/ocaml-${major_vers}/

checksums           rmd160  4b9b1d7f9d48fa867e2c4449633fb5e74e3aed06 \
                    sha256  1a9537c2abda43335cd0af8edbc575bab588a6db68308d7ce8bd9ad80573a477 \
                    size    6609018

description         Compiler and libraries for the OCaml programming language
long_description    OCaml is an industrial strength programming language \
                    in the ML family, supporting functional, imperative \
                    and object-oriented styles.

universal_variant   no

set docdir          ${prefix}/share/doc/${name}

compiler.blacklist  gcc-4.0 *gcc-4.2 {clang < 400}
configure.ccache    no

patch.pre_args-replace  -p0 -p1

patchfiles-append   patch-configure.diff

if {${os.platform} eq "darwin" && ${os.major} < 11} {
    patchfiles-append   patch-strnlen.diff
}

post-patch {
    reinplace "s|static_assert|_Static_assert|g" \
        runtime/bigarray.c runtime/domain.c runtime/extern.c runtime/fiber.c \
        runtime/floats.c runtime/memprof.c runtime/shared_heap.c
}

# OCaml needs the same compiler at runtime:
if {[string match macports-clang-* ${configure.compiler}]} {
    set clang_v [
        string range ${configure.compiler} [
            string length macports-clang-
        ] end
    ]
    depends_build-append    port:clang-${clang_v}
    depends_run-append      port:clang-${clang_v}
} elseif {[string match macports-gcc-* ${configure.compiler}]} {
    set gcc_v [
        string range ${configure.compiler} [
            string length macports-gcc-
        ] end
    ]
    depends_build-append    port:gcc${gcc_v}
    depends_run-append      port:gcc${gcc_v}
}

# see INSTALL.adoc
configure.cc-append {*}${configure.cc_archflags}

# see https://trac.macports.org/wiki/UsingTheRightCompiler
# mimic default values of default_as and default_aspp in configure.ac
# see INSTALL.adoc for PARTIALLD
configure.env-append \
    "AS=${configure.cc} -Wno-trigraphs -c" \
    "ASPP=${configure.cc} -Wno-trigraphs -c" \
    "PARTIALLD=${configure.cc} -Wl,-r"

# Configure.
configure.pre_args  --prefix=${prefix} --mandir=${prefix}/share/man

# Don't bake this into Makefile.config
configure.ldflags-delete    -L${prefix}/lib

# Needed for Rosetta only:
if {${os.arch} eq "i386" && ${configure.build_arch} eq "ppc"} {
    configure.args-append \
                    --enable-imprecise-c99-float-ops
}

build.args-append   V=1

# OCaml 5 has no native compiler (ocamlopt) on 32-bit platforms (i386)
# and ppc/ppc64, so build bytecode-only (world) instead of world.opt there.
if {${configure.build_arch} in [list arm i386 ppc ppc64]} {
    build.target    world
    } else {
    build.target    world.opt
}

platform darwin 8 {
    depends_build-append port:gmake
    build.cmd ${prefix}/bin/gmake
}

post-destroot {
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} Changes LICENSE README.adoc ${destroot}${docdir}
}

test.run            yes
test.target         ocamltest tests

livecheck.type      regex
livecheck.url       https://ocaml.org/releases/
livecheck.regex     "OCaml <\[^>\]+>(\[0-9.\]+)</a>, "
