# -*- 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.4.1
revision            0
set major_vers      [join [lrange [split ${version} .] 0 1] .]
# Note that ppc, ppc64 and i386 on Mac are no longer supported by upstream
# We may have to remove support at some point.
supported_archs     i386 x86_64 arm64 ppc ppc64
maintainers         {pmetzger @pmetzger} openmaintainer
categories          lang ocaml
license             LGPL
homepage            https://ocaml.org
master_sites        http://caml.inria.fr/pub/distrib/ocaml-${major_vers}/

checksums           rmd160  a77663dda03d6344e9d7edc37062b00f8ff48880 \
                    sha256  b1e297adc186635540758eb064c7fab025598ae4436f3b9767e5025188b4e0ab \
                    size    4483716

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}

# Note: the port maintainer has no access to older versions of MacOS,
# debug problems with these patches.
# OCaml 5's configure has no darwin ppc/i386 case, so it falls back to a
# bytecode-only build (arch=none) on those targets. The old native-ppc and
# 32-bit-darwin shared-library configure patches no longer apply and are not
# needed; only the strnlen shim for pre-10.7 libc remains relevant.
if {${os.major} < 11} {
    # need to add strnlen patch as not in library
    patchfiles-append  patch-strnlen-socketaddr.diff

    if {${build_arch} eq "i386" || ${build_arch} eq "x86_64"} {
    # compiler selection pulls in clang-3.4 on 10.6 and less
    # and this compiler is needed for this port to run once installed
    # so force this compiler and require it at runtime
    compiler.whitelist     macports-clang-3.4
    depends_run-append     port:clang-3.4
    }
}

# 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

# Building.
# OCaml 5 has no native compiler (ocamlopt) on 32-bit platforms (i386) nor on
# ppc/ppc64, so build bytecode-only (world) instead of world.opt there.
if {${build_arch} in [list i386 ppc 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>, "
