# -*- 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.
# Note that ocaml-camlp4 may no longer be available at all in ocaml 4.09 and
# after; all ports depending on camlp4 need to be obsoleted.
#
# When ocaml is next updated, please update lablgtk2 as well

name                ocaml
epoch               1
version             4.14.3
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  bd17ca297ba10dfff562efe2ac7ca32d6f3881d1 \
                    sha256  a5d583b8fbab9ea7bf6cf972ef9c38e7fedacbff6db7a34e3105115d343eb069 \
                    size    3811944

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.

use_xz              yes

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

if {${os.major} < 11} {
    # need to add strnlen patch as not in library
    patchfiles-append  patch-strnlen-socketaddr.diff \
                       patch-configure-darwin-ppc.diff
}

if {${build_arch} eq "i386" || ${build_arch} eq "ppc"} {
    patchfiles-append  patch-configure-darwin32.diff
}

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

# 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

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

# powerpc is supported only in bytecode atm
if {${build_arch} eq "ppc" || ${build_arch} eq "ppc64"} {
    build.target    world
    } else {
    build.target    world.opt
}

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>, "
