# -*- 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                hugs98
version             plus-Sep2006
revision            3
categories          lang haskell
maintainers         nomaintainer
license             BSD
description         The HUGS Haskell Interpreter
long_description    Hugs 98 is a functional programming system based \
                    on Haskell 98, the de facto standard for non-strict \
                    functional programming languages. Hugs 98 provides \
                    an almost complete implementation of Haskell 98.

homepage            https://www.haskell.org/hugs
master_sites        https://cvs.haskell.org/Hugs/downloads/2006-09

checksums           rmd160  4a7e744360a29fbf94f5ac86ea559e80f12205a5 \
                    sha256  aafaca9ca544572ebef70bbe86b5eb0abaa5d7c11c0b766d7db72a46b022bed5 \
                    size    5322244

depends_build-append \
                    port:autoconf \
                    port:automake \
                    port:bison \
                    port:gmake \
                    port:libtool \
                    port:pkgconfig
depends_lib-append  port:libedit \
                    port:xorg-libX11

patchfiles-append   patch-configure.ac.diff \
                    patch-O1.diff \
                    patch-gcc-inline.diff \
                    patch-GLUT.diff \
                    patch-packages.diff

# Only Apple gcc understands -no-cpp-precomp
if {${configure.compiler} ni [list gcc-4.0 gcc-4.2 apple-gcc-4.0 apple-gcc-4.2]} {
    patchfiles-append patch-no-cpp-precomp.diff
}

# https://svnweb.freebsd.org/ports/head/lang/hugs/Makefile?revision=530719&view=co&pathrev=534092
# This is untested though; on PPC -O0 breaks the build.
if {${build_arch} eq "i386"} {
    patchfiles-replace \
                    patch-O1.diff patch-O0.diff
}

if {${os.platform} eq "darwin" && ${os.major} >= 10} {
    patchfiles-append patch-HTYPE_INT.diff
    # This fixes the 'Undefined symbols: "_environ"' error
    patchfiles-append patch-environ.diff
    # This fixes the 'Undefined symbols: "renameFile_17' and 'readdir_40' errors
    patchfiles-append patch-libraries-tools-make-bootlib.diff
    # error: invalid preprocessing directive #!: #!/usr/bin/runhaskell
    # https://github.com/FranklinChen/hugs98-plus-Sep2006/commit/5ca5d8da5cc692127d0621f652d720b8863772d7
    # https://github.com/FranklinChen/hugs98-plus-Sep2006/commit/4f323b9ab1fd6c53fe48d72aad4e7fba2ce8850c
    patchfiles-append patch-cpp-cleanup.diff
}

# Build with Clang has been failing.
compiler.blacklist  *clang*

if {${os.platform} eq "darwin" && ${os.major} > 15} {
    known_fail  yes
    pre-fetch {
        ui_error "This is an old compiler not supported on modern systems. Consider GHC instead."
        return -code error "incompatible OS version"
    }
} else {
    compiler.fallback-append \
                    gcc-4.2 apple-gcc-4.2 macports-gcc-12 macports-gcc-11 macports-gcc-7 macports-gcc-6
}

use_parallel_build  no

build.cmd           ${prefix}/bin/gmake

platform darwin 10 powerpc {
    # We ought to convince Rosetta to build for the right arch
    configure.args-append   CC="${configure.cc} -arch ppc" \
                            --build=powerpc-apple-darwin${os.major}
}

livecheck.type      none
