# -*- 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.7.7
revision            0
categories          lang algol devel
license             GPL-3
maintainers         nomaintainer
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://jmvdveer.home.xs4all.nl/algol.html
master_sites        https://jmvdveer.home.xs4all.nl/ \
                    https://github.com/NevilleDNZ/algol68g-mirror/archive/refs/tags/

checksums           rmd160  ad311d64fdd65800792b75394b84aaf51f11b306 \
                    sha256  91079b549aafb82eefb0aad2708ab266364fcc6fd34eb8f339fc79180d704a12 \
                    size    665935

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

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

use_autoreconf      yes

configure.args-append \
                    --disable-mathlib \
                    --disable-plotutils \
                    --disable-postgresql \
                    --disable-silent-rules \
                    --enable-curses \
                    --enable-gsl \
                    --enable-mpfr \
                    --enable-readline \
                    --prefix=${prefix}

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.type      regex
livecheck.url       ${homepage}
livecheck.regex     algol68g-(\[0-9.\]+)${extract.suffix}
