# -*- 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.1
revision            1
set major_vers      [join [lrange [split ${version} .] 0 1] .]
platforms           darwin
# 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  ff7e2c46d0c03440c361969459aa869a0cd57a52 \
                    sha256  c127974d0242576cf47061b20aa9c86d17be0d6aa9687f6ec9835de67be7bb6f \
                    size    3803356

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.
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 "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
    }
}

# Note: the port maintainer has no access to an i386 host, and cannot
# debug problems on one.
if {${build_arch} eq "i386" || ${build_arch} eq "ppc"} {
    patchfiles-append  patch-configure-darwin32.diff
}

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