# -*- 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                ghc-ppc-bootstrap
set canonicalname   ghc
version             7.0.4
revision            2
categories          lang haskell
maintainers         nomaintainer
license             BSD
supported_archs     ppc
universal_variant   no
installs_libs       no

description         The Glorious Glasgow Haskell Compilation System
long_description    This is a package that installs a binary bootstrap GHC compiler.

homepage            https://haskell.org/${canonicalname}
# This address is unique, hardcoding version here is appropriate:
master_sites        https://downloads.haskell.org/ghc/7.0.4/krabby/
distname            GHC-${version}-powerpc
distfiles           ${distname}.pkg

checksums           rmd160  38cc042793d2b4f4a6b901c6bb7f6a1f6959cce8 \
                    sha256  81cc84e18d30d35d4103b21d146b264abd7f00879ae64ef492bc83d67231fb7c \
                    size    171783399

depends_extract     port:xar

worksrcdir          ${canonicalname}-${version}

# Newer gcc does not build ghc-bootstrap, so no point making variants here for those.
variant gcc7 conflicts gcc42 description {Compile with gcc 7} {
    configure.compiler      macports-gcc-7
    depends_run-append      port:gcc7
}

variant gcc42 conflicts gcc7 description {Compile with Xcode gcc 4.2} {
    configure.compiler      gcc-4.2
}

if {![variant_isset gcc7] && ![variant_isset gcc42]} {
    default_variants +gcc42
}

extract {
    system -W ${workpath} "mkdir -p ${worksrcpath}/pkg"
    system -W ${workpath} "mkdir -p ${worksrcpath}/files"
    system -W ${distpath} "cp ${distpath}/${distfiles} ${worksrcpath}/pkg"
    system -W ${worksrcpath}/pkg "${prefix}/bin/xar -xf ${worksrcpath}/pkg/GHC-${version}-powerpc.pkg -C ${worksrcpath}/files"
    system -W ${worksrcpath}/files/ghc.pkg "cat Payload | gunzip -dc | cpio -i"

if {![variant_isset framework]} {
    system -W ${worksrcpath}/files/ghc.pkg "mv GHC.framework/Versions/${version}-powerpc/usr ${worksrcpath}/${name}"
    system -W ${worksrcpath}/files/ghc.pkg "cp -R GHC.framework/Versions/${version}-powerpc/Tools ${worksrcpath}/${name}/share"
    }
}

use_configure no

build {}

