pkgsrc-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS commit: pkgsrc/lang/ghc94



Module Name:    pkgsrc
Committed By:   pho
Date:           Sat Jan 21 04:49:25 UTC 2023

Added Files:
        pkgsrc/lang/ghc94: DEINSTALL DESCR INSTALL Makefile bootstrap.mk
            buildlink3.mk distinfo options.mk
        pkgsrc/lang/ghc94/files: BOOTSTRAP.md UserSettings.hs
        pkgsrc/lang/ghc94/patches:
            patch-compiler_GHC_Driver_Pipeline_Execute.hs
            patch-compiler_GHC_SysTools_Process.hs patch-configure.ac
            patch-hadrian_bindist_Makefile patch-hadrian_bootstrap_bootstrap.py
            patch-hadrian_src_Builder.hs patch-hadrian_src_Oracles_Setting.hs
            patch-hadrian_src_Rules_BinaryDist.hs
            patch-hadrian_src_Settings_Builders_Ghc.hs
            patch-hadrian_src_Settings_Default.hs
            patch-hadrian_src_Settings_Packages.hs
            patch-libraries_Cabal_Cabal_src_Distribution_Simple_GHC.hs
            patch-libraries_base_GHC_Event_KQueue.hsc
            patch-libraries_base_System_CPUTime_Posix_Times.hsc
            patch-libraries_base_System_Environment.hs
            patch-libraries_base_System_Environment_ExecutablePath.hsc
            patch-libraries_base_configure
            patch-libraries_ghc-boot_GHC_BaseDir.hs
            patch-libraries_process_cbits_posix_fork__exec.c
            patch-libraries_terminfo_configure.ac
            patch-libraries_text_text.cabal
            patch-libraries_time_lib_Data_Time_Clock_Internal_CTimespec.hsc
            patch-libraries_time_lib_Data_Time_Clock_Internal_CTimeval.hs
            patch-libraries_unix_System_Posix_Env.hsc
            patch-libraries_unix_System_Posix_Env_ByteString.hsc
            patch-libraries_unix_System_Posix_Files_Common.hsc
            patch-libraries_unix_System_Posix_Signals.hsc
            patch-libraries_unix_include_execvpe.h
            patch-m4_fptools__set__haskell__platform__vars.m4
            patch-rts_linker_MMap.c patch-rts_linker_MMap.h
            patch-rts_rts.cabal.in patch-utils_haddock_driver_Main.hs
            patch-utils_haddock_haddock.cabal

Log Message:
lang/ghc94: import ghc-9.4.4

GHC: The Glasgow Haskell Compiler.

