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

name                algol68g
version             3.12.3
revision            0
categories          lang algol devel
license             GPL-3
maintainers         {@Dave-Allured noaa.gov:dave.allured} \
                    openmaintainer

description         Algol 68 implementation as defined by the Revised Report
long_description    Algol68G is an implementation of Algol 68 as defined by the Revised Report. \
                    It ranks among the most complete implementations of the language.

homepage            https://algol68genie.nl/en/algol-68-genie/
master_sites        https://algol68genie.nl

checksums           rmd160  73232151ae7026869c6b54306ac64c34afb6bd63 \
                    sha256  4d2e66f81ca2fb98f88e23ae41b475e7d40445f349b1088636782da320bd22b1 \
                    size    681167

extract.rename      yes

patchfiles-append   0001-configure.ac-fix-triples.patch \
                    0002-configure.ac-use-right-linker-flags.patch \
                    0003-configure.ac-support-mtune.patch \
                    0004-configure.ac-clear-up-a-mess.patch \
                    0005-configure.ac-use-correct-lib-name-for-R.patch \
                    0006-Fix-endianness-includes-and-macros.patch \
                    patch.plugin-driver_c.diff

compiler.c_standard 1999
compiler.blacklist-append \
                    {*gcc-[34].*} {clang < 500}

depends_build-append \
                    port:autoconf-archive \
                    port:grep \
                    path:bin/pkg-config:pkgconfig

depends_lib-append  port:gmp \
                    port:gsl \
                    port:mpfr \
                    port:ncurses \
                    port:readline

# We are patching configure.ac.
use_autoreconf      yes

configure.args-append \
                    --disable-mathlib \
                    --disable-plotutils \
                    --disable-postgresql \
                    --disable-silent-rules \
                    --enable-curses \
                    --enable-gsl \
                    --enable-mpfr \
                    --enable-readline

if {${configure.build_arch} ni [list ppc ppc64]} {
    configure.args-append \
                    --enable-clang
}

platform darwin 10 {
    # Rosetta needs this, otherwise it uses a wrong arch and clang
    if {${build_arch} eq "ppc"} {
        configure.args-append \
                        --build=powerpc-apple-darwin10
    }
}

# Notice that building compiler is untested for Darwin with the upstream
variant compiler description {Enable compiler, experimental} {
    # These are needed specifically for compiler:
    depends_build-append \
                        port:gsed
    depends_lib-append  port:gnutar

    configure.args-append \
                        --enable-compiler
}

variant native description {Optimize for the CPU} {
    if {${configure.build_arch} in [list ppc ppc64]} {
        configure.args-append \
                        --enable-tune=native
    } else {
        configure.args-append \
                        --enable-arch=native
    }
}

variant plotutils description {Building with GNU plotutils} {
    depends_lib-append  port:plotutils

    configure.args-replace\
                        --disable-plotutils --enable-plotutils
}

variant postgresql description {Enable postgresql support} {
    set pgsql_v         16
    depends_lib-append  port:postgresql${pgsql_v}

    configure.env-append \
                        PG_CONFIG=${prefix}/lib/postgresql${pgsql_v}/bin/pg_config

    configure.args-replace \
                        --disable-postgresql --enable-postgresql
    configure.cppflags-append \
                        -I${prefix}/include/postgresql${pgsql_v}
    configure.ldflags-append \
                        -L${prefix}/lib/postgresql${pgsql_v}
}

variant R description {Enable R support} {
    # Re linking to R: https://github.com/NevilleDNZ/algol68g-mirror/issues/4
    set r_branch        4.3
    depends_lib-append  port:R

    configure.args-replace \
                        --disable-mathlib --enable-mathlib
    configure.cppflags-append \
                        -I${frameworks_dir}/R.framework/Versions/${r_branch}/Resources/include
    configure.ldflags-append \
                        -L${frameworks_dir}/R.framework/Versions/${r_branch}/Resources/lib
}

livecheck.url       ${master_sites}/en/algol-68-genie-source-code-repository/
livecheck.type      regex
livecheck.regex     algol68g-(\[0-9.\]+)[quotemeta ${extract.suffix}]