if {![variant_isset framework]} {
    destroot.destdir prefix=${destroot}/share
    set path ${prefix}/share
    destroot {
        copy ${worksrcpath}/${name} ${destroot}${path}
    }

    post-destroot {
        # Delete dylibs; they arenʼt used by the bootstrap ghc and are incorrectly linked against /usr/local, causing rev-upgrade to complain.
        fs-traverse f ${destroot}${path}/${name}/lib {
            if {[file isfile ${f}]} {
                if {[file extension ${f}] == ".dylib"} {
                    delete ${f}
                }
            }
        }
        # Fix directory refs
        reinplace "s|[quotemeta /Library/Frameworks/GHC.framework/Versions/${version}-powerpc/usr]|${prefix}/share/${name}|" \
            ${destroot}${path}/${name}/bin/hsc2hs \
            ${destroot}${path}/${name}/bin/runghc \
            ${destroot}${path}/${name}/bin/ghc-${version} \
            ${destroot}${path}/${name}/bin/ghci-${version} \
            ${destroot}${path}/${name}/bin/ghc-pkg-${version} \
            ${destroot}${path}/${name}/bin/haddock-ghc-${version} \
            ${destroot}${path}/${name}/lib/ghc-${version}/package.conf.d/array-0.3.0.2-f538acad67d0b6696484da310d5949cf.conf \
            ${destroot}${path}/${name}/lib/ghc-${version}/package.conf.d/base-4.3.1.0-027b77b12e52d1549077882b70695ddf.conf \
            ${destroot}${path}/${name}/lib/ghc-${version}/package.conf.d/bin-package-db-0.0.0.0-ebccf3a563d9cc82a12563267e3b3973.conf \
            ${destroot}${path}/${name}/lib/ghc-${version}/package.conf.d/bytestring-0.9.1.10-518da2c2e8177a761e7c3f8131b096f3.conf \
            ${destroot}${path}/${name}/lib/ghc-${version}/package.conf.d/Cabal-1.10.2.0-5e1f7ddd36b188ae16e45b3a77b9c766.conf \
            ${destroot}${path}/${name}/lib/ghc-${version}/package.conf.d/containers-0.4.0.0-f1307d32d8f4b51a1487c01f0997b6d9.conf \
            ${destroot}${path}/${name}/lib/ghc-${version}/package.conf.d/directory-1.1.0.0-c0b12e512fadecf7242b2ec3cd952b2e.conf \
            ${destroot}${path}/${name}/lib/ghc-${version}/package.conf.d/extensible-exceptions-0.1.1.2-d8c5b906654260efd7249f497d17a831.conf \
            ${destroot}${path}/${name}/lib/ghc-${version}/package.conf.d/filepath-1.2.0.0-956a4b0c127b8c317f6cac3946b0b803.conf \
            ${destroot}${path}/${name}/lib/ghc-${version}/package.conf.d/ghc-${version}-75a79ada61f7974961ef6e048ae39af8.conf \
            ${destroot}${path}/${name}/lib/ghc-${version}/package.conf.d/ghc-binary-0.5.0.2-a36b46d7bbe800f04bce8a86565c2e8f.conf \
            ${destroot}${path}/${name}/lib/ghc-${version}/package.conf.d/ghc-prim-0.2.0.0-6bf7b03ebc9c668817e4379b6796c0c2.conf \
            ${destroot}${path}/${name}/lib/ghc-${version}/package.conf.d/haskell98-1.1.0.1-6f6b89a32eb0b5c7df8a4aba3d9884d3.conf \
            ${destroot}${path}/${name}/lib/ghc-${version}/package.conf.d/haskell2010-1.0.0.0-98ed3d653ac78fc3526ee288bfd554ae.conf \
            ${destroot}${path}/${name}/lib/ghc-${version}/package.conf.d/hpc-0.5.0.6-86b8caed77dec5a6adf56b6a203114d8.conf \
            ${destroot}${path}/${name}/lib/ghc-${version}/package.conf.d/integer-gmp-0.2.0.3-4c5ab8b517f0b5d4ecf2153d5dfb7f41.conf \
            ${destroot}${path}/${name}/lib/ghc-${version}/package.conf.d/old-locale-1.0.0.2-25ff1e5e0486bb3cf2cb85cb7daf8f22.conf \
            ${destroot}${path}/${name}/lib/ghc-${version}/package.conf.d/old-time-1.0.0.6-249d424df19da9487f0cb7da3ccb0868.conf \
            ${destroot}${path}/${name}/lib/ghc-${version}/package.conf.d/pretty-1.0.1.2-f2c716197e95f5c78869e6b87f2330d9.conf \
            ${destroot}${path}/${name}/lib/ghc-${version}/package.conf.d/process-1.0.1.5-7c01e525f8af6ff6ee54718777c83b45.conf \
            ${destroot}${path}/${name}/lib/ghc-${version}/package.conf.d/random-1.0.0.3-186815de972cb506efde02a72b0d8f8b.conf \
            ${destroot}${path}/${name}/lib/ghc-${version}/package.conf.d/template-haskell-2.5.0.0-5eb8b3886e957b3c9cb455b68e59f600.conf \
            ${destroot}${path}/${name}/lib/ghc-${version}/package.conf.d/time-1.2.0.3-ad46a3ade48e0011608895f44cc02a52.conf \
            ${destroot}${path}/${name}/lib/ghc-${version}/package.conf.d/unix-2.4.2.0-766adf3eeb77190cf0dabf1daf400c65.conf \
            ${destroot}${path}/${name}/lib/ghc-${version}/package.conf.d/builtin_ffi.conf \
            ${destroot}${path}/${name}/lib/ghc-${version}/package.conf.d/builtin_rts.conf
    }

    post-activate {
        catch {system "${prefix}/share/ghc-ppc-bootstrap/bin/ghc-pkg -v recache"}
    }
}

