# -*- 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
PortGroup           muniversal 1.0
PortGroup           select 1.0

name                guile-1.8
version             1.8.8
revision            8
categories          lang
maintainers         nomaintainer
platforms           darwin
license             LGPL-2.1+

description         GNU's Ubiquitous Intelligent Language for Extension (guile)
long_description    \
        Guile is an interpreter for the Scheme programming      \
        language, packaged for use in a wide variety of         \
        environments. Guile implements Scheme as described in   \
        the Revised^5 Report on the Algorithmic Language Scheme \
        (usually known as R5RS), providing clean and general    \
        data and control structures.                            \
                                                                \
        Guile goes beyond the rather austere language presented \
        in R5RS, extending it with a module system, full access \
        to POSIX system calls, networking support, multiple     \
        threads, dynamic linking, a foreign function call       \
        interface, powerful string processing, and many other   \
        features needed for programming in the real world.

#user_notes You may need to set the environment variable        \
#       DYLD_LIBRARY_PATH to ${prefix}/lib (or wherever         \
#       the guile libraries have been installed) if you want    \
#       to load guile modules from an application linked with   \
#       libguile.  This should only apply to developers using   \
#       guile as an extension language.

distname            guile-${version}
homepage            https://www.gnu.org/software/guile/guile.html
master_sites        gnu:guile

checksums           md5     18661a8fdfef13e2fcb7651720aa53f3                                 \
                    sha1    548d6927aeda332b117f8fc5e4e82c39a05704f9                         \
                    rmd160  8ac185a72ad8394b14d5377549e5bbf02889faaa                         \
                    sha256  c3471fed2e72e5b04ad133bbaaf16369e8360283679bcf19800bc1b381024050 \
                    size    3956654

patchfiles          patch-srfi-60.c.diff         \
                    patch-libguile-fports.c.diff \
                    patch-no-stack-checking.diff \
                    endl.patch

depends_lib         port:readline \
                    port:gettext  \
                    port:libiconv \
                    port:libtool  \
                    port:gmp

depends_run-append  port:guile_select

# guile-using applications may need to set DYLD_LIBRARY_PATH to the guile
# library path so they can be loaded at runtime. They should not use
# ${prefix}/lib because this includes other MacPorts libraries that they may not
# wish to load instead. Accordingly, we install guile libraries into
# ${prefix}/lib/${name}. For compatibility, we symlink everything back into
# ${prefix}/lib.

# See https://trac.macports.org/ticket/52494
#
# Note: I removed the compatibility symlinks.  The dependent ports should just
#       be fixed.

configure.args                               \
    --program-suffix=-1.8                    \
    --infodir="${prefix}/share/info/${name}" \
    --mandir="${prefix}/share/man"           \
    --enable-regex                           \
    --disable-error-on-warning               \
    --includedir ${prefix}/include/${name}   \
    --libdir ${prefix}/lib/${name}

# guile-1.8.pc should be installed into the ${prefix}/lib/pkgconfig, but it
# defaults to libdir.
destroot.args-append pkgconfigdir=${prefix}/lib/pkgconfig

post-patch {
    # This changes configure to do what the author actually intended based on their comments
    reinplace "s|-Werror -Wmissing-braces|-Werror=missing-braces|" ${worksrcpath}/configure
}

# Unable to cross compile, so we need to be able to run the built code
if {${os.arch} eq "i386" && ${os.major} >= 11} {
    supported_archs i386 x86_64
    set universal_archs_supported {i386 x86_64}
} elseif {${os.arch} eq "i386" && ${build_arch} eq "x86_64"} {
    supported_archs i386 x86_64 ppc
    set universal_archs_supported {i386 x86_64 ppc}
} elseif {${os.arch} eq "i386"} {
    supported_archs i386 ppc
    set universal_archs_supported {i386 ppc}
} elseif {${build_arch} eq "ppc64"} {
    supported_archs ppc ppc64
    set universal_archs_supported {ppc ppc64}
} else {
    supported_archs ${build_arch}
    set universal_archs_supported ${build_arch}
}

platform darwin {
    if {${universal_possible} && [variant_isset universal]} {
        set merger_host(x86_64) x86_64-apple-${os.platform}${os.major}
        set merger_host(i386) i686-apple-${os.platform}${os.major}
        set merger_host(ppc64) powerpc64-apple-${os.platform}${os.major}
        set merger_host(ppc) powerpc-apple-${os.platform}${os.major}
        set merger_configure_args(x86_64) "--build=x86_64-apple-${os.platform}${os.major}"
        set merger_configure_args(i386) "--build=i686-apple-${os.platform}${os.major}"
        set merger_configure_args(ppc) "--build=powerpc-apple-${os.platform}${os.major}"
        set merger_configure_args(ppc64) "--build=powerpc64-apple-${os.platform}${os.major}"
    } elseif {${build_arch} eq "i386"} {
        configure.args-append \
            --host=i686-apple-${os.platform}${os.major} \
            --build=i686-apple-${os.platform}${os.major}
    } elseif {${build_arch} eq "x86_64"} {
        configure.args-append \
            --host=x86_64-apple-${os.platform}${os.major} \
            --build=x86_64-apple-${os.platform}${os.major}
    } elseif {${build_arch} eq "ppc"} {
        configure.args-append \
            --host=powerpc-apple-${os.platform}${os.major} \
            --build=powerpc-apple-${os.platform}${os.major}
    } elseif {${build_arch} eq "ppc64"} {
        configure.args-append \
            --host=powerpc64-apple-${os.platform}${os.major} \
            --build=powerpc64-apple-${os.platform}${os.major}
    }
}

set merger_dont_diff "${prefix}/include/libguile/scmconfig.h"

post-destroot {
    move ${destroot}${prefix}/share/aclocal/guile.m4 \
        ${destroot}${prefix}/share/aclocal/${name}.m4

    reinplace "s|${prefix}/bin/guile|${prefix}/bin/guile-1.8|g" \
        ${destroot}${prefix}/bin/guile-config-1.8

    # Ensure that in case there is 8th part the build fails.  When that
    # happens, update the select file.
    if {[file exists ${destroot}${prefix}/share/info/${name}/guile.info-8 ]} {
        ui_error "Additional part of info page available."
        return -code error
    }
}

livecheck.type      regex
livecheck.url       "https://ftp.gnu.org/pub/gnu/guile/?C=N;O=D"
livecheck.regex     {guile-(1\.8(?:\.\d+)*)}

select.group        guile
select.file         ${name}

notes "
To make the Guile ${version} default one, run:

port select --set ${select.group} [file tail ${select.file}]
"