The Glasgow Haskell Compiler is a robust, fully-featured, optimising
compiler for the functional programming language Haskell 98
(http://www.haskell.org). GHC compiles Haskell to either native code
or C. It implements numerous experimental language extensions to
Haskell, including concurrency, a foreign language interface, several
type-system extensions, exceptions, and so on. GHC comes with a
generational garbage collector, a space and time profiler, and a
comprehensive set of libraries.

This package provides the 9.4.x release series.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 pkgsrc/lang/ghc94/DEINSTALL pkgsrc/lang/ghc94/DESCR \
    pkgsrc/lang/ghc94/INSTALL pkgsrc/lang/ghc94/Makefile \
    pkgsrc/lang/ghc94/bootstrap.mk pkgsrc/lang/ghc94/buildlink3.mk \
    pkgsrc/lang/ghc94/distinfo pkgsrc/lang/ghc94/options.mk
cvs rdiff -u -r0 -r1.1 pkgsrc/lang/ghc94/files/BOOTSTRAP.md \
    pkgsrc/lang/ghc94/files/UserSettings.hs
cvs rdiff -u -r0 -r1.1 \
    pkgsrc/lang/ghc94/patches/patch-compiler_GHC_Driver_Pipeline_Execute.hs \
    pkgsrc/lang/ghc94/patches/patch-compiler_GHC_SysTools_Process.hs \
    pkgsrc/lang/ghc94/patches/patch-configure.ac \
    pkgsrc/lang/ghc94/patches/patch-hadrian_bindist_Makefile \
    pkgsrc/lang/ghc94/patches/patch-hadrian_bootstrap_bootstrap.py \
    pkgsrc/lang/ghc94/patches/patch-hadrian_src_Builder.hs \
    pkgsrc/lang/ghc94/patches/patch-hadrian_src_Oracles_Setting.hs \
    pkgsrc/lang/ghc94/patches/patch-hadrian_src_Rules_BinaryDist.hs \
    pkgsrc/lang/ghc94/patches/patch-hadrian_src_Settings_Builders_Ghc.hs \
    pkgsrc/lang/ghc94/patches/patch-hadrian_src_Settings_Default.hs \
    pkgsrc/lang/ghc94/patches/patch-hadrian_src_Settings_Packages.hs \
    pkgsrc/lang/ghc94/patches/patch-libraries_Cabal_Cabal_src_Distribution_Simple_GHC.hs \
    pkgsrc/lang/ghc94/patches/patch-libraries_base_GHC_Event_KQueue.hsc \
    pkgsrc/lang/ghc94/patches/patch-libraries_base_System_CPUTime_Posix_Times.hsc \
    pkgsrc/lang/ghc94/patches/patch-libraries_base_System_Environment.hs \
    pkgsrc/lang/ghc94/patches/patch-libraries_base_System_Environment_ExecutablePath.hsc \
    pkgsrc/lang/ghc94/patches/patch-libraries_base_configure \
    pkgsrc/lang/ghc94/patches/patch-libraries_ghc-boot_GHC_BaseDir.hs \
    pkgsrc/lang/ghc94/patches/patch-libraries_process_cbits_posix_fork__exec.c \
    pkgsrc/lang/ghc94/patches/patch-libraries_terminfo_configure.ac \
    pkgsrc/lang/ghc94/patches/patch-libraries_text_text.cabal \
    pkgsrc/lang/ghc94/patches/patch-libraries_time_lib_Data_Time_Clock_Internal_CTimespec.hsc \
    pkgsrc/lang/ghc94/patches/patch-libraries_time_lib_Data_Time_Clock_Internal_CTimeval.hs \
    pkgsrc/lang/ghc94/patches/patch-libraries_unix_System_Posix_Env.hsc \
    pkgsrc/lang/ghc94/patches/patch-libraries_unix_System_Posix_Env_ByteString.hsc \
    pkgsrc/lang/ghc94/patches/patch-libraries_unix_System_Posix_Files_Common.hsc \
    pkgsrc/lang/ghc94/patches/patch-libraries_unix_System_Posix_Signals.hsc \
    pkgsrc/lang/ghc94/patches/patch-libraries_unix_include_execvpe.h \
    pkgsrc/lang/ghc94/patches/patch-m4_fptools__set__haskell__platform__vars.m4 \
    pkgsrc/lang/ghc94/patches/patch-rts_linker_MMap.c \
    pkgsrc/lang/ghc94/patches/patch-rts_linker_MMap.h \
    pkgsrc/lang/ghc94/patches/patch-rts_rts.cabal.in \
    pkgsrc/lang/ghc94/patches/patch-utils_haddock_driver_Main.hs \
    pkgsrc/lang/ghc94/patches/patch-utils_haddock_haddock.cabal

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: pkgsrc/lang/ghc94/DEINSTALL
diff -u /dev/null pkgsrc/lang/ghc94/DEINSTALL:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/DEINSTALL Sat Jan 21 04:49:25 2023
@@ -0,0 +1,9 @@
+#!/bin/sh
+#
+GHC_VERSION="@GHC_VERSION@"
+
+case ${STAGE} in
+    DEINSTALL)
+        ${RM} -f ${PKG_PREFIX}/lib/${PKGBASE}-${GHC_VERSION}/package.conf.d/package.cache
+        ;;
+esac
Index: pkgsrc/lang/ghc94/DESCR
diff -u /dev/null pkgsrc/lang/ghc94/DESCR:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/DESCR     Sat Jan 21 04:49:25 2023
@@ -0,0 +1,12 @@
+GHC: The Glasgow Haskell Compiler.
+
+The Glasgow Haskell Compiler is a robust, fully-featured, optimising
+compiler for the functional programming language Haskell 98
+(http://www.haskell.org). GHC compiles Haskell to either native code
+or C. It implements numerous experimental language extensions to
+Haskell, including concurrency, a foreign language interface, several
+type-system extensions, exceptions, and so on. GHC comes with a
+generational garbage collector, a space and time profiler, and a
+comprehensive set of libraries.
+
+This package provides the 9.4.x release series.
Index: pkgsrc/lang/ghc94/INSTALL
diff -u /dev/null pkgsrc/lang/ghc94/INSTALL:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/INSTALL   Sat Jan 21 04:49:25 2023
@@ -0,0 +1,8 @@
+#!/bin/sh
+#
+
+case ${STAGE} in
+    POST-INSTALL)
+        ${PKG_PREFIX}/bin/ghc-pkg recache
+        ;;
+esac
Index: pkgsrc/lang/ghc94/Makefile
diff -u /dev/null pkgsrc/lang/ghc94/Makefile:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/Makefile  Sat Jan 21 04:49:25 2023
@@ -0,0 +1,319 @@
+# $NetBSD: Makefile,v 1.1 2023/01/21 04:49:25 pho Exp $
+# -----------------------------------------------------------------------------
+# Package metadata
+#
+DISTNAME=      ghc-9.4.4-src
+PKGNAME=       ${DISTNAME:S/-src$//}
+CATEGORIES=    lang
+MASTER_SITES=  https://downloads.haskell.org/~ghc/${PKGVERSION_NOREV}/
+EXTRACT_SUFX=  .tar.xz
+
+MAINTAINER=    pkgsrc-users%NetBSD.org@localhost
+HOMEPAGE=      https://www.haskell.org/ghc/
+COMMENT=       Compiler for the functional language Haskell - 9.4 Release Series
+LICENSE=       modified-bsd
+
+UNLIMIT_RESOURCES=     cputime datasize virtualsize
+
+# GHC requires GHC to build itself. We have to prepare stripped-down
+# binaries sufficient to bootstrap compilers for each platform. If you want
+# to build them yourself, follow instructions in files/BOOTSTRAP.md.
+BROKEN_EXCEPT_ON_PLATFORM+=    Darwin-*-x86_64
+#BROKEN_EXCEPT_ON_PLATFORM+=   FreeBSD-*-i386
+#BROKEN_EXCEPT_ON_PLATFORM+=   FreeBSD-*-x86_64
+BROKEN_EXCEPT_ON_PLATFORM+=    NetBSD-*-aarch64
+BROKEN_EXCEPT_ON_PLATFORM+=    NetBSD-*-x86_64
+BROKEN_EXCEPT_ON_PLATFORM+=    SunOS-*-x86_64
+# It's broken on FreeBSD atm. Dunno what is causing this:
+# > ld: error:
+# > _build/stage0/lib/../lib/x86_64-freebsd-ghc-9.0.1/ghc-9.4.4/libHSghc-9.4.4.a(Instances.o):
+# > SHT_SYMTAB_SHNDX has 44805 entries, but the symbol table associated has
+# > 54313
+
+# We are going to do a PIE build on our responsibility. Do not put -pie in
+# wrappers, as that would prevent us from building stage-1 compiler.
+PKGSRC_OVERRIDE_MKPIE= yes
+
+.include "options.mk"
+
+
+# -----------------------------------------------------------------------------
+# Distfiles
+#
+DISTFILES=     ${DEFAULT_DISTFILES}
+WRKSRC=                ${WRKDIR}/${PKGNAME_NOREV}
+
+# We don't want to extract all of the DISTFILEs.
+EXTRACT_ONLY=  ${DEFAULT_DISTFILES}
+
+
+# -----------------------------------------------------------------------------
+# Tools
+#
+USE_TOOLS+=                    autoconf gmake
+USE_LANGUAGES+=                        c c++
+GNU_CONFIGURE=                 yes
+USE_GNU_CONFIGURE_HOST=                no
+USE_LIBTOOL=                   yes
+PYTHON_FOR_BUILD_ONLY=         yes
+.include "../../lang/python/tool.mk"
+
+# -----------------------------------------------------------------------------
+# Configuration
+#
+HADRIAN_ARGS=  # empty
+HADRIAN_ARGS+= -j${_MAKE_JOBS_N}
+
+CONFIGURE_ARGS.common+= \
+       --with-curses-libraries=${BUILDLINK_PREFIX.curses}/${BUILDLINK_LIBDIRS.curses:Q} \
+       --with-gmp-includes=${BUILDLINK_PREFIX.gmp}/${BUILDLINK_INCDIRS.gmp:Q} \
+       --with-gmp-libraries=${BUILDLINK_PREFIX.gmp}/${BUILDLINK_LIBDIRS.gmp:Q} \
+       --with-iconv-includes=${BUILDLINK_PREFIX.iconv}/${BUILDLINK_INCDIRS.iconv:Q} \
+       --with-iconv-libraries=${BUILDLINK_PREFIX.iconv}/${BUILDLINK_LIBDIRS.iconv:Q} \
+       --with-ffi-includes=${BUILDLINK_PREFIX.libffi}/${BUILDLINK_INCDIRS.libffi:Q} \
+       --with-ffi-libraries=${BUILDLINK_PREFIX.libffi}/${BUILDLINK_LIBDIRS.libffi:Q}
+
+.include "../../mk/bsd.prefs.mk"
+
+# We must pass non-wrapper tools to ./configure because they will be
+# embedded in the compiler (actually ${WRKSRC}/settings).
+CONFIGURE_ENV+=                ac_cv_prog_fp_prog_ar=${AR:Q}
+CONFIGURE_ENV+=                ac_cv_prog_LIBTOOL=libtool
+CONFIGURE_ARGS.common+=        LD=${LD:Q}
+
+# If there is HsColour in the PATH, GHC's build system tries to use it
+# without checking if it really works. That's not what we appreciate.
+CONFIGURE_ENV+=                ac_cv_path_HSCOLOUR=
+
+CONFIGURE_ARGS+=       ${CONFIGURE_ARGS.common}
+CONFIGURE_ARGS+=       --with-system-libffi
+
+# CFLAGS and LDFLAGS are currently not honored by "./configure". Since
+# LDFLAGS contains rpath flags it's very important to force GHC to honor
+# it. Otherwise neither GHC itself nor executables it produces will have
+# any rpaths so users will have to put "${PREFIX}/lib" into their
+# "/etc/ld-elf.so.conf". See
+# http://hackage.haskell.org/trac/ghc/ticket/2933
+.for stage in 0 1 2
+CONFIGURE_ENV+=        CONF_GCC_LINKER_OPTS_STAGE${stage}=${LDFLAGS:M*:Q}
+# Note that CONF_LD_LINKER_OPTS_STAGE{0,1,2} are only used for
+# creating static GHCi libraries (HS*.o). Setting them to ${LDFLAGS}
+# does more harm than good because our ${LDFLAGS} contains -Wl,*
+# flags. It's true that ../../mk/wrapper/cmd-sink-ld transforms them
+# but those flags will also be baked into the compiler (see
+# ${WRKSRC}/compiler/ghc.mk) so they cause problems when used outside
+# the buildlink.
+.endfor
+
+# The use of internal variable ${_PKGSRC_MKPIE} in mk/bsd.prefs.mk is not
+# very satisfying, but the current infrastructure does not export a public
+# variable indicating whether a PIE build is requested or not. Note that we
+# can't build stage-1 compiler as PIE, because our bootkit libraries aren't
+# necessarily built as PIC.
+.for stage in 0 1 2
+.  if ${stage} == 0
+CONFIGURE_ENV+=        CONF_CC_OPTS_STAGE${stage}=${CFLAGS:M*:Q}
+.  else
+.    if ${_PKGSRC_MKPIE} == "yes"
+CONFIGURE_ENV+=        CONF_CC_OPTS_STAGE${stage}=${CFLAGS:M*:Q}\ -fPIC
+CONFIGURE_ENV+=        CONF_HC_OPTS_STAGE${stage}=-fPIC\ -pie
+# Hadrian doesn't honor CONF_HC_OPTS_STAGE${stage}. Possibly a bug?
+HADRIAN_ARGS+= "stage${stage}.*.ghc.c.opts += -fPIC"
+HADRIAN_ARGS+= "stage${stage}.*.ghc.hs.opts += -fPIC"
+HADRIAN_ARGS+= "stage${stage}.*.ghc.link.opts += -pie"
+.    else
+CONFIGURE_ENV+=        CONF_CC_OPTS_STAGE${stage}=${CFLAGS:M*:Q}
+.    endif
+.  endif
+.endfor
+.if ${_PKGSRC_MKPIE} == "yes"
+# utils/unlit is a special case. It's built with the stage-0 compiler but
+# since it's entirely written in C there's no problem doing a PIE build.
+HADRIAN_ARGS+= "*.unlit.ghc.c.opts += -fPIC"
+HADRIAN_ARGS+= "*.unlit.ghc.link.opts += -pie"
+.endif
+
+# MacOS X 10.7 is the oldest OS X version supporting __thread. Although
+# ${WRKSRC}/configure has a check for it, the actual build will fail
+# without this env.
+.if ${OPSYS} == "Darwin"
+ALL_ENV+=      MACOSX_DEPLOYMENT_TARGET="10.7"
+.endif
+
+
+# -----------------------------------------------------------------------------
+# Security
+#
+# The runtime system of GHC (rts) has a mechanism called "RTS linker" whose
+# job is to load and execute *static* objects (.a and .o files) at run
+# time. It cannot survive PaX MPROTECT because preloadObjectFile() in
+# rts/linker.c tries to mmap pages with w+x. It doesn't play nice with ASLR
+# either because mmapForLinker() in rts/linker.c wants to always mmap pages
+# in the lower 32-bit area on 64-bit platforms.
+#
+# Luckily for us, the RTS linker is only used when the GHC executable (or
+# any user programs which uses GHC API as an interpreter, not a compiler)
+# is statically linked, which is no longer the case except for ghc-iserv
+# and ghc-iesrv-prof. They are launched when ghci is started with
+# -fexternal-interpreter without -dynamic, and their purpose is to run
+# non-PIC code from within a dynamically linked ghci using the evil RTS
+# linker.
+.for f in ghc-iserv ghc-iserv-prof
+NOT_PAX_MPROTECT_SAFE+=        lib/${PKGNAME_NOREV}/bin/${f}
+NOT_PAX_ASLR_SAFE+=    lib/${PKGNAME_NOREV}/bin/${f}
+.endfor
+
+
+# -----------------------------------------------------------------------------
+# Build hooks
+#
+
+# We patch configure.ac in some directories.
+post-patch:
+       @${PHASE_MSG} "Regenerating configuration scripts for ${PKGNAME}"
+       ${RUN}cd ${WRKSRC} && autoconf
+       ${RUN}cd ${WRKSRC}/libraries/terminfo && autoconf
+
+# Define the target "pre-configure", "pre-build", and non-standard
+# "bootstrap".
+.include "bootstrap.mk"
+
+# Our pre-configure phase installs a bindist of bootstrapping compiler
+# directly into TOOLS_DIR so that ./configure can find it. Our pre-build
+# phase bootstraps Hadrian.
+
+# We have a patch to Hadrian so that it uses absolute RPATHs as opposed to
+# relative ones (i.e. $ORIGIN). The patch uses --prefix at build time.
+HADRIAN_ARGS+= --prefix=${PREFIX:Q}
+
+# The output from Hadrian is too terse by default. Use at least a single
+# --verbose so we can know what's really going on.
+HADRIAN_ARGS+= --verbose ${PKG_VERBOSE:D--verbose}
+
+# The version restriction on Sphinx in ${WRKSRC}/configure.ac is too
+# loose, and building docs/users_guide rarely succeeds. We don't know
+# which version is actually required for it.
+BUILD_SPHINX_HTML?=    no
+HADRIAN_ARGS+=         ${${BUILD_SPHINX_HTML:tl} == "no":?--docs=no-sphinx:}
+
+# Don't even think of PDF.
+HADRIAN_ARGS+=         --docs=no-sphinx-pdfs
+
+# Haddock consumes nearly 5GB of memory while building documentation for
+# Cabal. This is unfortunately not acceptable. We must disable it until
+# things get improved.
+HADRIAN_ARGS+=         --docs=no-haddocks
+
+# Enable -fsplit-sections on platforms that support it.
+HADRIAN_ARGS+=         --flavour=default+split_sections
+
+do-build:
+       ${RUN}cd ${WRKSRC} && ${HADRIAN_CMD} ${HADRIAN_ARGS}
+       ${RUN}cd ${WRKSRC} && ${HADRIAN_CMD} ${HADRIAN_ARGS} docs
+
+
+# -----------------------------------------------------------------------------
+# Installation/removal hooks
+#
+
+# Substitutions for INSTALL and DEINSTALL that handles package.cache.
+FILES_SUBST+=  GHC_VERSION=${PKGVERSION_NOREV}
+
+# mk/install_script.sh, whose purpose is to generate GHC wrapper scripts to
+# be installed, refers to the variable $SHELL. This is bad because our
+# $SHELL is in the TOOLDIR.
+SUBST_CLASSES+=                        ghc-wrapper-sh
+SUBST_STAGE.ghc-wrapper-sh=    post-extract
+SUBST_FILES.ghc-wrapper-sh=    mk/install_script.sh
+SUBST_SED.ghc-wrapper-sh=      -e 's,\#!\$$SHELL,\#!/bin/sh,'
+
+# The "install" target in Hadrian doesn't support DESTDIR so we can't use
+# it.
+do-install:
+       ${RUN}cd ${WRKSRC} && \
+               ${HADRIAN_CMD} ${HADRIAN_ARGS} binary-dist-dir
+       ${RUN}cd ${WRKSRC}/_build/bindist/ghc-* && \
+               ${PKGSRC_SETENV} ${CONFIGURE_ENV} ${SH} ./configure ${CONFIGURE_ARGS}
+       ${RUN}cd ${WRKSRC}/_build/bindist/ghc-* && \
+               ${PKGSRC_SETENV} ${INSTALL_ENV} ${MAKE_ENV} \
+                       ${MAKE_PROGRAM} ${MAKE_FLAGS} ${INSTALL_MAKE_FLAGS} \
+                       RECACHE_PACKAGE_DB=NO install
+
+INSTALLATION_DIRS+=    share/bash-completion/completions
+post-install:
+       ${INSTALL_DATA} ${WRKSRC}/utils/completion/ghc.bash \
+               ${DESTDIR}${PREFIX}/share/bash-completion/completions/ghc
+# We don't want package.cache to be in the PLIST.
+       for f in package.cache package.cache.lock; do \
+               ${RM} ${DESTDIR}${PREFIX}/lib/${PKGNAME_NOREV}/lib/package.conf.d/$$f; \
+       done
+
+
+# -----------------------------------------------------------------------------
+# PLIST
+#
+# We can't use static PLIST because the package installs files with a
+# hashed name. And "PLIST_TYPE = dynamic" appears to be broken atm
+# [2019-12-27; pho].
+GENERATE_PLIST+= \
+       cd ${DESTDIR}${PREFIX} && \
+               ${FIND} * \( -type f -o -type l \) | ${SORT};
+
+
+# -----------------------------------------------------------------------------
+# Sanity checks
+#
+
+# These files don't pass our portability checks but we don't use them
+# anyway.
+CHECK_PORTABILITY_SKIP+=       validate
+
+# ghc57207_0.s: failed to add inputs for merge: Resource temporarily unavailable
+# XXX: On which platform? Is it still an issue?
+CTF_FILES_SKIP+=               */libHS*-ghc${PKGVERSION_NOREV}.*
+
+# ld: fatal: relocation error ... relocation requires reference symbol
+# XXX: On which platform? Is it still an issue?
+STRIP_FILES_SKIP+=             lib/${PKGNAME_NOREV}/libHSrts.a
+
+
+# -----------------------------------------------------------------------------
+# Dependencies
+#
+.if ${BUILD_SPHINX_HTML} != "no"
+BUILD_DEPENDS+=        ${PYPKGPREFIX}-sphinx-[0-9]*:../../textproc/py-sphinx
+.endif
+
+# NetBSD 9.x have libcurses with a newer major version than the
+# bootstrap kit is linked against. For now, work around this with
+# compat libraries.
+#
+# In a sandboxed build environment, we have to reach over to the
+# installed libraries themselves, since the symlinks compatXX adds
+# to the /usr tree can't be applied.
+.if !empty(MACHINE_PLATFORM:MNetBSD-*-aarch64*) && ${OPSYS_VERSION} >= 099000
+BUILD_DEPENDS+=        compat90-[0-9]*:../../emulators/compat90
+ALL_ENV+=      LD_LIBRARY_PATH=${PREFIX}/emul/netbsd/usr/lib
+.elif !empty(MACHINE_PLATFORM:MNetBSD-*-*) && ${OPSYS_VERSION} >= 099000
+BUILD_DEPENDS+=        compat80-[0-9]*:../../emulators/compat80
+BUILD_DEPENDS+=        compat90-[0-9]*:../../emulators/compat90
+ALL_ENV+=      LD_LIBRARY_PATH=${PREFIX}/emul/netbsd/usr/lib
+.elif !empty(MACHINE_PLATFORM:MNetBSD-*-x86_64) && ${OPSYS_VERSION} >= 090000
+BUILD_DEPENDS+=        compat80-[0-9]*:../../emulators/compat80
+ALL_ENV+=      LD_LIBRARY_PATH=${PREFIX}/emul/netbsd/usr/lib:${WRKDIR}/lib
+# XXX: ${WRKDIR}/lib is a temporary workaround for compat80 not having
+# libterminfo.so.1. See ./bootstrap.mk
+.endif
+
+# On Solaris-based platforms our bootkit tends to depend on
+# pkgsrc-installed shlibs.
+.if ${OPSYS} == "SunOS"
+ALL_ENV+=      LD_LIBRARY_PATH=${PREFIX}/lib
+.endif
+
+.include "../../converters/libiconv/buildlink3.mk"
+.include "../../devel/libffi/buildlink3.mk"
+.include "../../devel/gmp/buildlink3.mk"
+.include "../../mk/curses.buildlink3.mk"
+.include "../../mk/pthread.buildlink3.mk"
+.include "../../mk/bsd.pkg.mk"
Index: pkgsrc/lang/ghc94/bootstrap.mk
diff -u /dev/null pkgsrc/lang/ghc94/bootstrap.mk:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/bootstrap.mk      Sat Jan 21 04:49:25 2023
@@ -0,0 +1,333 @@
+# $NetBSD: bootstrap.mk,v 1.1 2023/01/21 04:49:25 pho Exp $
+# -----------------------------------------------------------------------------
+# Select a bindist of bootstrapping compiler on a per-platform basis. See
+# ./files/BOOTSTRAP.md for details.
+#
+# BOOT_ARCHIVE
+#   This variable is set to the name of compressed archive file of a
+#   bootstrapping compiler for the platform.
+#
+# BOOT_VERSION
+#   Version of the bootstrapping compiler to use.
+#
+.include "../../mk/bsd.prefs.mk"
+
+# Notes on version dependencies:
+# * GHC 9.4.4 requires 9.0 or later to bootstrap.
+# * GHC 9.2.1 requires 8.10 or later to bootstrap.
+# * GHC 9.0.1 requires 8.8 or later to bootstrap.
+# * GHC 8.8.4 requires 8.4 or later to bootstrap.
+# * GHC 8.4.4 requires 8.0 or later to bootstrap.
+# * GHC 8.0.2 requires 7.8 or later to bootstrap.
+# * GHC 7.10.3 requires 7.6 or later to bootstrap.
+
+# GHC has migrated away from GNU Make to Hadrian as its build system. We
+# first need to build it in order to build GHC, but a source tarball
+# required for building Hadrian is specific to the version of GHC to use
+# for bootstrapping. See ./files/BOOTSTRAP.md for instructions on how to
+# create one.
+HADRIAN_BOOT_SOURCE=   ghc-${BOOT_VERSION}-boot-hadrian.tar.gz
+
+.if !empty(MACHINE_PLATFORM:MDarwin-*-x86_64) || make(distinfo) || make (makesum) || make(mdi)
+BOOT_VERSION:= 9.0.1
+BOOT_ARCHIVE:= ghc-${BOOT_VERSION}-boot-x86_64-apple-darwin.tar.xz
+DISTFILES:=    ${DISTFILES} ${BOOT_ARCHIVE} ${HADRIAN_BOOT_SOURCE} # Available in LOCAL_PORTS
+.endif
+
+.if !empty(MACHINE_PLATFORM:MFreeBSD-*-i386) || make(distinfo) || make (makesum) || make(mdi)
+BOOT_VERSION:= 9.0.1
+BOOT_ARCHIVE:= ghc-${BOOT_VERSION}-boot-i386-unknown-freebsd.tar.xz
+DISTFILES:=    ${DISTFILES} ${BOOT_ARCHIVE} ${HADRIAN_BOOT_SOURCE} # Available in LOCAL_PORTS
+.endif
+
+.if !empty(MACHINE_PLATFORM:MFreeBSD-*-x86_64) || make(distinfo) || make(makesum) || make(mdi)
+BOOT_VERSION:= 9.0.1
+BOOT_ARCHIVE:= ghc-${BOOT_VERSION}-boot-x86_64-unknown-freebsd.tar.xz
+DISTFILES:=    ${DISTFILES} ${BOOT_ARCHIVE} ${HADRIAN_BOOT_SOURCE} # Available in LOCAL_PORTS
+.endif
+
+.if !empty(MACHINE_PLATFORM:MNetBSD-*-aarch64) || make(distinfo) || make(makesum) || make(mdi)
+# Cross-compiled from x86_64 on a QEMU guest. It took days to compile...
+BOOT_VERSION:= 9.2.1
+BOOT_ARCHIVE:= ghc-${BOOT_VERSION}-boot-aarch64-unknown-netbsd.tar.xz
+DISTFILES:=    ${DISTFILES} ${BOOT_ARCHIVE} ${HADRIAN_BOOT_SOURCE} # Available in LOCAL_PORTS
+.endif
+
+.if !empty(MACHINE_PLATFORM:MNetBSD-*-x86_64) || make(distinfo) || make(makesum) || make(mdi)
+BOOT_VERSION:= 9.2.1
+BOOT_ARCHIVE:= ghc-${BOOT_VERSION}-boot-x86_64-unknown-netbsd.tar.xz
+DISTFILES:=    ${DISTFILES} ${BOOT_ARCHIVE} ${HADRIAN_BOOT_SOURCE} # Available in LOCAL_PORTS
+.  if !empty(MACHINE_PLATFORM:MNetBSD-9.99.*-x86_64) || make(distinfo) || make (makesum) || make(mdi)
+# XXX: emulators/compat80 appears to lack libterminfo.so.1 used by
+# this bootkit.
+DISTFILES+=    netbsd-9.0-amd64-libterminfo.tar.gz
+EXTRACT_ONLY+= netbsd-9.0-amd64-libterminfo.tar.gz
+SITES.netbsd-9.0-amd64-libterminfo.tar.gz?=    ${MASTER_SITE_LOCAL}
+.  endif
+.endif
+
+.if !empty(MACHINE_PLATFORM:MSunOS-*-x86_64) || make(distinfo) || make (makesum) || make(mdi)
+BOOT_VERSION:=         9.0.1
+BOOT_ARCHIVE:=         ghc-${BOOT_VERSION}-boot-x86_64-unknown-solaris2.tar.xz
+DISTFILES:=            ${DISTFILES} ${BOOT_ARCHIVE} ${HADRIAN_BOOT_SOURCE} # Available in LOCAL_PORTS
+.endif
+
+# DISTFILES contains duplicate HADRIAN_BOOT_SOURCE entries at this
+# point. Dedupe them now.
+DISTFILES:=    ${DISTFILES:O:u}
+
+.if empty(BOOT_ARCHIVE)
+BOOT_ARCHIVE:=         ghc-${BOOT_VERSION}-boot-unknown.tar.xz
+PKG_FAIL_REASON+=      "internal error: unsupported platform"
+.endif
+
+# For package developers, please do not upload any bootkits unsafely
+# built. That is, machines shared with someone or on a cloud hosting
+# service should be avoided for building bootkits.
+.for i in ${DISTFILES:M*-boot-*}
+SITES.${i}?=   ${MASTER_SITE_LOCAL}
+.endfor
+
+# Current bootstrap binary kit for SunOS is built with GNU libiconv
+# and ncurses6.
+.if !empty(MACHINE_PLATFORM:MSunOS-*)
+BUILD_DEPENDS+=        libiconv>=1.9.1:../../converters/libiconv
+BUILD_DEPENDS+=        ncurses>=6.0:../../devel/ncurses
+.endif
+
+.if ${OPSYS} == "SunOS" && ${OS_VARIANT:U} == "OmniOS"
+# Also cpp is missing from /usr/bin. Why? This leads
+# ${WRKSRC}/libffi/configure to fail.
+TOOLS_PLATFORM.cpp=    /usr/lib/cpp
+.endif
+
+
+# -----------------------------------------------------------------------------
+# The "pre-configure" hook
+#
+# Install a bootstrapping (stage-0) compiler directly into TOOLS_DIR so
+# that ./configure can find it.
+#
+USE_TOOLS+=    xzcat xz gtar cpp
+
+pre-configure:
+       ${RUN}${TEST} -f ${DISTDIR}/${DIST_SUBDIR}/${BOOT_ARCHIVE} || \
+       ${FAIL_MSG}  "Put your trusted bootstrap archive as ${DISTDIR}/${DIST_SUBDIR}/${BOOT_ARCHIVE}"
+
+       @${PHASE_MSG} "Extracting bootstrapping compiler for ${PKGNAME}"
+       ${RUN}${MKDIR} ${WRKDIR}/bootkit-dist
+       ${RUN}cd ${WRKDIR}/bootkit-dist && \
+               ${XZCAT} ${DISTDIR}/${DIST_SUBDIR}/${BOOT_ARCHIVE} | \
+               ${GTAR} -xf -
+
+       @${PHASE_MSG} "Preparing bootstrapping compiler for ${PKGNAME}"
+       ${RUN}cd ${WRKDIR}/bootkit-dist/ghc-${BOOT_VERSION}-boot && \
+               ${PKGSRC_SETENV} ${CONFIGURE_ENV} ${SH} ./configure \
+                       --prefix=${TOOLS_DIR:Q} ${CONFIGURE_ARGS.boot} && \
+               ${PKGSRC_SETENV} ${MAKE_ENV} ${MAKE_PROGRAM} install
+
+
+# -----------------------------------------------------------------------------
+# The "pre-build" hook
+#
+# Bootstrap Hadrian with the stage-0 compiler. It is important to do this
+# in "pre-build" because we often need to patch Hadrian itself while
+# updating our packages and we want it to be rebuilt every time we make
+# changes to it.
+#
+pre-build:
+       ${RUN}${TEST} -f ${DISTDIR}/${DIST_SUBDIR}/${HADRIAN_BOOT_SOURCE} || \
+               ${FAIL_MSG} "${HADRIAN_BOOT_SOURCE} not found in ${DISTDIR}/${DIST_SUBDIR}.\
+                       You first need to create it before building ${PKGNAME}.\
+                       See ./files/BOOTSTRAP.md for details."
+
+       @${PHASE_MSG} "Building Hadrian for GHC ${BOOT_VERSION}"
+       ${RUN}cd ${WRKSRC}/hadrian/bootstrap && \
+               python bootstrap.py -s ${DISTDIR}/${DIST_SUBDIR}/${HADRIAN_BOOT_SOURCE}
+
+# This defines how to run the Hadrian command. Also used in do-build and
+# such.
+HADRIAN_CMD=   ${PKGSRC_SET_ENV} ${ALL_ENV} ${WRKSRC}/hadrian/bootstrap/_build/bin/hadrian
+
+# -----------------------------------------------------------------------------
+# An unusual target "bootstrap"
+#
+# Build a bootstrapping compiler using an already installed GHC. This is
+# certainly impossible if you don't have one. It's absolutely important to
+# build it with the fewest possible run-time dependencies, otherwise the
+# resulting binary can easily get unusable.
+
+# We don't want our bootkits to have a run-time dependency on
+# libgcc. In fact GHC's implementation of Haskell exception handling
+# does not depend on libgcc's facilities so it is attractive to do the
+# same for "normal" build... but we can't. This is because Haskell
+# programs may call C functions via FFI, and those C functions may
+# call C++ functions in turn, possibly in a different shared library.
+.include "../../mk/compiler.mk"
+.if make(bootstrap) && !empty(CC_VERSION:Mgcc-*)
+# But on some platforms, gcc automagically inserts a dependency on a
+# shared libgcc when -lpthread is given, which is seemingly
+# unavoidable.
+LDFLAGS+=      -static-libgcc
+.endif
+
+# Gather information about packages on which bootkit depends. It will
+# be used in the post-bootstrap phase.
+BOOT_GHC_DEPS:=                curses iconv
+BOOT_GHC_PKGSRC_DEPS:= # empty
+.for pkg in ${BOOT_GHC_DEPS}
+
+# NOTE: pkglint(1) complains for including these builtin.mk files,
+# telling that we must include buildlink3.mk instead. But then how do
+# we get variables like USE_BUILTIN.${pkg} defined before including
+# ../../mk/bsd.pkg.mk, given that ../../mk/bsd.buildlink3.mk isn't
+# protected against multiple inclusion?
+CHECK_BUILTIN.${pkg}:= yes
+.  if ${pkg} == "curses"
+.    include "../../mk/curses.builtin.mk"
+.  elif ${pkg} == "iconv"
+.    include "../../converters/libiconv/builtin.mk"
+.  endif
+CHECK_BUILTIN.${pkg}:= no
+
+# BOOT_GHC_PKGSRC_DEPS is a list of packages whose pkgsrc version is
+# preferred over native one, either by user or ../../mk/platform
+.  if ${PREFER.${pkg}} == "pkgsrc"
+BOOT_GHC_PKGSRC_DEPS+= ${pkg}
+.  endif
+.endfor
+
+# Compiler wrappers must not remove -I/-L flags for the installed
+# GHC's libdir, otherwise the stage-0 GHC (which we are going to use
+# for building our bootstraping kit) will not work. Ideally it should
+# be added to BUILDLINK_PASSTHRU_DIRS only .if make(bootstrap), but
+# then running "${MAKE} wrapper" before "${MAKE} bootstrap" will
+# result in a cryptic error which we can't easily catch.
+BOOT_GHC_LIBDIR_CMD=           ghc --print-libdir
+.if !defined(BOOT_GHC_LIBDIR)
+BOOT_GHC_LIBDIR!=              (${BOOT_GHC_LIBDIR_CMD}) 2>/dev/null || ${ECHO}
+.endif
+MAKEVARS+=                     BOOT_GHC_LIBDIR
+BUILDLINK_PASSTHRU_DIRS+=      ${BOOT_GHC_LIBDIR}
+
+# Default values for BUILDLINK_INCDIRS.<pkg> are only generated in the
+# barrier. See ../../mk/buildlink3/bsd.buildlink3.mk and
+# ../../mk/bsd.pkg.barrier.mk
+.PHONY: bootstrap
+BOOT_ARCHIVE.new=              ${BOOT_ARCHIVE:S/-${BOOT_VERSION}-/-${PKGVERSION_NOREV}-/}
+.if make(bootstrap)
+_BARRIER_CMDLINE_TARGETS+=     bootstrap
+.endif
+.if !defined(_PKGSRC_BARRIER)
+bootstrap: barrier
+.else
+bootstrap: pre-bootstrap .WAIT ${WRKDIR}/stamp-dist-boot .WAIT post-bootstrap
+.endif
+
+# For normal build we use pkgsrc libffi.so, but for bootkits we can't do
+# that because that would mean bootkits have run-time dependency on
+# it. However, building the bundled one isn't a solution either, because
+# pkgsrc libffi tends to be heavily patched to support our exotic
+# platforms. So we remove ${BUILDLINK_DIR}/lib/libffi.so just before we
+# build our bootkit so that the resulting executables link with the static
+# one.
+CONFIGURE_ARGS.boot=   ${CONFIGURE_ARGS.common}
+CONFIGURE_ARGS.boot+=  --with-bindist-prefix="ghc-boot-" --with-system-libffi
+
+# Hadrian arguments to use while building a bootkit.
+HADRIAN_ARGS.boot=     ${HADRIAN_ARGS}
+HADRIAN_ARGS.boot+=    --flavour=bootkit+split_sections --docs=none
+
+# Determine the version of GHC being used to build the bootkit. We will
+# need this to bootstrap Hadrian.
+.if make(bootstrap)
+BOOT_GHC_VERSION_CMD=  ghc --numeric-version
+BOOT_GHC_VERSION!=     (${BOOT_GHC_VERSION_CMD}) 2>/dev/null || ${ECHO}
+HADRIAN_BOOT_SOURCE:=  ghc-${BOOT_GHC_VERSION}-boot-hadrian.tar.gz
+.endif
+
+.PHONY: pre-bootstrap
+pre-bootstrap: wrapper
+.if empty(BOOT_GHC_LIBDIR)
+       ${RUN}if ${BOOT_GHC_LIBDIR_CMD} 2>/dev/null 1>&2; then \
+               ${ERROR_MSG} "Running \"${BOOT_GHC_LIBDIR_CMD}\" has failed during wrapper phase."; \
+               ${FAIL_MSG}  "Please run \"${MAKE} clean\" and try again."; \
+       else \
+               ${ERROR_MSG} "Failed to run \"${BOOT_GHC_LIBDIR_CMD}\":"; \
+               ${BOOT_GHC_LIBDIR_CMD}; \
+               ${ERROR_MSG} "You don't seem to have a working GHC in your PATH."; \
+               ${FAIL_MSG}  "Please install one and then run \"${MAKE} clean bootstrap\"."; \
+       fi
+.endif
+# ${_COOKIE.configure} is not defined yet so we can't use .if here.
+       ${RUN}if ${TEST} -f ${_COOKIE.configure}; then \
+               ${ERROR_MSG} "You have already configured the package in a way\
+                       that building bootstrapping compiler is impossible."; \
+               ${FAIL_MSG}  "Please run \"${MAKE} clean\" first."; \
+       fi
+
+${WRKDIR}/stamp-configure-boot:
+       @${PHASE_MSG} "Configuring bootstrapping compiler ${PKGNAME_NOREV}"
+       cd ${WRKSRC} && \
+               ${PKGSRC_SETENV} ${CONFIGURE_ENV} ${SH} ./configure ${CONFIGURE_ARGS.boot}
+       ${TOUCH} ${.TARGET}
+
+${WRKDIR}/stamp-build-boot: ${WRKDIR}/stamp-configure-boot
+       ${RUN}${TEST} -f ${DISTDIR}/${DIST_SUBDIR}/${HADRIAN_BOOT_SOURCE} || \
+               ${FAIL_MSG} "${HADRIAN_BOOT_SOURCE} not found in ${DISTDIR}/${DIST_SUBDIR}.\
+                       You first need to create it before building the bootkit.\
+                       See ./files/BOOTSTRAP.md for details."
+
+       @${PHASE_MSG} "Building Hadrian for ${BOOT_GHC_VERSION}"
+       ${CP} -f ${FILESDIR}/UserSettings.hs ${WRKSRC}/hadrian/
+       cd ${WRKSRC}/hadrian/bootstrap && \
+               python bootstrap.py -s ${DISTDIR}/${DIST_SUBDIR}/${HADRIAN_BOOT_SOURCE}
+
+       @${PHASE_MSG} "Building bootstrapping compiler ${PKGNAME_NOREV}"
+       for f in ${BUILDLINK_DIR:Q}/lib/libffi.*; do \
+               case "$$f" in \
+                       *.a) :;; \
+                       *)   ${RM} -f "$$f";; \
+               esac; \
+       done
+       cd ${WRKSRC} && ${HADRIAN_CMD} ${HADRIAN_ARGS.boot}
+       ${TOUCH} ${.TARGET}
+
+${WRKDIR}/stamp-dist-boot: ${WRKDIR}/stamp-build-boot
+       @${PHASE_MSG} "Creating binary distribution of bootstrapping ${PKGNAME_NOREV}"
+       cd ${WRKSRC} && ${HADRIAN_CMD} ${HADRIAN_ARGS.boot} binary-dist
+       ${MV} -f ${WRKSRC}/_build/bindist/${BOOT_ARCHIVE.new} ${WRKDIR}/${BOOT_ARCHIVE.new}
+
+.PHONY: post-bootstrap
+post-bootstrap:
+       @${ECHO} "=========================================================================="
+       @${ECHO} "Done creating ${BOOT_ARCHIVE.new}"
+       @${ECHO} "  in ${WRKDIR}"
+       @${ECHO}
+       @${ECHO} "Now you can copy it into ${DISTDIR}/${DIST_SUBDIR} to use as your"
+       @${ECHO} "bootstrap kit. You may want to take a backup in case \"lintpkgsrc -r\""
+       @${ECHO} "removes it."
+       @${ECHO}
+       @${ECHO} "Your bootstrap kit has the following run-time dependencies:"
+.for pkg in ${BOOT_GHC_DEPS}
+       @${PRINTF} "  * %-8s" "${pkg}:"
+.  if ${USE_BUILTIN.${pkg}:tl} == no
+       @${ECHO_N} " pkgsrc ${BUILDLINK_PKGNAME.${pkg}}"
+.  else
+       @${ECHO_N} " native"
+.    if empty(BUILTIN_PKG.${pkg})
+       @${ECHO_N} " (version/variant unknown)"
+.    else
+       @${ECHO_N} " ${BUILTIN_PKG.${pkg}}"
+.    endif
+.  endif
+       @${ECHO}
+.endfor
+.if !empty(BOOT_GHC_PKGSRC_DEPS)
+       @${ECHO}
+       @${ECHO} "Please note that it is generally not a good idea for a bootkit to depend"
+       @${ECHO} "on pkgsrc packages, as pkgsrc tends to move faster than operating systems"
+       @${ECHO} "so your bootkit may bitrot more quickly. You may want to rebuild it"
+       @${ECHO} "without setting PREFER_PKGSRC to \"yes\"."
+.endif
+       @${ECHO} "=========================================================================="
Index: pkgsrc/lang/ghc94/buildlink3.mk
diff -u /dev/null pkgsrc/lang/ghc94/buildlink3.mk:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/buildlink3.mk     Sat Jan 21 04:49:25 2023
@@ -0,0 +1,18 @@
+# $NetBSD: buildlink3.mk,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+BUILDLINK_TREE+=       ghc
+
+.if !defined(GHC_BUILDLINK3_MK)
+GHC_BUILDLINK3_MK:=
+
+BUILDLINK_API_DEPENDS.ghc+=    ghc>=9.4.4
+BUILDLINK_ABI_DEPENDS.ghc+=    ghc>=9.4.4
+BUILDLINK_PKGSRCDIR.ghc?=      ../../lang/ghc94
+
+.include "../../converters/libiconv/buildlink3.mk"
+.include "../../devel/libffi/buildlink3.mk"
+.include "../../devel/gmp/buildlink3.mk"
+.include "../../mk/curses.buildlink3.mk"
+.endif # GHC_BUILDLINK3_MK
+
+BUILDLINK_TREE+=       -ghc
Index: pkgsrc/lang/ghc94/distinfo
diff -u /dev/null pkgsrc/lang/ghc94/distinfo:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/distinfo  Sat Jan 21 04:49:25 2023
@@ -0,0 +1,66 @@
+$NetBSD: distinfo,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+BLAKE2s (ghc-9.0.1-boot-hadrian.tar.gz) = fff7259676e3d0281c7e15e684b65dc04313c9bcb4d6161962325c3fcee08c7b
+SHA512 (ghc-9.0.1-boot-hadrian.tar.gz) = 02047ca0718a240ce702aeac16c2194b6bf73119dacb59816c1e9a631667e420e44c6ef6d5b83f225af3bd31e3ec3fc8f28e9a3cb22e86f63089110429759878
+Size (ghc-9.0.1-boot-hadrian.tar.gz) = 1473040 bytes
+BLAKE2s (ghc-9.0.1-boot-i386-unknown-freebsd.tar.xz) = 1dd13bbed8d4b873ccb1bed06706f41093ab616c6a63be8e59dfdfeab0af2b72
+SHA512 (ghc-9.0.1-boot-i386-unknown-freebsd.tar.xz) = f243d2a091dbaa670ecaac913266e428164064e5c73a2d4e96b603f16af94f3c4af4358e01c04d492de8ddd8c4b6d25ebe8b62b929b6191cd87f0f1d13873fde
+Size (ghc-9.0.1-boot-i386-unknown-freebsd.tar.xz) = 48912780 bytes
+BLAKE2s (ghc-9.0.1-boot-x86_64-apple-darwin.tar.xz) = 377b623a7fd13401376e07c6fe7e19db321bc9883156894af703d72524816f5f
+SHA512 (ghc-9.0.1-boot-x86_64-apple-darwin.tar.xz) = 1c2d8e1df4d8545068c453e8437e29f1528015ce056150d98827709c026fc23f5460887467d20321b1d32e3fffefe7081c068d702881184029d1c63c0adb25e4
+Size (ghc-9.0.1-boot-x86_64-apple-darwin.tar.xz) = 57551160 bytes
+BLAKE2s (ghc-9.0.1-boot-x86_64-unknown-freebsd.tar.xz) = 4957b6df3c21773d16477ff2d9fc6c4d41e3dee574a39d4672677cbea4f1aa64
+SHA512 (ghc-9.0.1-boot-x86_64-unknown-freebsd.tar.xz) = 01b196eca0a23b64687cb795601ca02a409ea0a1b2db48f5b9ab90a95a1db05a254ac92db43726f15382f4cc9e54052685959467a2925fb67ebe5f68570c1eca
+Size (ghc-9.0.1-boot-x86_64-unknown-freebsd.tar.xz) = 49644112 bytes
+BLAKE2s (ghc-9.0.1-boot-x86_64-unknown-solaris2.tar.xz) = c4fdba92d75ccfedc3c1c0a8a73720113b5c5c59ec27ce4aead8172b8345f570
+SHA512 (ghc-9.0.1-boot-x86_64-unknown-solaris2.tar.xz) = 92694ef783274f42800d899af4dd558087e3c2ce13e175558a23f5187c944333a2872cee1df9b14683903a0542954a8483c7413343aacaa2b1676d10a6d27a6d
+Size (ghc-9.0.1-boot-x86_64-unknown-solaris2.tar.xz) = 59903112 bytes
+BLAKE2s (ghc-9.2.1-boot-aarch64-unknown-netbsd.tar.xz) = a8b619b3bf7aa28dbbcc3f9a61fb7af6080b5f9e479cdaca1a9c8e343761f2f3
+SHA512 (ghc-9.2.1-boot-aarch64-unknown-netbsd.tar.xz) = 80692415f9380219bbd9aa70fda152f2b8d7dc6e5b296fae1afeac513c52a4485c188304c9a013390de1cf91c42baa300c624eae7c4ed2321428dd507dd7f9d0
+Size (ghc-9.2.1-boot-aarch64-unknown-netbsd.tar.xz) = 63303064 bytes
+BLAKE2s (ghc-9.2.1-boot-hadrian.tar.gz) = 363fea08f46524eab654b3225650be4938bd0404e8c44145381f97a0c4489dca
+SHA512 (ghc-9.2.1-boot-hadrian.tar.gz) = a006ab38df77bc22e51ee75808065ad75781f85eb52cae54ed8995942ba16e70f4d68d4097f2597bca09e8b7890858d0a28a0f66216e6a4b21a3c68bb8082c59
+Size (ghc-9.2.1-boot-hadrian.tar.gz) = 1501585 bytes
+BLAKE2s (ghc-9.2.1-boot-x86_64-unknown-netbsd.tar.xz) = 07ef9f58aefe6aa30984426ab3a15e7831e19f4fdf762d414f9dedb6cee5eb8a
+SHA512 (ghc-9.2.1-boot-x86_64-unknown-netbsd.tar.xz) = 2bf06b9d76972f09a3eba6e881a99ead8f0cbd1542f102d2159451313b42fa03aeee56cb6d1fbe4b40ec417eda4c4783ff9af9e84c3b2fbd2be31ed33ce52883
+Size (ghc-9.2.1-boot-x86_64-unknown-netbsd.tar.xz) = 53193220 bytes
+BLAKE2s (ghc-9.4.4-src.tar.xz) = d77e26d73dfd2c96130a17c89c9fa361d71493d228eab8e919e2b79ee1783f3f
+SHA512 (ghc-9.4.4-src.tar.xz) = 6c9df7279a30b546bbd30a330905b3bdec31531e1343aa24bad721792235472857153e7f5d8d79e109ed63a314a1a4a647b66510e91eba4627c6806ae5c1fca2
+Size (ghc-9.4.4-src.tar.xz) = 28564104 bytes
+BLAKE2s (netbsd-9.0-amd64-libterminfo.tar.gz) = cf57e942d3331df269d8668bc09c59e8a81fbdfa5bb6c671d758d367a23c84ce
+SHA512 (netbsd-9.0-amd64-libterminfo.tar.gz) = 79288d44b84df8848afc2cdfee628cc4fd1ec0334159403ef8ba994d617bc56a7114af3031198afb5f3b8f45c0463a848099431e32bc6725042908576b6f95b8
+Size (netbsd-9.0-amd64-libterminfo.tar.gz) = 27744 bytes
+SHA1 (patch-compiler_GHC_Driver_Pipeline_Execute.hs) = 8a86aabddfa4cc5dcff3bb9812010696fb6a16df
+SHA1 (patch-compiler_GHC_SysTools_Process.hs) = ceb26657516e207e22d555ec6f87f735344b0d08
+SHA1 (patch-configure.ac) = 985482ae70830ddbf1334c9c82a2cec78a34bb4c
+SHA1 (patch-hadrian_bindist_Makefile) = 9a2a708d200ee03a199e8626210b13174a5b3663
+SHA1 (patch-hadrian_bootstrap_bootstrap.py) = 0a0aec27437d3e8e034f6dcfc797e9f751ce85a6
+SHA1 (patch-hadrian_src_Builder.hs) = fc0d05c4a8b052dac87a8d2e7a6166f8779bd92a
+SHA1 (patch-hadrian_src_Oracles_Setting.hs) = 0790059f027fca3ee17c42d770a29c56cd0d4cde
+SHA1 (patch-hadrian_src_Rules_BinaryDist.hs) = fb908f74b8b619bccd673fbdb40b1c53ab7a51d8
+SHA1 (patch-hadrian_src_Settings_Builders_Ghc.hs) = e2913e9f83bb36bb0b432a24518c9b6ca2990c6a
+SHA1 (patch-hadrian_src_Settings_Default.hs) = 0e0278308ca4decac3fabd89831195b2a20c6eab
+SHA1 (patch-hadrian_src_Settings_Packages.hs) = ce0032960a7804950fb58feb7ddbc5dc8697f74a
+SHA1 (patch-libraries_Cabal_Cabal_src_Distribution_Simple_GHC.hs) = a8b2eeec9a469b43e611f79fbf5b080c1e05aa50
+SHA1 (patch-libraries_base_GHC_Event_KQueue.hsc) = 8ee5da667a241a05fde3c580d3dc9bdc05aa5f00
+SHA1 (patch-libraries_base_System_CPUTime_Posix_Times.hsc) = 2bfb779d534d12073287274ce5e90b99e457a860
+SHA1 (patch-libraries_base_System_Environment.hs) = 7d79a91f295915b4408d5f41d5405739d7189215
+SHA1 (patch-libraries_base_System_Environment_ExecutablePath.hsc) = d3c4f9c4fd3589e4a2e47d1e6c6648ccdb8a1df6
+SHA1 (patch-libraries_base_configure) = 4e02082cdfde8d927d12f3d2f3d98ace6d4ee116
+SHA1 (patch-libraries_ghc-boot_GHC_BaseDir.hs) = e3393294a27f5d33db07252cbae4308ba4a2d877
+SHA1 (patch-libraries_process_cbits_posix_fork__exec.c) = 9c942faf829a64a20237c788e8c8265179db55c7
+SHA1 (patch-libraries_terminfo_configure.ac) = c961bc2280c38b950888b9a34358738eae072abf
+SHA1 (patch-libraries_text_text.cabal) = 5cfa19359cbdca7c836abae60302addd5e3e4218
+SHA1 (patch-libraries_time_lib_Data_Time_Clock_Internal_CTimespec.hsc) = 588270767f8a9cbde0648fc99807891fef65d721
+SHA1 (patch-libraries_time_lib_Data_Time_Clock_Internal_CTimeval.hs) = 68914d012a98cc4a4a245efeabcb9143dba0246a
+SHA1 (patch-libraries_unix_System_Posix_Env.hsc) = e94936c139ca15d45cac4a7feb74a601567913ab
+SHA1 (patch-libraries_unix_System_Posix_Env_ByteString.hsc) = a579c00d7d5d7ffbb73f6499e09588d6417be123
+SHA1 (patch-libraries_unix_System_Posix_Files_Common.hsc) = 6efef280832d376915a8987e4e8aac283408f607
+SHA1 (patch-libraries_unix_System_Posix_Signals.hsc) = 49215dce493a6bbc440f91a3959e592f86fc779b
+SHA1 (patch-libraries_unix_include_execvpe.h) = 560c6e9b644687fad62e380f73f08359c48639a2
+SHA1 (patch-m4_fptools__set__haskell__platform__vars.m4) = 8c7a7ab965f4df8a68bedb35c32ee32c59ac2c94
+SHA1 (patch-rts_linker_MMap.c) = 8325e7714db4d2eff2cba35cc7dd9650ef75bc6d
+SHA1 (patch-rts_linker_MMap.h) = 8228fabcdaeb1511191da9fc614ff94d3eee8fbd
+SHA1 (patch-rts_rts.cabal.in) = 605e30da81e444046d00457fc3961025c2073615
+SHA1 (patch-utils_haddock_driver_Main.hs) = 26b015d3aef9fdff66e66c8e3d9a370a2dbd7067
+SHA1 (patch-utils_haddock_haddock.cabal) = 80b1ae7304afe14f117d0b432d5dda78e5b916c5
Index: pkgsrc/lang/ghc94/options.mk
diff -u /dev/null pkgsrc/lang/ghc94/options.mk:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/options.mk        Sat Jan 21 04:49:25 2023
@@ -0,0 +1,65 @@
+# $NetBSD: options.mk,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+PKG_OPTIONS_VAR=       PKG_OPTIONS.ghc
+
+.include "../../mk/bsd.prefs.mk"
+
+# GHC has a native implementation of codegen (NCG) for some platforms. On
+# those platforms LLVM is optional. It's a requirement anywhere else. See
+# compiler/GHC/Driver/Backend.hs
+#
+# The LLVM backend tends to produce slightly faster code than what NCG
+# produces, but it is much slower than NCG. It is therefore not the default
+# backend on platforms where NCG is available. On platforms where NCG is
+# available, LLVM should be disabled by default because it's a huge
+# dependency that takes hours to compile.
+#
+# Note that bootkits also require LLVM/Clang on platforms lacking NCG. This
+# can cause a transitional problem when a new compiler arrives with NCG for
+# a platform which used to lack one. In this case we have to either (1)
+# build a new bootkit for the platform with LLVM backend disabled, or (2)
+# reuse the old bootkit by putting llvm/clang in BUILD_DEPENDS (regardless
+# of user choice) and arrange parameters so that they are used only by the
+# stage-0 compiler. We don't have an infrastructure for (2), as it's not
+# worth the additional complexity, so (1) is the only option atm.
+
+GHC_NCG_SUPPORTED=     aarch64 i386 x86_64 powerpc powerpc64 sparc
+.if !empty(GHC_NCG_SUPPORTED:M${MACHINE_ARCH})
+PKG_SUPPORTED_OPTIONS+=        llvm
+GHC_LLVM_REQUIRED=     no
+.else
+GHC_LLVM_REQUIRED=     yes
+.endif
+
+.if !empty(PKG_SUPPORTED_OPTIONS)
+.  include "../../mk/bsd.options.mk"
+.endif
+
+.if !empty(PKG_OPTIONS:Mllvm) || ${GHC_LLVM_REQUIRED} == "yes"
+DEPENDS+=              llvm-[0-9]*:../../lang/llvm
+CONFIGURE_ARGS.common+=        LLC=${PREFIX:Q}/bin/llc
+CONFIGURE_ARGS.common+=        OPT=${PREFIX:Q}/bin/opt
+
+# When we use the LLVM backend, we *have* to use Clang's integrated
+# assembler because llc emits assembly source files incompatible with
+# Binutils < 2.36 (see https://reviews.llvm.org/D97448). It also requires
+# Clang on Darwin (see runClang in compiler/GHC/SysTools/Tasks.hs).
+DEPENDS+=              clang-[0-9]*:../../lang/clang
+CONFIGURE_ARGS.common+=        CLANG=${PREFIX:Q}/bin/clang
+CONFIGURE_ARGS.common+=        CC=${PREFIX:Q}/bin/clang
+
+# Maybe GHC doesn't like this but it's the only option available to us.
+LLVM_VERSION_CMD=      ${PKG_INFO} -E llvm | ${SED} -E 's/^llvm-([0-9]*)\..*/\1/'
+LLVM_MAX_VERSION_CMD=  ${EXPR} ${LLVM_VERSION_CMD:sh} + 1
+SUBST_CLASSES+=                llvm
+SUBST_STAGE.llvm=      post-extract
+SUBST_MESSAGE.llvm=    Modifying configure.ac to accept whichever version of LLVM installed via pkgsrc
+SUBST_FILES.llvm=      configure.ac
+SUBST_SED.llvm=                -e 's/LlvmMaxVersion=[0-9]*/LlvmMaxVersion=${LLVM_MAX_VERSION_CMD:sh}/'
+
+.else
+CONFIGURE_ARGS.common+=        LLC=${FALSE:Q}
+CONFIGURE_ARGS.common+=        OPT=${FALSE:Q}
+CONFIGURE_ARGS.common+=        CLANG=${FALSE:Q}
+CONFIGURE_ARGS.common+=        CC=${CC:Q}
+.endif