variant framework description {Install as a Framework} {
    destroot.destdir prefix=${destroot}${frameworks_dir}
    destroot {
        copy ${worksrcpath}/files/ghc.pkg/GHC.framework ${destroot}${frameworks_dir}
    }

    post-destroot {
        fs-traverse f ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib {
            if {[file isfile ${f}]} {
                if {[file extension ${f}] == ".dylib"} {
                    delete ${f}
                }
            }
        }
        reinplace "s|/Library/Frameworks|${frameworks_dir}|" \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/bin/hsc2hs \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/bin/runghc \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/bin/ghc-${version} \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/bin/ghci-${version} \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/bin/ghc-pkg-${version} \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/bin/haddock-ghc-${version} \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib/ghc-${version}/package.conf.d/array-0.3.0.2-f538acad67d0b6696484da310d5949cf.conf \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib/ghc-${version}/package.conf.d/base-4.3.1.0-027b77b12e52d1549077882b70695ddf.conf \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib/ghc-${version}/package.conf.d/bin-package-db-0.0.0.0-ebccf3a563d9cc82a12563267e3b3973.conf \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib/ghc-${version}/package.conf.d/bytestring-0.9.1.10-518da2c2e8177a761e7c3f8131b096f3.conf \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib/ghc-${version}/package.conf.d/Cabal-1.10.2.0-5e1f7ddd36b188ae16e45b3a77b9c766.conf \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib/ghc-${version}/package.conf.d/containers-0.4.0.0-f1307d32d8f4b51a1487c01f0997b6d9.conf \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib/ghc-${version}/package.conf.d/directory-1.1.0.0-c0b12e512fadecf7242b2ec3cd952b2e.conf \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib/ghc-${version}/package.conf.d/extensible-exceptions-0.1.1.2-d8c5b906654260efd7249f497d17a831.conf \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib/ghc-${version}/package.conf.d/filepath-1.2.0.0-956a4b0c127b8c317f6cac3946b0b803.conf \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib/ghc-${version}/package.conf.d/ghc-${version}-75a79ada61f7974961ef6e048ae39af8.conf \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib/ghc-${version}/package.conf.d/ghc-binary-0.5.0.2-a36b46d7bbe800f04bce8a86565c2e8f.conf \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib/ghc-${version}/package.conf.d/ghc-prim-0.2.0.0-6bf7b03ebc9c668817e4379b6796c0c2.conf \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib/ghc-${version}/package.conf.d/haskell98-1.1.0.1-6f6b89a32eb0b5c7df8a4aba3d9884d3.conf \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib/ghc-${version}/package.conf.d/haskell2010-1.0.0.0-98ed3d653ac78fc3526ee288bfd554ae.conf \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib/ghc-${version}/package.conf.d/hpc-0.5.0.6-86b8caed77dec5a6adf56b6a203114d8.conf \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib/ghc-${version}/package.conf.d/integer-gmp-0.2.0.3-4c5ab8b517f0b5d4ecf2153d5dfb7f41.conf \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib/ghc-${version}/package.conf.d/old-locale-1.0.0.2-25ff1e5e0486bb3cf2cb85cb7daf8f22.conf \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib/ghc-${version}/package.conf.d/old-time-1.0.0.6-249d424df19da9487f0cb7da3ccb0868.conf \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib/ghc-${version}/package.conf.d/pretty-1.0.1.2-f2c716197e95f5c78869e6b87f2330d9.conf \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib/ghc-${version}/package.conf.d/process-1.0.1.5-7c01e525f8af6ff6ee54718777c83b45.conf \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib/ghc-${version}/package.conf.d/random-1.0.0.3-186815de972cb506efde02a72b0d8f8b.conf \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib/ghc-${version}/package.conf.d/template-haskell-2.5.0.0-5eb8b3886e957b3c9cb455b68e59f600.conf \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib/ghc-${version}/package.conf.d/time-1.2.0.3-ad46a3ade48e0011608895f44cc02a52.conf \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib/ghc-${version}/package.conf.d/unix-2.4.2.0-766adf3eeb77190cf0dabf1daf400c65.conf \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib/ghc-${version}/package.conf.d/builtin_ffi.conf \
            ${destroot}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/lib/ghc-${version}/package.conf.d/builtin_rts.conf
    }

    post-activate {
        catch {system "${prefix}${frameworks_dir}/GHC.framework/Versions/${version}-powerpc/usr/bin/ghc-pkg -v recache"}
    }
}

livecheck.type      none