Index: pkgsrc/lang/ghc94/files/BOOTSTRAP.md
diff -u /dev/null pkgsrc/lang/ghc94/files/BOOTSTRAP.md:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/files/BOOTSTRAP.md        Sat Jan 21 04:49:25 2023
@@ -0,0 +1,90 @@
+<!-- $NetBSD: BOOTSTRAP.md,v 1.1 2023/01/21 04:49:25 pho Exp $ -->
+
+# We need GHC to build GHC
+
+GHC requires itself to build, and unfortunately the only way to get a
+working GHC for a foreign target is to do a cross-compilation.
+
+In order to build a bootkit for a new platform, you need to manually set up
+a cross-building C compiler and binutils, libc, libterminfo, and libiconv
+for the target. Then you can follow instructions in
+https://gitlab.haskell.org/ghc/ghc/wikis/building/cross-compiling
+
+Once you get a working GHC for the target platform, install it somewhere in
+your PATH, run "bmake clean; bmake bootstrap" on the target platform and
+you'll have a bootkit for the target. *But read a note below on the build
+system.*
+
+
+## The build system "Hadrian" is also written in Haskell
+
+[Migrating from Make to Hadrian (for
+packagers)](https://www.haskell.org/ghc/blog/20220805-make-to-hadrian.html)
+
+GHC devs had used GNU Make to build GHC for decades, but its Makefiles had
+grown unwieldy to the point where maintenance was virtually
+impossible. They were in need of something more expressive than Make and
+eventually developed their own build system named Hadrian, which is written
+in Haskell. Unfortunately to us, this makes our lives harder for three
+reasons:
+
+1. Haskell libraries required to build Hadrian isn't bundled with GHC. We
+   either need to use `misc/cabal-install` to fetch them (which isn't an
+   option because we can't build cabal-install without GHC), or use a
+   separate source tarball to bootstrap Hadrian.
+2. The source tarball of Hadrian dependencies is specific to bootkit
+   version. That is, if we are to use GHC 9.2.1 as our bootkit, we need a
+   source tarball specific to GHC 9.2.1.
+3. The required tarballs aren't distributed officially. We must roll them
+   in our own hand. But in order to do it you need a working instance of
+   `misc/cabal-install`.
+
+So we must provide not only GHC bootkits but also Hadrian deps tarballs in
+our LOCAL_PORTS.
+
+
+### How to create `HADRIAN_BOOT_SOURCE` for your bootkit
+
+The name of Hadrian deps tarball is defined as `${HADRIAN_BOOT_SOURCE}` in
+`bootstrap.mk`. If you find one in our LOCAL_PORTS it means someone has
+already created it and you don't need to do anything special. It is
+platform-independent. It's only tied with a specific version of GHC. Just
+do `bmake` and it will first bootstrap Hadrian and then use it to build the
+entire package. If not, you have to create a tarball specific to your
+bootkit version.
+
+First, check if GHC has a so-called "build plan" in
+`${WRKSRC}/hadrian/bootstrap`. If you find
+`plan-bootstrap-${BOOT_VERSION}.json` for your bootkit version then you can
+skip this step. If not, install `misc/cabal-install` and do:
+
+```
+% cd ${WRKSRC}/hadrian
+% cabal configure
+% cd ./bootstrap
+% cabal build --allow-newer
+% cp ../dist-newstyle/cache/plan.json plan-${BOOT_VERSION}.json
+% cabal run -v0 -- plan-${BOOT_VERSION}.json | \
+      tee plan-bootstrap-${BOOT_VERSION}.json
+```
+
+Now you have a build plan. Create a tarball like so:
+
+```
+% cd ${WRKSRC}/hadrian/bootstrap
+% ./bootstrap.py --deps plan-bootstrap-${BOOT_VERSION}.json fetch \
+      -o ghc-${BOOT_VERSION}-boot-hadrian
+```
+
+Now you have `ghc-${BOOT_VERSION}-boot-hadrian.tar.gz` that is necessary to
+bootstrap Hadrian with your bootkit. Copy it to `${DISTDIR}`, and if you're
+a pkgsrc developer place it in LOCAL_PORTS.
+
+## HC files in ancient times, where have they gone?
+
+GHC in fact has never supported bootstrapping only with a C compiler.
+Prior to GHC 7, it had a thing called "HC source", which was a set of C
+source files compiled from Haskell source, but it wasn't actually
+cross-platform. It was because HC files were generated with many
+assumptions about the platform, such as the layout of libc structs, the
+size of `off_t` and `time_t`, byte-order, word size, etc.
Index: pkgsrc/lang/ghc94/files/UserSettings.hs
diff -u /dev/null pkgsrc/lang/ghc94/files/UserSettings.hs:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/files/UserSettings.hs     Sat Jan 21 04:49:25 2023
@@ -0,0 +1,66 @@
+-- $NetBSD: UserSettings.hs,v 1.1 2023/01/21 04:49:25 pho Exp $
+--
+-- This is a Hadrian settings file to override some defaults in a way which
+-- isn't possible through command-line options. It is only used during the
+-- build of bootkits. Options for regular builds are passed via command
+-- line.
+
+module UserSettings (
+    userFlavours, userPackages, userDefaultFlavour,
+    verboseCommand, buildProgressColour, successColour, finalStage
+    ) where
+
+import Flavour.Type
+import Expression
+import {-# SOURCE #-} Settings.Default
+
+-- See ${WRKSRIC}/hadrian/doc/user-settings.md for instructions.
+
+userDefaultFlavour :: String
+userDefaultFlavour = "default"
+
+userFlavours :: [Flavour]
+userFlavours = [bootkitFlavour]
+
+-- It is preferred to use this flavour with "split_sections" transformer,
+-- e.g. --flavour=bootkit+split_sections
+bootkitFlavour :: Flavour
+bootkitFlavour =
+  defaultFlavour
+  { name               = "bootkit"
+    -- We don't want in-tree GMP to be statically linked as it increases
+    -- the bindist size. Dynamic linkage is even worse.
+  , bignumBackend      = "native"
+    -- We only want vanilla libraries and RTS. No profiling, no shared
+    -- libraries, no debugging.
+  , libraryWays        = pure [vanilla]
+  , rtsWays            = pure [vanilla]
+    -- Don't build or use dynamic Haskell libraries.
+  , dynamicGhcPrograms = pure False
+    -- Build GHC as minimally as possible.
+  , ghciWithDebugger   = False
+  , ghcProfiled        = False
+  , ghcDebugged        = False
+  , ghcDebugAssertions = False
+  , ghcThreaded        = False
+    -- This is a bootstrap compiler. We don't want any kinds of
+    -- documentation.
+  , ghcDocs            = pure mempty
+  }
+
+userPackages :: [Package]
+userPackages = []
+
+verboseCommand :: Predicate
+verboseCommand = do
+    verbosity <- expr getVerbosity
+    return $ verbosity >= Verbose
+
+buildProgressColour :: BuildProgressColour
+buildProgressColour = mkBuildProgressColour (Dull Magenta)
+
+successColour :: SuccessColour
+successColour = mkSuccessColour (Dull Green)
+
+finalStage :: Stage
+finalStage = Stage2

Index: pkgsrc/lang/ghc94/patches/patch-compiler_GHC_Driver_Pipeline_Execute.hs
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-compiler_GHC_Driver_Pipeline_Execute.hs:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-compiler_GHC_Driver_Pipeline_Execute.hs     Sat Jan 21 04:49:25 2023
@@ -0,0 +1,17 @@
+$NetBSD: patch-compiler_GHC_Driver_Pipeline_Execute.hs,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+This is pkgsrc-specific. Do not use -Xpreprocessor to pass options to
+CPP. Our tool wrappers may remove some of them, and if that happens an
+unpaired -Xpreprocessor will be left behind and confuses CC.
+
+--- compiler/GHC/Driver/Pipeline/Execute.hs.orig       2022-12-23 16:19:02.000000000 +0000
++++ compiler/GHC/Driver/Pipeline/Execute.hs
+@@ -373,7 +373,7 @@ runCcPhase cc_phase pipe_env hsc_env inp
+       aug_imports = augmentImports dflags opts
+ 
+       more_preprocessor_opts = concat
+-        [ ["-Xpreprocessor", i]
++        [ [ i ]
+         | not hcc
+         , i <- aug_imports
+         ]
Index: pkgsrc/lang/ghc94/patches/patch-compiler_GHC_SysTools_Process.hs
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-compiler_GHC_SysTools_Process.hs:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-compiler_GHC_SysTools_Process.hs    Sat Jan 21 04:49:25 2023
@@ -0,0 +1,32 @@
+$NetBSD: patch-compiler_GHC_SysTools_Process.hs,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+This is more like pkgsrc-specific than an upstream issue. Unless we
+are on Windows, don't use "response file", the @FILE syntax while
+invoking CC or LD. Our tool wrappers don't look into response files,
+and therefore can't detect mistakes like depending on Cabal packages
+that aren't declared as pkgsrc dependency.
+
+Note that this patch would break GHC if we didn't have its $ORIGIN use
+eliminated because our wrappers hate relative rpaths.
+
+--- compiler/GHC/SysTools/Process.hs.orig      2022-12-23 16:19:02.000000000 +0000
++++ compiler/GHC/SysTools/Process.hs
+@@ -160,6 +160,7 @@ runSomethingResponseFile
+   -> [Option]
+   -> Maybe [(String,String)]
+   -> IO ()
++#if defined(mingw32_HOST_OS)
+ runSomethingResponseFile logger tmpfs dflags filter_fn phase_name pgm args mb_env =
+     runSomethingWith logger phase_name pgm args $ \real_args -> do
+         fp <- getResponseFile real_args
+@@ -198,6 +199,10 @@ runSomethingResponseFile logger tmpfs df
+             x
+         , "\""
+         ]
++#else
++runSomethingResponseFile logger tmpfs dflags filter_fn phase_name pgm args mb_env =
++  runSomethingFiltered logger filter_fn phase_name pgm args Nothing mb_env
++#endif
+ 
+ runSomethingFiltered
+   :: Logger -> (String->String) -> String -> String -> [Option]
Index: pkgsrc/lang/ghc94/patches/patch-configure.ac
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-configure.ac:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-configure.ac        Sat Jan 21 04:49:25 2023
@@ -0,0 +1,17 @@
+$NetBSD: patch-configure.ac,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Hunk #0:
+    Disable DTrace support on solaris2.
+    XXX: But why?
+
+--- configure.ac.orig  2022-12-23 16:19:02.000000000 +0000
++++ configure.ac
+@@ -800,7 +800,7 @@ if test "x$EnableDtrace" = "xyes"; then
+   if test -n "$DtraceCmd"; then
+     if test "x$TargetOS_CPP-$TargetVendor_CPP" = "xdarwin-apple" \
+       -o "x$TargetOS_CPP-$TargetVendor_CPP" = "xfreebsd-portbld" \
+-      -o "x$TargetOS_CPP-$TargetVendor_CPP" = "xsolaris2-unknown"; then
++      ; then
+       HaveDtrace=YES
+     fi
+   fi
Index: pkgsrc/lang/ghc94/patches/patch-hadrian_bindist_Makefile
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-hadrian_bindist_Makefile:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-hadrian_bindist_Makefile    Sat Jan 21 04:49:25 2023
@@ -0,0 +1,17 @@
+$NetBSD: patch-hadrian_bindist_Makefile,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Don't run `ghc-pkg recache' while installing a binary distribution. See
+also "do-install" in Makefile.
+
+--- hadrian/bindist/Makefile.orig      2023-01-12 03:34:04.854847389 +0000
++++ hadrian/bindist/Makefile
+@@ -213,7 +213,9 @@ update_package_db: install_bin install_l
+       @echo "Updating the package DB"
+       $(foreach p, $(PKG_CONFS),\
+               $(call patchpackageconf,$(shell echo $(notdir $p) | sed 's/-\([0-9]*[0-9]\.\)*conf//g'),$(shell echo "$p" | sed 's:\0xxx\0:   :g'),$(docdir),$(shell mk/relpath.sh "$(ActualLibsDir)" 
"$(docdir)"),$(shell echo $(notdir $p) | sed 's/.conf//g')))
++ifneq "$(RECACHE_PACKAGE_DB)" "NO"
+       '$(DESTDIR)$(ActualBinsDir)/$(CrossCompilePrefix)ghc-pkg' --global-package-db "$(DESTDIR)$(ActualLibsDir)/package.conf.d" recache
++endif
+ 
+ install_mingw:
+       @echo "Installing MingGW"
Index: pkgsrc/lang/ghc94/patches/patch-hadrian_bootstrap_bootstrap.py
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-hadrian_bootstrap_bootstrap.py:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-hadrian_bootstrap_bootstrap.py      Sat Jan 21 04:49:25 2023
@@ -0,0 +1,61 @@
+$NetBSD: patch-hadrian_bootstrap_bootstrap.py,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+bootstrap.py assumes that GHC always has a threaded RTS but our bootkits
+don't. It is debatable at least as to whether this should be upstreamed.
+
+--- hadrian/bootstrap/bootstrap.py.orig        2022-12-23 16:19:02.000000000 +0000
++++ hadrian/bootstrap/bootstrap.py
+@@ -180,7 +180,44 @@ def install_dep(dep: BootstrapDep, ghc: 
+ 
+     sdist_dir = resolve_dep(dep)
+ 
+-    install_sdist(dist_dir, sdist_dir, ghc, dep.flags)
++    # Some packages are going to be built with threaded RTS, which is
++    # impossible in our case.
++    flags = [flag.replace("+threaded", "-threaded") for flag in dep.flags]
++
++    # "shake" is worse. It tries to build an unneeded executable with
++    # hard-coded "-thread". The only way to disable it is to modify its
++    # .cabal file here.
++    if dep.package == "shake":
++        with open(sdist_dir / f'{dep.package}.cabal', 'r') as cabal_file:
++            cabal = cabal_file.read()
++        cabal = cabal.replace("executable shake\n", "executable shake\n    buildable: False\n")
++        with open(sdist_dir / f'{dep.package}.cabal', 'w') as cabal_file:
++            cabal_file.write(cabal)
++
++    # This is a temporary workaround for aarch64 codegen bug in 9.2.1. Once
++    # we update our bootkit for aarch64 we can remove
++    # this. https://gitlab.haskell.org/ghc/ghc/-/issues/20594
++    if dep.package == "QuickCheck":
++        with open(sdist_dir / f'{dep.package}.cabal', 'r') as cabal_file:
++            cabal = cabal_file.read()
++        cabal = cabal.replace("ö", "o")
++        with open(sdist_dir / f'{dep.package}.cabal', 'w') as cabal_file:
++            cabal_file.write(cabal)
++
++    # Same as above
++    if dep.package == "clock":
++        with open(sdist_dir / f'{dep.package}.cabal', 'r') as cabal_file:
++            cabal = cabal_file.read()
++        cabal = cabal.replace("©", "(c)")
++        with open(sdist_dir / f'{dep.package}.cabal', 'w') as cabal_file:
++            cabal_file.write(cabal)
++
++    # If it's from Hackage and we've already installed it, don't do it
++    # twice. That only wastes time.
++    stamp = sdist_dir / 'bootstrap-done'
++    if dep.source == PackageSource.LOCAL or not stamp.exists():
++        install_sdist(dist_dir, sdist_dir, ghc, flags)
++        stamp.touch()
+ 
+ def install_sdist(dist_dir: Path, sdist_dir: Path, ghc: Compiler, flags: List[str]):
+     prefix = PSEUDOSTORE.resolve()
+@@ -459,6 +496,7 @@ Alternatively, you could use `bootstrap.
+           fetch_from_plan(plan, TARBALLS)
+ 
+         bootstrap(info, ghc)
++        return # Don't waste time by creating an archive.
+         hadrian_path = (BINDIR / 'hadrian').resolve()
+ 
+         archive = make_archive(hadrian_path)
Index: pkgsrc/lang/ghc94/patches/patch-hadrian_src_Builder.hs
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-hadrian_src_Builder.hs:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-hadrian_src_Builder.hs      Sat Jan 21 04:49:25 2023
@@ -0,0 +1,32 @@
+$NetBSD: patch-hadrian_src_Builder.hs,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+We build haddock as a dynamically-linked executable but it doesn't contain
+an rpath to our not-yet-installed shared libraries. This is usually not a
+problem because Hadrian embeds relative rpaths (i.e. $ORIGIN) in
+dynamically-linked objects but we patch Hadrian not to do that.
+
+--- hadrian/src/Builder.hs.orig        2023-01-11 18:03:24.816170940 +0000
++++ hadrian/src/Builder.hs
+@@ -31,6 +31,7 @@ import Hadrian.Utilities
+ import Oracles.Setting (bashPath)
+ import System.Exit
+ import System.IO (stderr)
++import System.Directory (makeAbsolute)
+ 
+ import Base
+ import Context
+@@ -381,6 +382,14 @@ instance H.Builder Builder where
+                   when (code /= ExitSuccess) $ do
+                     fail "tests failed"
+ 
++                Haddock _ -> do
++                  libPath'  <- libPath (vanillaContext Stage1 haddock)
++                  distDir'  <- distDir Stage1
++                  shlibPath <- liftIO $ makeAbsolute (libPath' -/- distDir')
++                  let envs = [ AddEnv "LD_LIBRARY_PATH" shlibPath
++                             , AddEnv "DYLD_LIBRARY_PATH" shlibPath ] -- Darwin
++                  cmd' envs [path] buildArgs
++
+                 _  -> cmd' [path] buildArgs
+ 
+ -- TODO: Some builders are required only on certain platforms. For example,
Index: pkgsrc/lang/ghc94/patches/patch-hadrian_src_Oracles_Setting.hs
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-hadrian_src_Oracles_Setting.hs:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-hadrian_src_Oracles_Setting.hs      Sat Jan 21 04:49:25 2023
@@ -0,0 +1,40 @@
+$NetBSD: patch-hadrian_src_Oracles_Setting.hs,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Hadrian's idea of rpath usability is overly pessimistic. If it's an ELF or
+a Mach-O target we should assume it supports rpaths. Not upstreamed yet.
+
+--- hadrian/src/Oracles/Setting.hs.orig        2023-01-15 17:18:47.276886521 +0000
++++ hadrian/src/Oracles/Setting.hs
+@@ -269,20 +269,28 @@ anyTargetArch = matchSetting TargetArch
+ anyHostOs :: [String] -> Action Bool
+ anyHostOs = matchSetting HostOs
+ 
+--- | Check whether the target OS uses the ELF object format.
+-isElfTarget :: Action Bool
+-isElfTarget = anyTargetOs
++-- | List of OSes that use the ELF object format.
++elfOSes :: [String]
++elfOSes =
+     [ "linux", "freebsd", "dragonfly", "openbsd", "netbsd", "solaris2", "kfreebsdgnu"
+     , "haiku", "linux-android"
+     ]
+ 
++-- | List of OSes that use the Mach-O object format.
++machoOSes :: [String]
++machoOSes = [ "darwin" ]
++
++-- | Check whether the target OS uses the ELF object format.
++isElfTarget :: Action Bool
++isElfTarget = anyTargetOs elfOSes
++
+ -- | Check whether the host OS supports the @-rpath@ linker option when
+ -- using dynamic linking.
+ --
+ -- TODO: Windows supports lazy binding (but GHC doesn't currently support
+ --       dynamic way on Windows anyways).
+ hostSupportsRPaths :: Action Bool
+-hostSupportsRPaths = anyHostOs ["linux", "darwin", "freebsd"]
++hostSupportsRPaths = anyHostOs (elfOSes ++ machoOSes)
+ 
+ -- | Check whether the target supports GHCi.
+ ghcWithInterpreter :: Action Bool
Index: pkgsrc/lang/ghc94/patches/patch-hadrian_src_Rules_BinaryDist.hs
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-hadrian_src_Rules_BinaryDist.hs:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-hadrian_src_Rules_BinaryDist.hs     Sat Jan 21 04:49:25 2023
@@ -0,0 +1,73 @@
+$NetBSD: patch-hadrian_src_Rules_BinaryDist.hs,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Hunk #0, #1, #3:
+    Distinguish bootstrapping bindists from regular ones. This is
+    pkgsrc-specific.
+
+Hunk #2:
+    Do not run `ghc-pkg recache' while creating a binary distribution. We
+    don't want a package cache to be installed because we do it in our
+    INSTALL script. Also it's not possible to run ghc-pkg in the first
+    place without setting LD_LIBRARY_PATH since we don't build relocatable
+    executables. This is pkgsrc-specific.
+
+Hunk #4:
+    We want our bootkits to be as small as possible, even though `xz -9e'
+    is very slow and consumes about 680 MiB of memory. This is
+    pkgsrc-specific.
+
+--- hadrian/src/Rules/BinaryDist.hs.orig       2022-12-23 16:19:02.000000000 +0000
++++ hadrian/src/Rules/BinaryDist.hs
+@@ -113,7 +113,7 @@ bindistRules = do
+         need ["binary-dist-dir"]
+         version        <- setting ProjectVersion
+         targetPlatform <- setting TargetPlatformFull
+-        let ghcVersionPretty = "ghc-" ++ version ++ "-" ++ targetPlatform
++        let ghcVersionPretty = "ghc-" ++ version ++ "-boot-" ++ targetPlatform
+             bindistFilesDir  = root -/- "bindist" -/- ghcVersionPretty
+             prefixErr = "You must specify a path with --prefix when using the"
+                      ++ " 'install' rule"
+@@ -136,7 +136,7 @@ bindistRules = do
+ 
+         let ghcBuildDir      = root -/- stageString Stage1
+             bindistFilesDir  = root -/- "bindist" -/- ghcVersionPretty
+-            ghcVersionPretty = "ghc-" ++ version ++ "-" ++ targetPlatform
++            ghcVersionPretty = "ghc-" ++ version ++ "-boot-" ++ targetPlatform
+             rtsIncludeDir    = ghcBuildDir -/- "lib" -/- distDir -/- rtsDir
+                                -/- "include"
+ 
+@@ -194,16 +194,6 @@ bindistRules = do
+         copyDirectory (rtsIncludeDir)         bindistFilesDir
+         when windowsHost $ createGhcii (bindistFilesDir -/- "bin")
+ 
+-        -- Call ghc-pkg recache, after copying so the package.cache is
+-        -- accurate, then it's on the distributor to use `cp -a` to install
+-        -- a relocatable bindist.
+-        --
+-        -- N.B. the ghc-pkg executable may be prefixed with a target triple
+-        -- (c.f. #20267).
+-        ghcPkgName <- programName (vanillaContext Stage1 ghcPkg)
+-        cmd_ (bindistFilesDir -/- "bin" -/- ghcPkgName) ["recache"]
+-
+-
+         -- The settings file must be regenerated by the bindist installation
+         -- logic to account for the environment discovered by the bindist
+         -- configure script on the host. Not on Windows, however, where
+@@ -279,7 +269,7 @@ bindistRules = do
+             version        <- setting ProjectVersion
+             targetPlatform <- setting TargetPlatformFull
+ 
+-            let ghcVersionPretty = "ghc-" ++ version ++ "-" ++ targetPlatform
++            let ghcVersionPretty = "ghc-" ++ version ++ "-boot-" ++ targetPlatform
+ 
+             -- Finally, we create the archive <root>/bindist/ghc-X.Y.Z-platform.tar.xz
+             tarPath <- builderPath (Tar Create)
+@@ -332,7 +322,7 @@ data Compressor = Gzip | Bzip2 | Xz
+ -- | Flag to pass to tar to use the given 'Compressor'.
+ compressorTarFlag :: Compressor -> String
+ compressorTarFlag Gzip  = "--gzip"
+-compressorTarFlag Xz    = "--xz"
++compressorTarFlag Xz    = "--use-compress-program=xz --verbose -9 --extreme"
+ compressorTarFlag Bzip2 = "--bzip"
+ 
+ -- | File extension to use for archives compressed with the given 'Compressor'.
Index: pkgsrc/lang/ghc94/patches/patch-hadrian_src_Settings_Builders_Ghc.hs
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-hadrian_src_Settings_Builders_Ghc.hs:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-hadrian_src_Settings_Builders_Ghc.hs        Sat Jan 21 04:49:25 2023
@@ -0,0 +1,75 @@
+$NetBSD: patch-hadrian_src_Settings_Builders_Ghc.hs,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Don't use rpaths relative to $ORIGIN. Use the final installation path. This
+is pkgsrc-specific.
+
+--- hadrian/src/Settings/Builders/Ghc.hs.orig  2022-12-23 16:19:02.000000000 +0000
++++ hadrian/src/Settings/Builders/Ghc.hs
+@@ -5,6 +5,7 @@ module Settings.Builders.Ghc (ghcBuilder
+ import Hadrian.Haskell.Cabal
+ import Hadrian.Haskell.Cabal.Type
+ 
++import CommandLine
+ import Flavour
+ import Packages
+ import Settings.Builders.Common
+@@ -104,10 +105,10 @@ ghcLinkArgs = builder (Ghc LinkHs) ? do
+     fmwks   <- getContextData frameworks
+     way     <- getWay
+ 
+-    -- Relative path from the output (rpath $ORIGIN).
+-    originPath <- dropFileName <$> getOutput
+-    context <- getContext
+-    libPath' <- expr (libPath context)
++    -- Absolute rpath to the final destination.
++    fileName <- takeFileName <$> getOutput
++    prefix   <- fromMaybe (error "--prefix missing from the command line") <$> expr cmdPrefix
++    projVer  <- getSetting ProjectVersion
+     st <- getStage
+     distDir <- expr (Context.distDir st)
+ 
+@@ -121,17 +122,8 @@ ghcLinkArgs = builder (Ghc LinkHs) ? do
+ 
+     let
+         dynamic = Dynamic `wayUnit` way
+-        distPath = libPath' -/- distDir
+-        originToLibsDir = makeRelativeNoSysLink originPath distPath
+-        rpath
+-            -- Programs will end up in the bin dir ($ORIGIN) and will link to
+-            -- libraries in the lib dir.
+-            | isProgram pkg = metaOrigin -/- originToLibsDir
+-            -- libraries will all end up in the lib dir, so just use $ORIGIN
+-            | otherwise     = metaOrigin
+-            where
+-                metaOrigin | osxTarget = "@loader_path"
+-                           | otherwise = "$ORIGIN"
++        ghclibdir = prefix -/- "lib" -/- ("ghc-" ++ projVer)
++        rpath     = ghclibdir -/- "lib" -/- distDir
+ 
+         -- TODO: an alternative would be to generalize by linking with extra
+         -- bundled libraries, but currently the rts is the only use case. It is
+@@ -144,23 +136,13 @@ ghcLinkArgs = builder (Ghc LinkHs) ? do
+             , arg ("-l" ++ libffiName')
+             ]
+ 
+-        -- This is the -rpath argument that is required for the bindist scenario
+-        -- to work. Indeed, when you install a bindist, the actual executables
+-        -- end up nested somewhere under $libdir, with the wrapper scripts
+-        -- taking their place in $bindir, and 'rpath' therefore doesn't seem
+-        -- to give us the right paths for such a case.
+-        -- TODO: Could we get away with just one rpath...?
+-        bindistRpath = "$ORIGIN" -/- ".." -/- ".." -/- originToLibsDir
+-
+     mconcat [ dynamic ? mconcat
+                 [ arg "-dynamic"
+                 -- TODO what about windows?
+                 , isLibrary pkg ? pure [ "-shared", "-dynload", "deploy" ]
+                 , hostSupportsRPaths ? mconcat
+                       [ arg ("-optl-Wl,-rpath," ++ rpath)
+-                      , isProgram pkg ? arg ("-optl-Wl,-rpath," ++ bindistRpath)
+-                      -- The darwin and Windows linkers don't support/require the -zorigin option
+-                      , not (osxTarget || winTarget) ? arg "-optl-Wl,-zorigin"
++                      , isLibrary pkg ? pure ["-dylib-install-name", rpath -/- fileName]
+                       -- We set RPATH directly (relative to $ORIGIN). There's
+                       -- no reason for GHC to inject further RPATH entries.
+                       -- See #19485.
Index: pkgsrc/lang/ghc94/patches/patch-hadrian_src_Settings_Default.hs
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-hadrian_src_Settings_Default.hs:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-hadrian_src_Settings_Default.hs     Sat Jan 21 04:49:25 2023
@@ -0,0 +1,19 @@
+$NetBSD: patch-hadrian_src_Settings_Default.hs,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Do not build haddock with the stage-0 compiler. That's not only pointless
+but also impossible in our case because our bootkits in the pre-Hadrian era
+lack the xhtml package, which haddock depends on.
+
+Probably not eligible for upstreaming though, because regular GHC
+distributions of course have xhtml.
+
+--- hadrian/src/Settings/Default.hs.orig       2023-01-11 15:35:59.835839905 +0000
++++ hadrian/src/Settings/Default.hs
+@@ -86,7 +86,6 @@ stage0Packages = do
+              , ghcHeap
+              , ghci
+              , ghcPkg
+-             , haddock
+              , hsc2hs
+              , hpc
+              , hpcBin
Index: pkgsrc/lang/ghc94/patches/patch-hadrian_src_Settings_Packages.hs
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-hadrian_src_Settings_Packages.hs:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-hadrian_src_Settings_Packages.hs    Sat Jan 21 04:49:25 2023
@@ -0,0 +1,16 @@
+$NetBSD: patch-hadrian_src_Settings_Packages.hs,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Don't assume we always build the threaded RTS. Not upstreamed yet.
+
+--- hadrian/src/Settings/Packages.hs.orig      2023-01-11 04:48:46.860292356 +0000
++++ hadrian/src/Settings/Packages.hs
+@@ -387,7 +387,8 @@ rtsPackageArgs = package rts ? do
+ 
+     mconcat
+         [ builder (Cabal Flags) ? mconcat
+-          [ any (wayUnit Profiling) rtsWays `cabalFlag` "profiling"
++          [ any (wayUnit Threaded) rtsWays  `cabalFlag` "threaded"
++          , any (wayUnit Profiling) rtsWays `cabalFlag` "profiling"
+           , any (wayUnit Debug) rtsWays     `cabalFlag` "debug"
+           , any (wayUnit Dynamic) rtsWays   `cabalFlag` "dynamic"
+           , useSystemFfi                    `cabalFlag` "use-system-libffi"
Index: pkgsrc/lang/ghc94/patches/patch-libraries_Cabal_Cabal_src_Distribution_Simple_GHC.hs
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-libraries_Cabal_Cabal_src_Distribution_Simple_GHC.hs:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-libraries_Cabal_Cabal_src_Distribution_Simple_GHC.hs        Sat Jan 21 04:49:25 2023
@@ -0,0 +1,33 @@
+$NetBSD: patch-libraries_Cabal_Cabal_src_Distribution_Simple_GHC.hs,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Enable Cabal's rpath overriding functionality on all the platforms
+known to use ELF.
+
+When a Cabal package which defines both a library and an executable
+to be built, GHC by default embeds an rpath to the *build* directory
+into the executable. This may sound like a bug in GHC but is actually
+not, because GHC doesn't know the fact that the said library is going
+to be installed elsewhere. To overcome this issue, Cabal has a
+functionality to disable the default rpath handling of GHC and
+construct the correct set of rpaths... but only on certain platforms
+for some reason.
+
+Pull request: https://github.com/haskell/cabal/pull/7382
+
+--- libraries/Cabal/Cabal/src/Distribution/Simple/GHC.hs.orig  2022-01-21 02:23:32.884988700 +0000
++++ libraries/Cabal/Cabal/src/Distribution/Simple/GHC.hs
+@@ -1734,10 +1734,10 @@ getRPaths lbi clbi | supportRPaths hostO
+       case compid of
+         CompilerId GHC ver | ver >= mkVersion [7,10,2] -> True
+         _                                              -> False
+-    supportRPaths OpenBSD     = False
+-    supportRPaths NetBSD      = False
+-    supportRPaths DragonFly   = False
+-    supportRPaths Solaris     = False
++    supportRPaths OpenBSD     = True
++    supportRPaths NetBSD      = True
++    supportRPaths DragonFly   = True
++    supportRPaths Solaris     = True
+     supportRPaths AIX         = False
+     supportRPaths HPUX        = False
+     supportRPaths IRIX        = False
Index: pkgsrc/lang/ghc94/patches/patch-libraries_base_GHC_Event_KQueue.hsc
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-libraries_base_GHC_Event_KQueue.hsc:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-libraries_base_GHC_Event_KQueue.hsc Sat Jan 21 04:49:25 2023
@@ -0,0 +1,16 @@
+$NetBSD: patch-libraries_base_GHC_Event_KQueue.hsc,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Suppress linker warnings about compatibility syscall wrappers by using
+"capi" instead of "ccall".
+
+--- libraries/base/GHC/Event/KQueue.hsc.orig   2019-12-26 18:05:56.276488590 +0000
++++ libraries/base/GHC/Event/KQueue.hsc
+@@ -284,7 +284,7 @@ foreign import capi safe "sys/event.h ke
+     c_kevent :: KQueueFd -> Ptr Event -> CInt -> Ptr Event -> CInt
+              -> Ptr TimeSpec -> IO CInt
+ 
+-foreign import ccall unsafe "kevent"
++foreign import capi unsafe "sys/event.h kevent"
+     c_kevent_unsafe :: KQueueFd -> Ptr Event -> CInt -> Ptr Event -> CInt
+                     -> Ptr TimeSpec -> IO CInt
+ #else
Index: pkgsrc/lang/ghc94/patches/patch-libraries_base_System_CPUTime_Posix_Times.hsc
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-libraries_base_System_CPUTime_Posix_Times.hsc:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-libraries_base_System_CPUTime_Posix_Times.hsc       Sat Jan 21 04:49:25 2023
@@ -0,0 +1,16 @@
+$NetBSD: patch-libraries_base_System_CPUTime_Posix_Times.hsc,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Suppress linker warnings about compatibility syscall wrappers by using
+"capi" instead of "ccall".
+
+--- libraries/base/System/CPUTime/Posix/Times.hsc.orig 2020-01-04 12:08:39.515726533 +0000
++++ libraries/base/System/CPUTime/Posix/Times.hsc
+@@ -27,7 +27,7 @@ getCPUTime = allocaBytes (#const sizeof(
+                         `div` fromIntegral clockTicks)
+ 
+ type CTms = ()
+-foreign import ccall unsafe times :: Ptr CTms -> IO CClock
++foreign import capi unsafe "sys/times.h times" times :: Ptr CTms -> IO CClock
+ 
+ getCpuTimePrecision :: IO Integer
+ getCpuTimePrecision =
Index: pkgsrc/lang/ghc94/patches/patch-libraries_base_System_Environment.hs
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-libraries_base_System_Environment.hs:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-libraries_base_System_Environment.hs        Sat Jan 21 04:49:25 2023
@@ -0,0 +1,23 @@
+$NetBSD: patch-libraries_base_System_Environment.hs,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Suppress linker warnings about compatibility syscall wrappers by using
+"capi" instead of "ccall".
+
+--- libraries/base/System/Environment.hs.orig  2018-02-25 20:02:28.000000000 +0000
++++ libraries/base/System/Environment.hs
+@@ -1,5 +1,6 @@
+ {-# LANGUAGE Safe #-}
+ {-# LANGUAGE CPP #-}
++{-# LANGUAGE CApiFFI #-}
+ 
+ -----------------------------------------------------------------------------
+ -- |
+@@ -246,7 +247,7 @@ putEnv keyvalue = do
+   -- environment.
+   throwErrnoIf_ (/= 0) "putenv" (c_putenv s)
+ 
+-foreign import ccall unsafe "putenv" c_putenv :: CString -> IO CInt
++foreign import capi unsafe "stdlib.h putenv" c_putenv :: CString -> IO CInt
+ #endif
+ 
+ -- | @unsetEnv name@ removes the specified environment variable from the
Index: pkgsrc/lang/ghc94/patches/patch-libraries_base_System_Environment_ExecutablePath.hsc
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-libraries_base_System_Environment_ExecutablePath.hsc:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-libraries_base_System_Environment_ExecutablePath.hsc        Sat Jan 21 04:49:25 2023
@@ -0,0 +1,67 @@
+$NetBSD: patch-libraries_base_System_Environment_ExecutablePath.hsc,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Support executablePath on Solaris. Not upstreamed yet.
+
+--- libraries/base/System/Environment/ExecutablePath.hsc.orig  2023-01-14 16:23:19.153537486 +0000
++++ libraries/base/System/Environment/ExecutablePath.hsc
+@@ -38,6 +38,12 @@ import Data.List (isSuffixOf)
+ import Foreign.C
+ import Foreign.Marshal.Array
+ import System.Posix.Internals
++#elif defined(solaris2_HOST_OS)
++import Control.Exception (catch, throw)
++import Foreign.C
++import Foreign.Marshal.Array
++import System.IO.Error (isDoesNotExistError)
++import System.Posix.Internals
+ #elif defined(freebsd_HOST_OS) || defined(netbsd_HOST_OS)
+ import Control.Exception (catch, throw)
+ import Foreign.C
+@@ -92,7 +98,7 @@ getExecutablePath :: IO FilePath
+ --
+ -- If the operating system provides a reliable way to determine the current
+ -- executable, return the query action, otherwise return @Nothing@.  The action
+--- is defined on FreeBSD, Linux, MacOS, NetBSD, and Windows.
++-- is defined on FreeBSD, Linux, MacOS, NetBSD, Solaris, and Windows.
+ --
+ -- Even where the query action is defined, there may be situations where no
+ -- result is available, e.g. if the executable file was deleted while the
+@@ -158,9 +164,9 @@ executablePath = Just (fmap Just getExec
+       | otherwise             = throw e
+ 
+ --------------------------------------------------------------------------------
+--- Linux
++-- Linux / Solaris
+ 
+-#elif defined(linux_HOST_OS)
++#elif defined(linux_HOST_OS) || defined(solaris2_HOST_OS)
+ 
+ foreign import ccall unsafe "readlink"
+     c_readlink :: CString -> CString -> CSize -> IO CInt
+@@ -177,6 +183,7 @@ readSymbolicLink file =
+                    c_readlink s buf 4096
+             peekFilePathLen (buf,fromIntegral len)
+ 
++#  if defined(linux_HOST_OS)
+ getExecutablePath = readSymbolicLink $ "/proc/self/exe"
+ 
+ executablePath = Just (check <$> getExecutablePath) where
+@@ -187,6 +194,18 @@ executablePath = Just (check <$> getExec
+   check s | "(deleted)" `isSuffixOf` s = Nothing
+           | otherwise = Just s
+ 
++#  elif defined(solaris2_HOST_OS)
++getExecutablePath = readSymbolicLink "/proc/self/path/a.out"
++
++executablePath = Just ((Just <$> getExecutablePath) `catch` f)
++  where
++    -- readlink(2) fails with ENOENT when the executable has been deleted,
++    -- even though the symlink itself still exists according to readdir(3).
++    f e | isDoesNotExistError e = pure Nothing
++        | otherwise             = throw e
++
++#endif
++
+ --------------------------------------------------------------------------------
+ -- FreeBSD / NetBSD
+ 
Index: pkgsrc/lang/ghc94/patches/patch-libraries_base_configure
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-libraries_base_configure:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-libraries_base_configure    Sat Jan 21 04:49:25 2023
@@ -0,0 +1,18 @@
+$NetBSD: patch-libraries_base_configure,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Ensure libiconv can be found at runtime.
+
+XXX: I don't think this is needed because rpath flags are handled by
+Cabal. LDFLAGS is not used anyway. (pho@)
+
+--- libraries/base/configure.orig      2021-10-28 20:43:03.000000000 +0000
++++ libraries/base/configure
+@@ -4209,7 +4209,7 @@ fi
+ 
+ # Check whether --with-iconv-libraries was given.
+ if test "${with_iconv_libraries+set}" = set; then :
+-  withval=$with_iconv_libraries; ICONV_LIB_DIRS=$withval; LDFLAGS="-L$withval $LDFLAGS"
++  withval=$with_iconv_libraries; ICONV_LIB_DIRS=$withval; LDFLAGS="-L$withval ${COMPILER_RPATH_FLAG}$withval $LDFLAGS"
+ else
+   ICONV_LIB_DIRS=
+ fi
Index: pkgsrc/lang/ghc94/patches/patch-libraries_ghc-boot_GHC_BaseDir.hs
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-libraries_ghc-boot_GHC_BaseDir.hs:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-libraries_ghc-boot_GHC_BaseDir.hs   Sat Jan 21 04:49:25 2023
@@ -0,0 +1,81 @@
+$NetBSD: patch-libraries_ghc-boot_GHC_BaseDir.hs,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Make getBaseDir less platform-dependent by making use of base-4.17
+`executablePath` when possible, and falling back on `getExecutablePath`
+when it's not available. Not upstreamed yet.
+
+--- libraries/ghc-boot/GHC/BaseDir.hs.orig     2023-01-14 17:06:00.667592015 +0000
++++ libraries/ghc-boot/GHC/BaseDir.hs
+@@ -12,18 +12,20 @@
+ -- installation location at build time. ghc-pkg also can expand those variables
+ -- and so needs the top dir location to do that too.
+ 
+-module GHC.BaseDir where
++module GHC.BaseDir
++  ( expandTopDir
++  , expandPathVar
++  , getBaseDir
++  ) where
+ 
+ import Prelude -- See Note [Why do we import Prelude here?]
+ 
+ import Data.List (stripPrefix)
+ import System.FilePath
+ 
+--- Windows
+-#if defined(mingw32_HOST_OS)
+-import System.Environment (getExecutablePath)
+--- POSIX
+-#elif defined(darwin_HOST_OS) || defined(linux_HOST_OS) || defined(freebsd_HOST_OS) || defined(openbsd_HOST_OS) || defined(netbsd_HOST_OS)
++#if MIN_VERSION_base(4,17,0)
++import System.Environment (executablePath)
++#else
+ import System.Environment (getExecutablePath)
+ #endif
+ 
+@@ -42,17 +44,23 @@ expandPathVar var value str
+ expandPathVar var value (x:xs) = x : expandPathVar var value xs
+ expandPathVar _ _ [] = []
+ 
++#if !MIN_VERSION_base(4,17,0)
++-- Polyfill for executablePath
++executablePath :: Maybe (IO (Maybe FilePath))
++executablePath = Just (Just <$> getExecutablePath)
++#endif
++
+ -- | Calculate the location of the base dir
+ getBaseDir :: IO (Maybe String)
+ #if defined(mingw32_HOST_OS)
+-getBaseDir = Just . (\p -> p </> "lib") . rootDir <$> getExecutablePath
++getBaseDir = maybe (pure Nothing) ((((</> "lib") . rootDir) <$>) <$>) executablePath
+   where
+     -- locate the "base dir" when given the path
+     -- to the real ghc executable (as opposed to symlink)
+     -- that is running this function.
+     rootDir :: FilePath -> FilePath
+     rootDir = takeDirectory . takeDirectory . normalise
+-#elif defined(darwin_HOST_OS) || defined(linux_HOST_OS) || defined(freebsd_HOST_OS) || defined(openbsd_HOST_OS) || defined(netbsd_HOST_OS)
++#else
+ -- on unix, this is a bit more confusing.
+ -- The layout right now is something like
+ --
+@@ -64,14 +72,15 @@ getBaseDir = Just . (\p -> p </> "lib")
+ -- As such, we first need to find the absolute location to the
+ -- binary.
+ --
+--- getExecutablePath will return (3). One takeDirectory will
++-- executablePath will return (3). One takeDirectory will
+ -- give use /lib/ghc-X.Y.Z/bin, and another will give us (4).
+ --
+ -- This of course only works due to the current layout. If
+ -- the layout is changed, such that we have ghc-X.Y.Z/{bin,lib}
+ -- this would need to be changed accordingly.
+ --
+-getBaseDir = Just . (\p -> p </> "lib") . takeDirectory . takeDirectory <$> getExecutablePath
+-#else
+-getBaseDir = return Nothing
++getBaseDir = maybe (pure Nothing) ((((</> "lib") . rootDir) <$>) <$>) executablePath
++  where
++    rootDir :: FilePath -> FilePath
++    rootDir = takeDirectory . takeDirectory
+ #endif
Index: pkgsrc/lang/ghc94/patches/patch-libraries_process_cbits_posix_fork__exec.c
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-libraries_process_cbits_posix_fork__exec.c:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-libraries_process_cbits_posix_fork__exec.c  Sat Jan 21 04:49:25 2023
@@ -0,0 +1,14 @@
+$NetBSD: patch-libraries_process_cbits_posix_fork__exec.c,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Ensure _POSIX_PTHREAD_SEMANTICS is defined on SunOS.
+
+--- libraries/process/cbits/posix/fork_exec.c.orig     2021-10-28 20:42:10.000000000 +0000
++++ libraries/process/cbits/posix/fork_exec.c
+@@ -1,3 +1,7 @@
++#ifdef __sun
++#define _POSIX_PTHREAD_SEMANTICS
++#endif
++
+ #include "common.h"
+ 
+ #include <sys/types.h>
Index: pkgsrc/lang/ghc94/patches/patch-libraries_terminfo_configure.ac
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-libraries_terminfo_configure.ac:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-libraries_terminfo_configure.ac     Sat Jan 21 04:49:25 2023
@@ -0,0 +1,23 @@
+$NetBSD: patch-libraries_terminfo_configure.ac,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Fix build on NetBSD 10. setupterm(3) is in libterminfo on this
+platform. Not upstreamed yet.
+
+--- libraries/terminfo/configure.ac.orig       2023-01-13 13:47:37.528995149 +0000
++++ libraries/terminfo/configure.ac
+@@ -17,10 +17,11 @@ AC_PROG_CC()
+ 
+ AC_CHECK_LIB(tinfow, setupterm, HaveLibCurses=YES; LibCurses=tinfow,
+   [AC_CHECK_LIB(tinfo, setupterm, HaveLibCurses=YES; LibCurses=tinfo,
+-    [AC_CHECK_LIB(ncursesw, setupterm, HaveLibCurses=YES; LibCurses=ncursesw,
+-      [AC_CHECK_LIB(ncurses, setupterm, HaveLibCurses=YES; LibCurses=ncurses,
+-        [AC_CHECK_LIB(curses, setupterm, HaveLibCurses=YES; LibCurses=curses,
+-          HaveLibCurses=NO; LibCurses=not-installed)])])])])
++    [AC_CHECK_LIB(terminfo, setupterm, HaveLibCurses=YES; LibCurses=terminfo,
++      [AC_CHECK_LIB(ncursesw, setupterm, HaveLibCurses=YES; LibCurses=ncursesw,
++        [AC_CHECK_LIB(ncurses, setupterm, HaveLibCurses=YES; LibCurses=ncurses,
++          [AC_CHECK_LIB(curses, setupterm, HaveLibCurses=YES; LibCurses=curses,
++            HaveLibCurses=NO; LibCurses=not-installed)])])])])])
+ 
+ if test "x$HaveLibCurses" = "xNO" ; then
+     AC_MSG_FAILURE([curses library not found, so this package cannot be built])
Index: pkgsrc/lang/ghc94/patches/patch-libraries_text_text.cabal
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-libraries_text_text.cabal:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-libraries_text_text.cabal   Sat Jan 21 04:49:25 2023
@@ -0,0 +1,19 @@
+$NetBSD: patch-libraries_text_text.cabal,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+This is a temporary workaround for aarch64 codegen bug in 9.2.1. Once we
+update our bootkit for aarch64 we can remove this.
+https://gitlab.haskell.org/ghc/ghc/-/issues/20594
+
+--- libraries/text/text.cabal.orig     2022-12-23 16:19:54.000000000 +0000
++++ libraries/text/text.cabal
+@@ -127,10 +127,6 @@ library
+   if (arch(aarch64) || arch(arm)) && impl(ghc == 8.10.*)
+     build-depends: base < 0
+ 
+-  -- Subword primitives in GHC 9.2.1 are broken on ARM platforms.
+-  if (arch(aarch64) || arch(arm)) && impl(ghc == 9.2.1)
+-    build-depends: base < 0
+-
+   exposed-modules:
+     Data.Text
+     Data.Text.Array
Index: pkgsrc/lang/ghc94/patches/patch-libraries_time_lib_Data_Time_Clock_Internal_CTimespec.hsc
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-libraries_time_lib_Data_Time_Clock_Internal_CTimespec.hsc:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-libraries_time_lib_Data_Time_Clock_Internal_CTimespec.hsc   Sat Jan 21 04:49:25 2023
@@ -0,0 +1,23 @@
+$NetBSD: patch-libraries_time_lib_Data_Time_Clock_Internal_CTimespec.hsc,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Suppress linker warnings about compatibility symbols.
+
+--- libraries/time/lib/Data/Time/Clock/Internal/CTimespec.hsc.orig     2020-01-04 02:21:30.506303962 +0000
++++ libraries/time/lib/Data/Time/Clock/Internal/CTimespec.hsc
+@@ -1,3 +1,4 @@
++{-# LANGUAGE CApiFFI #-}
+ module Data.Time.Clock.Internal.CTimespec where
+ 
+ #include "HsTimeConfig.h"
+@@ -29,9 +30,9 @@ instance Storable CTimespec where
+         #{poke struct timespec, tv_sec } p s
+         #{poke struct timespec, tv_nsec} p ns
+ 
+-foreign import ccall unsafe "time.h clock_gettime"
++foreign import capi unsafe "time.h clock_gettime"
+     clock_gettime :: ClockID -> Ptr CTimespec -> IO CInt
+-foreign import ccall unsafe "time.h clock_getres"
++foreign import capi unsafe "time.h clock_getres"
+     clock_getres :: ClockID -> Ptr CTimespec -> IO CInt
+ 
+ -- | Get the resolution of the given clock.
Index: pkgsrc/lang/ghc94/patches/patch-libraries_time_lib_Data_Time_Clock_Internal_CTimeval.hs
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-libraries_time_lib_Data_Time_Clock_Internal_CTimeval.hs:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-libraries_time_lib_Data_Time_Clock_Internal_CTimeval.hs     Sat Jan 21 04:49:25 2023
@@ -0,0 +1,33 @@
+$NetBSD: patch-libraries_time_lib_Data_Time_Clock_Internal_CTimeval.hs,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Suppress linker warnings about compatibility syscall wrappers by using
+"capi" instead of "ccall". In Haskell FFI, "ccall" is actually an
+interface to C ABI rather than C API. That is, GHC generates direct
+references to the symbol even if it's actually defined as a cpp macro
+or something like that, because GHC knows nothing about those macros
+in foreign headers. Hence the following warnings:
+
+  .../libHStime-1.4.0.1.a(CTimeval.o): In function `s1Kp_info':
+  (.text+0x2f): warning: warning: reference to compatibility
+  gettimeofday(); include <sys/time.h> to generate correct reference
+
+In other words, you can safely use "ccall" only when you are sure the
+symbol you want to import is actually a symbol in the ABI sense, which
+is not always the case for the POSIX API.
+
+--- libraries/time/lib/Data/Time/Clock/Internal/CTimeval.hs.orig       2021-10-28 20:42:10.000000000 +0000
++++ libraries/time/lib/Data/Time/Clock/Internal/CTimeval.hs
+@@ -1,3 +1,4 @@
++{-# LANGUAGE CApiFFI #-}
+ {-# LANGUAGE Safe #-}
+ 
+ module Data.Time.Clock.Internal.CTimeval where
+@@ -21,7 +22,7 @@ instance Storable CTimeval where
+         pokeElemOff (castPtr p) 0 s
+         pokeElemOff (castPtr p) 1 mus
+ 
+-foreign import ccall unsafe "time.h gettimeofday" gettimeofday :: Ptr CTimeval -> Ptr () -> IO CInt
++foreign import capi unsafe "sys/time.h gettimeofday" gettimeofday :: Ptr CTimeval -> Ptr () -> IO CInt
+ 
+ -- | Get the current POSIX time from the system clock.
+ getCTimeval :: IO CTimeval
Index: pkgsrc/lang/ghc94/patches/patch-libraries_unix_System_Posix_Env.hsc
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-libraries_unix_System_Posix_Env.hsc:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-libraries_unix_System_Posix_Env.hsc Sat Jan 21 04:49:25 2023
@@ -0,0 +1,16 @@
+$NetBSD: patch-libraries_unix_System_Posix_Env.hsc,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Suppress linker warnings about compatibility symbols by using "capi"
+instead of "ccall".
+
+--- libraries/unix/System/Posix/Env.hsc.orig   2016-11-17 22:08:50.000000000 +0000
++++ libraries/unix/System/Posix/Env.hsc
+@@ -156,7 +156,7 @@ putEnv keyvalue = do s <- newFilePath ke
+       newFilePath fp = getFileSystemEncoding >>= \enc -> GHC.newCString enc fp
+ #endif
+ 
+-foreign import ccall unsafe "putenv"
++foreign import capi unsafe "stdlib.h putenv"
+    c_putenv :: CString -> IO CInt
+ 
+ {- |The 'setEnv' function inserts or resets the environment variable name in
Index: pkgsrc/lang/ghc94/patches/patch-libraries_unix_System_Posix_Env_ByteString.hsc
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-libraries_unix_System_Posix_Env_ByteString.hsc:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-libraries_unix_System_Posix_Env_ByteString.hsc      Sat Jan 21 04:49:25 2023
@@ -0,0 +1,16 @@
+$NetBSD: patch-libraries_unix_System_Posix_Env_ByteString.hsc,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Suppress linker warnings about compatibility symbols by using "capi"
+instead of "ccall".
+
+--- libraries/unix/System/Posix/Env/ByteString.hsc.orig        2022-12-23 16:19:54.000000000 +0000
++++ libraries/unix/System/Posix/Env/ByteString.hsc
+@@ -153,7 +153,7 @@ putEnv (PS fp o l) = withForeignPtr fp $
+   pokeByteOff buf l (0::Word8)
+   throwErrnoIfMinus1_ "putenv" (c_putenv (castPtr buf))
+ 
+-foreign import ccall unsafe "putenv"
++foreign import capi unsafe "HsUnix.h putenv"
+    c_putenv :: CString -> IO CInt
+ 
+ {- |The 'setEnv' function inserts or resets the environment variable name in
Index: pkgsrc/lang/ghc94/patches/patch-libraries_unix_System_Posix_Files_Common.hsc
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-libraries_unix_System_Posix_Files_Common.hsc:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-libraries_unix_System_Posix_Files_Common.hsc        Sat Jan 21 04:49:25 2023
@@ -0,0 +1,33 @@
+$NetBSD: patch-libraries_unix_System_Posix_Files_Common.hsc,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Suppress linker warnings about compatibility syscall wrappers by using
+"capi" instead of "ccall".
+
+--- libraries/unix/System/Posix/Files/Common.hsc.orig  2016-04-20 10:08:26.000000000 +0000
++++ libraries/unix/System/Posix/Files/Common.hsc
+@@ -1,4 +1,5 @@
+ {-# LANGUAGE Trustworthy #-}
++{-# LANGUAGE CApiFFI #-}
+ 
+ -----------------------------------------------------------------------------
+ -- |
+@@ -448,16 +449,16 @@ toCTimeVal t = CTimeVal sec (truncate $ 
+     (sec, frac) = if (frac' < 0) then (sec' - 1, frac' + 1) else (sec', frac')
+     (sec', frac') = properFraction $ toRational t
+ 
+-foreign import ccall unsafe "utimes"
++foreign import capi unsafe "sys/time.h utimes"
+     c_utimes :: CString -> Ptr CTimeVal -> IO CInt
+ 
+ #ifdef HAVE_LUTIMES
+-foreign import ccall unsafe "lutimes"
++foreign import capi unsafe "sys/time.h lutimes"
+     c_lutimes :: CString -> Ptr CTimeVal -> IO CInt
+ #endif
+ 
+ #if HAVE_FUTIMES
+-foreign import ccall unsafe "futimes"
++foreign import capi unsafe "sys/time.h futimes"
+     c_futimes :: CInt -> Ptr CTimeVal -> IO CInt
+ #endif
+ 
Index: pkgsrc/lang/ghc94/patches/patch-libraries_unix_System_Posix_Signals.hsc
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-libraries_unix_System_Posix_Signals.hsc:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-libraries_unix_System_Posix_Signals.hsc     Sat Jan 21 04:49:25 2023
@@ -0,0 +1,22 @@
+$NetBSD: patch-libraries_unix_System_Posix_Signals.hsc,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Suppress linker warnings about compatibility symbols.
+
+--- libraries/unix/System/Posix/Signals.hsc.orig       2016-04-20 10:08:26.000000000 +0000
++++ libraries/unix/System/Posix/Signals.hsc
+@@ -590,7 +590,7 @@ awaitSignal maybe_sigset = do
+   -- XXX My manpage says it can also return EFAULT. And why is ignoring
+   -- EINTR the right thing to do?
+ 
+-foreign import ccall unsafe "sigsuspend"
++foreign import capi unsafe "signal.h sigsuspend"
+   c_sigsuspend :: Ptr CSigset -> IO CInt
+ 
+ #if defined(darwin_HOST_OS) && __GLASGOW_HASKELL__ < 706
+@@ -615,5 +615,5 @@ foreign import capi unsafe "signal.h sig
+   c_sigismember :: Ptr CSigset -> CInt -> IO CInt
+ #endif
+ 
+-foreign import ccall unsafe "sigpending"
++foreign import capi unsafe "signal.h sigpending"
+   c_sigpending :: Ptr CSigset -> IO CInt
Index: pkgsrc/lang/ghc94/patches/patch-libraries_unix_include_execvpe.h
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-libraries_unix_include_execvpe.h:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-libraries_unix_include_execvpe.h    Sat Jan 21 04:49:25 2023
@@ -0,0 +1,19 @@
+$NetBSD: patch-libraries_unix_include_execvpe.h,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Don't conflict with builtin execvpe(3).
+
+Already fixed in the upstream (unix-2.8.0.0).
+
+--- libraries/unix/include/execvpe.h.orig      2016-02-04 16:16:38.000000000 +0000
++++ libraries/unix/include/execvpe.h
+@@ -15,8 +15,10 @@ __hsunix_execvpe(const char *name, char 
+ #include "HsUnixConfig.h"
+ #if HAVE_EXECVPE
+ # include <unistd.h>
++# if !defined(execvpe) && !HAVE_DECL_EXECVPE
+ extern int
+ execvpe(const char *name, char *const argv[], char *const envp[]);
++# endif
+ #else
+ # define execvpe(name,argv,envp) __hsunix_execvpe(name,argv,envp)
+ #endif
Index: pkgsrc/lang/ghc94/patches/patch-m4_fptools__set__haskell__platform__vars.m4
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-m4_fptools__set__haskell__platform__vars.m4:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-m4_fptools__set__haskell__platform__vars.m4 Sat Jan 21 04:49:25 2023
@@ -0,0 +1,29 @@
+$NetBSD: patch-m4_fptools__set__haskell__platform__vars.m4,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Pretend the toolchain doesn't support .note.GNU-stack on NetBSD. This is a
+temporary workaround and shouldn't live forever. See:
+https://mail-index.netbsd.org/tech-toolchain/2023/01/15/msg004188.html
+
+--- m4/fptools_set_haskell_platform_vars.m4.orig       2023-01-15 14:19:38.638967614 +0000
++++ m4/fptools_set_haskell_platform_vars.m4
+@@ -180,6 +180,11 @@ AC_DEFUN([GHC_IDENT_DIRECTIVE],
+ # so we empty CFLAGS while running this test
+ AC_DEFUN([GHC_GNU_NONEXEC_STACK],
+ [
++    case $TargetOS in
++      netbsd)
++        TargetHasGnuNonexecStack=NO;;
++      *)
++
+     CFLAGS2="$CFLAGS"
+     CFLAGS=
+     case $TargetArch in
+@@ -206,6 +211,8 @@ AC_DEFUN([GHC_GNU_NONEXEC_STACK],
+         [AC_MSG_RESULT(no)
+          TargetHasGnuNonexecStack=NO])
+     CFLAGS="$CFLAGS2"
++
++    esac
+ ])
+ 
+ # FPTOOLS_SET_HASKELL_PLATFORM_VARS
Index: pkgsrc/lang/ghc94/patches/patch-rts_linker_MMap.c
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-rts_linker_MMap.c:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-rts_linker_MMap.c   Sat Jan 21 04:49:25 2023
@@ -0,0 +1,123 @@
+$NetBSD: patch-rts_linker_MMap.c,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Hunk #0-2, #6:
+    NetBSD-specific way of switching pages from rw- to r-x. Even when the
+    RTS linker is not used, libraries/ghci/GHCi/InfoTable.hsc
+    (fillExecBuffer) calls rts/ExecPage.c (allocateExecPage) to store some
+    executable code, then calls freezeExecPage() and fails. If we were to
+    disable PaX MPROTECT entirely then we could omit this change, but of
+    course that's not the right thing to do.
+
+    pho@ is reluctant to upstream these hunks because this change alone
+    doesn't make GHCi work on NetBSD. We also need hunk #3-5 but they are
+    rather hackish and don't really seem right.
+
+Hunk #3-5:
+    NetBSD mmap(2) doesn't work the same way as that of Linux. We
+    essentially can't use the hint address to map a new page based on the
+    address of the previously mapped one.
+
+    Minimal test case:
+    https://gist.github.com/depressed-pho/a629247b48b3e6178e35a14c62e9d44f
+
+    tech-kern thread:
+    https://mail-index.netbsd.org/tech-kern/2022/02/17/msg027969.html
+
+--- rts/linker/MMap.c.orig     2023-01-10 12:21:10.038457244 +0000
++++ rts/linker/MMap.c
+@@ -46,6 +46,8 @@ static const char *memoryAccessDescripti
+   case MEM_NO_ACCESS:    return "no-access";
+   case MEM_READ_ONLY:    return "read-only";
+   case MEM_READ_WRITE:   return "read-write";
++  case MEM_READ_WRITE_THEN_READ_EXECUTE:
++                         return "read-write-then-read-execute";
+   case MEM_READ_EXECUTE: return "read-execute";
+   case MEM_READ_WRITE_EXECUTE:
+                          return "read-write-execute";
+@@ -196,6 +198,8 @@ memoryAccessToProt(MemoryAccess access)
+   case MEM_NO_ACCESS:    return PAGE_NOACCESS;
+   case MEM_READ_ONLY:    return PAGE_READONLY;
+   case MEM_READ_WRITE:   return PAGE_READWRITE;
++  case MEM_READ_WRITE_THEN_READ_EXECUTE:
++                         return PAGE_READWRITE;
+   case MEM_READ_EXECUTE: return PAGE_EXECUTE_READ;
+   case MEM_READ_WRITE_EXECUTE:
+                          return PAGE_EXECUTE_READWRITE;
+@@ -258,6 +262,17 @@ memoryAccessToProt(MemoryAccess access)
+     case MEM_NO_ACCESS:    return 0;
+     case MEM_READ_ONLY:    return PROT_READ;
+     case MEM_READ_WRITE:   return PROT_READ | PROT_WRITE;
++    case MEM_READ_WRITE_THEN_READ_EXECUTE:
++#  if defined(netbsd_HOST_OS)
++        /* PROT_MPROTECT(PROT_EXEC) means that the pages are going to be
++         * marked as executable in the future. On NetBSD requesting
++         * additional permissions with mprotect(2) only succeeds when
++         * permissions were initially requested in this manner.
++         */
++                           return PROT_READ | PROT_WRITE | PROT_MPROTECT(PROT_EXEC);
++#  else
++                           return PROT_READ | PROT_WRITE;
++#  endif
+     case MEM_READ_EXECUTE: return PROT_READ | PROT_EXEC;
+     case MEM_READ_WRITE_EXECUTE:
+                            return PROT_READ | PROT_WRITE | PROT_EXEC;
+@@ -301,6 +316,23 @@ nearImage(void) {
+     return &region;
+ }
+ 
++/* mmap(2) works differently on NetBSD. When a hint address is provided, it
++ * searches for a free region at or below the hint, and *never* above
++ * it. This means we really can't search for free regions incrementally on
++ * the user side. Let the kernel do it for us.
++ */
++static void *
++mmapAnywhere (
++        size_t bytes,
++        MemoryAccess access,
++        uint32_t flags,
++        int fd,
++        int offset)
++{
++    int prot = memoryAccessToProt(access);
++    return doMmap(NULL, bytes, prot, flags, fd, offset);
++}
++
+ static void *
+ mmapInRegion (
+         struct MemoryRegion *region,
+@@ -358,7 +390,11 @@ mmapForLinker (size_t bytes, MemoryAcces
+     IF_DEBUG(linker_verbose, debugBelch("mmapForLinker: start\n"));
+     if (RtsFlags.MiscFlags.linkerAlwaysPic) {
+         /* make no attempt at mapping low memory if we are assuming PIC */
++#if defined(netbsd_HOST_OS)
++        region = NULL;
++#else
+         region = &allMemory;
++#endif
+     } else {
+         region = nearImage();
+     }
+@@ -368,7 +404,13 @@ mmapForLinker (size_t bytes, MemoryAcces
+         flags |= TRY_MAP_32BIT;
+     }
+ 
+-    void *result = mmapInRegion(region, bytes, access, flags, fd, offset);
++    void *result;
++    if (region) {
++        result = mmapInRegion(region, bytes, access, flags, fd, offset);
++    }
++    else {
++        result = mmapAnywhere(bytes, access, flags, fd, offset);
++    }
+     IF_DEBUG(linker_verbose,
+              debugBelch("mmapForLinker: mapped %zd bytes starting at %p\n",
+                         bytes, result));
+@@ -383,7 +425,7 @@ mmapForLinker (size_t bytes, MemoryAcces
+ void *
+ mmapAnonForLinker (size_t bytes)
+ {
+-    return mmapForLinker (bytes, MEM_READ_WRITE, MAP_ANONYMOUS, -1, 0);
++    return mmapForLinker (bytes, MEM_READ_WRITE_THEN_READ_EXECUTE, MAP_ANONYMOUS, -1, 0);
+ }
+ 
+ void munmapForLinker (void *addr, size_t bytes, const char *caller)
Index: pkgsrc/lang/ghc94/patches/patch-rts_linker_MMap.h
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-rts_linker_MMap.h:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-rts_linker_MMap.h   Sat Jan 21 04:49:25 2023
@@ -0,0 +1,15 @@
+$NetBSD: patch-rts_linker_MMap.h,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Needed for supporting NetBSD PaX MPROTECT. See patch-rts_linker_MMap.c for
+details.
+
+--- rts/linker/MMap.h.orig     2023-01-10 12:41:09.417481027 +0000
++++ rts/linker/MMap.h
+@@ -54,6 +54,7 @@ typedef enum {
+     MEM_NO_ACCESS,
+     MEM_READ_ONLY,
+     MEM_READ_WRITE,
++    MEM_READ_WRITE_THEN_READ_EXECUTE,
+     MEM_READ_EXECUTE,
+     MEM_READ_WRITE_EXECUTE,
+ } MemoryAccess;
Index: pkgsrc/lang/ghc94/patches/patch-rts_rts.cabal.in
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-rts_rts.cabal.in:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-rts_rts.cabal.in    Sat Jan 21 04:49:25 2023
@@ -0,0 +1,50 @@
+$NetBSD: patch-rts_rts.cabal.in,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Don't assume we always build the threaded RTS. Not upstreamed yet.
+
+--- rts/rts.cabal.in.orig      2023-01-11 05:03:17.728266721 +0000
++++ rts/rts.cabal.in
+@@ -45,6 +45,8 @@ flag find-ptr
+ -- threaded. The flags "compose": if you enable debug and profiling,
+ -- you will produce vanilla, _thr, _debug, _p but also _thr_p,
+ -- _thr_debug_p and so on.
++flag threaded
++  default: False
+ flag profiling
+   default: False
+ flag debug
+@@ -84,18 +86,26 @@ library
+     -- this cabal file. We therefore declare several
+     -- flavours to be available when passing the suitable (combination of)
+     -- flag(s) when configuring the RTS from hadrian, using Cabal.
+-    extra-library-flavours: _thr
+-
++    if flag(threaded)
++      extra-library-flavours: _thr
++      if flag(dynamic)
++        extra-dynamic-library-flavours: _thr
+     if flag(profiling)
+-      extra-library-flavours: _p _thr_p
++      extra-library-flavours: _p
++      if flag(threaded)
++        extra-library-flavours: _thr_p
+       if flag(debug)
+-        extra-library-flavours: _debug_p _thr_debug_p
++        extra-library-flavours: _debug_p
++        if flag(threaded)
++          extra-library-flavours: _thr_debug_p
+     if flag(debug)
+-      extra-library-flavours: _debug _thr_debug
++      extra-library-flavours: _debug
++      if flag(threaded)
++        extra-library-flavours: _thr_debug
+       if flag(dynamic)
+-        extra-dynamic-library-flavours: _debug _thr_debug
+-    if flag(dynamic)
+-      extra-dynamic-library-flavours: _thr
++        extra-dynamic-library-flavours: _debug
++        if flag(threaded)
++          extra-dynamic-library-flavours: _thr_debug
+ 
+     if flag(thread-sanitizer)
+       cc-options: -fsanitize=thread
Index: pkgsrc/lang/ghc94/patches/patch-utils_haddock_driver_Main.hs
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-utils_haddock_driver_Main.hs:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-utils_haddock_driver_Main.hs        Sat Jan 21 04:49:25 2023
@@ -0,0 +1,19 @@
+$NetBSD: patch-utils_haddock_driver_Main.hs,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Workaround for haddock dying when the locale isn't "*.UTF-8". Of course
+this isn't a real fix. Haddock is very fragile when it comes to locale
+setting, and fixing it properly would be seriously a lot of work.
+
+--- utils/haddock/driver/Main.hs.orig  2020-07-28 17:05:24.000000000 +0000
++++ utils/haddock/driver/Main.hs
+@@ -1,7 +1,9 @@
+ module Main where
+ 
+ import Documentation.Haddock (haddock)
++import GHC.IO.Encoding (setLocaleEncoding, utf8)
+ import GHC.ResponseFile (getArgsWithResponseFiles)
+ 
+ main :: IO ()
+-main = getArgsWithResponseFiles >>= haddock
++main = do setLocaleEncoding utf8
++          getArgsWithResponseFiles >>= haddock
Index: pkgsrc/lang/ghc94/patches/patch-utils_haddock_haddock.cabal
diff -u /dev/null pkgsrc/lang/ghc94/patches/patch-utils_haddock_haddock.cabal:1.1
--- /dev/null   Sat Jan 21 04:49:25 2023
+++ pkgsrc/lang/ghc94/patches/patch-utils_haddock_haddock.cabal Sat Jan 21 04:49:25 2023
@@ -0,0 +1,24 @@
+$NetBSD: patch-utils_haddock_haddock.cabal,v 1.1 2023/01/21 04:49:25 pho Exp $
+
+Don't assume we always build the threaded RTS. Not upstreamed yet.
+
+--- utils/haddock/haddock.cabal.orig   2023-01-11 07:37:47.265320221 +0000
++++ utils/haddock/haddock.cabal
+@@ -59,12 +59,16 @@ flag in-ghc-tree
+   description: Are we in a GHC tree?
+   default: False
+   manual: True
++flag threaded
++  default: False
+ 
+ executable haddock
+   default-language:     Haskell2010
+   main-is:              Main.hs
+   hs-source-dirs:       driver
+-  ghc-options:          -funbox-strict-fields -Wall -Wincomplete-uni-patterns -Wincomplete-record-updates -O2 -threaded
++  ghc-options:          -funbox-strict-fields -Wall -Wincomplete-uni-patterns -Wincomplete-record-updates -O2
++  if flag(threaded)
++    ghc-options: -threaded
+ 
+   -- haddock typically only supports a single GHC major version
+   build-depends:



Home | Main Index | Thread Index | Old Index