pkgsrc-Changes archive

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

CVS commit: pkgsrc/lang/ghc96



Module Name:    pkgsrc
Committed By:   pho
Date:           Mon Oct 23 08:06:49 UTC 2023

Added Files:
        pkgsrc/lang/ghc96: DEINSTALL DESCR INSTALL Makefile bootstrap.mk
            buildlink3.mk distinfo options.mk
        pkgsrc/lang/ghc96/files: BOOTSTRAP.md UserSettings.hs
            extract-vanilla-package-db
        pkgsrc/lang/ghc96/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_bootstrap_src_Main.hs 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_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_Signals.hsc
            patch-m4_fptools__set__haskell__platform__vars.m4
            patch-rts_linker_MMap.c patch-rts_linker_MMap.h
            patch-utils_genprimopcode_Main.hs
            patch-utils_haddock_driver_Main.hs
            patch-utils_haddock_haddock.cabal

Log Message:
lang/ghc96: import ghc-9.6.3

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.6.x release series.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 pkgsrc/lang/ghc96/DEINSTALL pkgsrc/lang/ghc96/DESCR \
    pkgsrc/lang/ghc96/INSTALL pkgsrc/lang/ghc96/Makefile \
    pkgsrc/lang/ghc96/bootstrap.mk pkgsrc/lang/ghc96/buildlink3.mk \
    pkgsrc/lang/ghc96/distinfo pkgsrc/lang/ghc96/options.mk
cvs rdiff -u -r0 -r1.1 pkgsrc/lang/ghc96/files/BOOTSTRAP.md \
    pkgsrc/lang/ghc96/files/UserSettings.hs \
    pkgsrc/lang/ghc96/files/extract-vanilla-package-db
cvs rdiff -u -r0 -r1.1 \
    pkgsrc/lang/ghc96/patches/patch-compiler_GHC_Driver_Pipeline_Execute.hs \
    pkgsrc/lang/ghc96/patches/patch-compiler_GHC_SysTools_Process.hs \
    pkgsrc/lang/ghc96/patches/patch-configure.ac \
    pkgsrc/lang/ghc96/patches/patch-hadrian_bindist_Makefile \
    pkgsrc/lang/ghc96/patches/patch-hadrian_bootstrap_bootstrap.py \
    pkgsrc/lang/ghc96/patches/patch-hadrian_bootstrap_src_Main.hs \
    pkgsrc/lang/ghc96/patches/patch-hadrian_src_Builder.hs \
    pkgsrc/lang/ghc96/patches/patch-hadrian_src_Oracles_Setting.hs \
    pkgsrc/lang/ghc96/patches/patch-hadrian_src_Rules_BinaryDist.hs \
    pkgsrc/lang/ghc96/patches/patch-hadrian_src_Settings_Builders_Ghc.hs \
    pkgsrc/lang/ghc96/patches/patch-hadrian_src_Settings_Default.hs \
    pkgsrc/lang/ghc96/patches/patch-hadrian_src_Settings_Packages.hs \
    pkgsrc/lang/ghc96/patches/patch-libraries_Cabal_Cabal_src_Distribution_Simple_GHC.hs \
    pkgsrc/lang/ghc96/patches/patch-libraries_base_GHC_Event_KQueue.hsc \
    pkgsrc/lang/ghc96/patches/patch-libraries_base_System_CPUTime_Posix_Times.hsc \
    pkgsrc/lang/ghc96/patches/patch-libraries_base_System_Environment.hs \
    pkgsrc/lang/ghc96/patches/patch-libraries_base_System_Environment_ExecutablePath.hsc \
    pkgsrc/lang/ghc96/patches/patch-libraries_base_configure \
    pkgsrc/lang/ghc96/patches/patch-libraries_ghc-boot_GHC_BaseDir.hs \
    pkgsrc/lang/ghc96/patches/patch-libraries_process_cbits_posix_fork__exec.c \
    pkgsrc/lang/ghc96/patches/patch-libraries_terminfo_configure.ac \
    pkgsrc/lang/ghc96/patches/patch-libraries_time_lib_Data_Time_Clock_Internal_CTimespec.hsc \
    pkgsrc/lang/ghc96/patches/patch-libraries_time_lib_Data_Time_Clock_Internal_CTimeval.hs \
    pkgsrc/lang/ghc96/patches/patch-libraries_unix_System_Posix_Env.hsc \
    pkgsrc/lang/ghc96/patches/patch-libraries_unix_System_Posix_Env_ByteString.hsc \
    pkgsrc/lang/ghc96/patches/patch-libraries_unix_System_Posix_Signals.hsc \
    pkgsrc/lang/ghc96/patches/patch-m4_fptools__set__haskell__platform__vars.m4 \
    pkgsrc/lang/ghc96/patches/patch-rts_linker_MMap.c \
    pkgsrc/lang/ghc96/patches/patch-rts_linker_MMap.h \
    pkgsrc/lang/ghc96/patches/patch-utils_genprimopcode_Main.hs \
    pkgsrc/lang/ghc96/patches/patch-utils_haddock_driver_Main.hs \
    pkgsrc/lang/ghc96/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/ghc96/DEINSTALL
diff -u /dev/null pkgsrc/lang/ghc96/DEINSTALL:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/DEINSTALL Mon Oct 23 08:06:48 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/ghc96/DESCR
diff -u /dev/null pkgsrc/lang/ghc96/DESCR:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/DESCR     Mon Oct 23 08:06:48 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.6.x release series.
Index: pkgsrc/lang/ghc96/INSTALL
diff -u /dev/null pkgsrc/lang/ghc96/INSTALL:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/INSTALL   Mon Oct 23 08:06:48 2023
@@ -0,0 +1,8 @@
+#!/bin/sh
+#
+
+case ${STAGE} in
+    POST-INSTALL)
+        ${PKG_PREFIX}/bin/ghc-pkg recache
+        ;;
+esac
Index: pkgsrc/lang/ghc96/Makefile
diff -u /dev/null pkgsrc/lang/ghc96/Makefile:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/Makefile  Mon Oct 23 08:06:48 2023
@@ -0,0 +1,316 @@
+# $NetBSD: Makefile,v 1.1 2023/10/23 08:06:48 pho Exp $
+# -----------------------------------------------------------------------------
+# Package metadata
+#
+DISTNAME=      ghc-9.6.3-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.6 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
+
+# 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=         tool
+.include "../../lang/python/tool.mk"
+
+# -----------------------------------------------------------------------------
+# Configuration
+#
+HADRIAN_ARGS.common=   # empty
+HADRIAN_ARGS.common+=  -j${_MAKE_JOBS_N}
+HADRIAN_ARGS=          ${HADRIAN_ARGS.common}
+
+# 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.common+=  --verbose ${PKG_VERBOSE:D--verbose}
+
+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}
+
+# While we use binutils ar which supports "@", this appears to be leaking
+# somewhere into assuming that SunOS ld also supports "@" which it does not.
+CONFIGURE_ENV.SunOS+=  fp_cv_prog_ar_supports_atfile=no
+
+# 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 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.
+.if ${OPSYS} == "FreeBSD"
+#   -fsplit-sections appears to corrupt the symbol table of stage 1
+#   libHSghc-*.a(Instances.o) and cause a linkage failure. Either Clang or
+#   LLD is doing something wrong, probably the former.
+HADRIAN_ARGS+=         --flavour=default
+.else
+HADRIAN_ARGS+=         --flavour=default+split_sections
+.endif
+
+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"
+TOOL_DEPENDS+= ${PYPKGPREFIX}-sphinx-[0-9]*:../../textproc/py-sphinx
+.endif
+
+# NetBSD bootkits are currently built on 9. We need some compat libraries
+# to run them on later versions.
+#
+# 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 ${MACHINE_PLATFORM:MNetBSD-*-*} && ${OPSYS_VERSION} >= 099000
+TOOL_DEPENDS+= compat90-[0-9]*:../../emulators/compat90
+ALL_ENV+=      LD_LIBRARY_PATH=${PREFIX}/emul/netbsd/usr/lib
+.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/ghc96/bootstrap.mk
diff -u /dev/null pkgsrc/lang/ghc96/bootstrap.mk:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/bootstrap.mk      Mon Oct 23 08:06:48 2023
@@ -0,0 +1,378 @@
+# $NetBSD: bootstrap.mk,v 1.1 2023/10/23 08:06:48 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.6.3 requires 9.2 or later to bootstrap.
+# * 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 ${MACHINE_PLATFORM:MDarwin-*-x86_64} || make(distinfo) || make (makesum) || make(mdi)
+BOOT_VERSION:= 9.4.7
+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 ${MACHINE_PLATFORM:MFreeBSD-*-i386} || make(distinfo) || make (makesum) || make(mdi)
+BOOT_VERSION:= 9.4.7
+BOOT_ARCHIVE:= ghc-${BOOT_VERSION}-boot-i386-unknown-freebsd.tar.xz
+DISTFILES:=    ${DISTFILES} ${BOOT_ARCHIVE} ${HADRIAN_BOOT_SOURCE} # Available in LOCAL_PORTS
+.endif
+
+.if ${MACHINE_PLATFORM:MFreeBSD-*-x86_64} || make(distinfo) || make(makesum) || make(mdi)
+BOOT_VERSION:= 9.4.7
+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 ${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.4.7
+BOOT_ARCHIVE:= ghc-${BOOT_VERSION}-boot-aarch64-unknown-netbsd.tar.xz
+DISTFILES:=    ${DISTFILES} ${BOOT_ARCHIVE} ${HADRIAN_BOOT_SOURCE} # Available in LOCAL_PORTS
+.endif
+
+.if ${MACHINE_PLATFORM:MNetBSD-*-x86_64} || make(distinfo) || make(makesum) || make(mdi)
+BOOT_VERSION:= 9.4.7
+BOOT_ARCHIVE:= ghc-${BOOT_VERSION}-boot-x86_64-unknown-netbsd.tar.xz
+DISTFILES:=    ${DISTFILES} ${BOOT_ARCHIVE} ${HADRIAN_BOOT_SOURCE} # Available in LOCAL_PORTS
+.endif
+
+.if ${MACHINE_PLATFORM:MSunOS-*-x86_64} || make(distinfo) || make (makesum) || make(mdi)
+BOOT_VERSION:=         9.2.1
+BOOT_ARCHIVE:=         ghc-${BOOT_VERSION}-boot-x86_64-unknown-solaris2.tar.xz
+SITES.${BOOT_ARCHIVE}= https://us-central.manta.mnx.io/pkgsrc/public/pkg-bootstraps/
+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 ${OPSYS} == "SunOS"
+TOOL_DEPENDS+= libiconv>=1.9.1:../../converters/libiconv
+TOOL_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
+
+# Bootkits from the pre-Hadrian era has a different name for the top
+# directory in their archives. We can eliminate this conditional once all
+# of our bootkits are updated to 9.4 or later.
+.if ${BOOT_ARCHIVE:M9.2.*}
+BOOT_ARCHIVE_TOP_DIR=  ghc-${BOOT_VERSION}-boot
+.else
+BOOT_ARCHIVE_TOP_DIR=  ${BOOT_ARCHIVE:C/\.tar\..z$//}
+.endif
+
+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}"
+# <kludge>
+# "RTS ways" in "ghc --info" is totally bogus, because GhcRTSWays in
+# hadrian/bindist/config.mk.in does not reflect Hadrian user settings at
+# all. This leads Hadrian to believe that the stage-0 compiler has threaded
+# RTS despite it doesn't. Note that GHC devs are in the process of moving
+# the settings file from being generated by configure, to being generated
+# by the build system. This kludge is expected to go away in the (hopefully
+# near) future.
+       ${RUN}cd ${WRKDIR}/bootkit-dist/${BOOT_ARCHIVE_TOP_DIR} && \
+               ${SED} -e '/^GhcRTSWays/d' < mk/config.mk.in > mk/config.mk.in.tmp && \
+               ${MV} -f mk/config.mk.in.tmp mk/config.mk.in
+# </kludge>
+       ${RUN}cd ${WRKDIR}/bootkit-dist/${BOOT_ARCHIVE_TOP_DIR} && \
+               ${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 && \
+               ${PKGSRC_SET_ENV} ${ALL_ENV} \
+                       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) && ${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.common}
+HADRIAN_ARGS.boot+=    --docs=none
+.if ${OPSYS} == "FreeBSD"
+#   -fsplit-sections appears to corrupt the symbol table of stage 1
+#   libHSghc-*.a(Instances.o) and cause a linkage failure. Either Clang or
+#   LLD is doing something wrong, probably the former.
+HADRIAN_ARGS.boot+=    --flavour=bootkit
+.else
+HADRIAN_ARGS.boot+=    --flavour=bootkit+split_sections
+.endif
+
+# 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/
+# ${HADRIAN_BOOT_SOURCE} often contains libraries older than what we have
+# in pkgsrc. When that happens bootstrap.py tries to build Hadrian with
+# pkgsrc-installed libraries and fails because they aren't buildlinked. So
+# we must temporarily disable wrappers while building it.
+       saved_IFS="$$IFS"; \
+       IFS=":"; \
+       set -- $$PATH; \
+       IFS="$$saved_IFS"; \
+       pruned_path=; \
+       while ${TEST} "$$#" -gt 0; do \
+               if ${TEST} "$$1" != "${WRAPPER_BINDIR}"; then \
+                       if ${TEST} "$$pruned_path" = ""; then \
+                               pruned_path="$$1"; \
+                       else \
+                               pruned_path="$$pruned_path:$$1"; \
+                       fi; \
+               fi; \
+               shift; \
+       done; \
+       PATH="$$pruned_path"; \
+       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/ghc96/buildlink3.mk
diff -u /dev/null pkgsrc/lang/ghc96/buildlink3.mk:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/buildlink3.mk     Mon Oct 23 08:06:48 2023
@@ -0,0 +1,18 @@
+# $NetBSD: buildlink3.mk,v 1.1 2023/10/23 08:06:48 pho Exp $
+
+BUILDLINK_TREE+=       ghc
+
+.if !defined(GHC_BUILDLINK3_MK)
+GHC_BUILDLINK3_MK:=
+
+BUILDLINK_API_DEPENDS.ghc+=    ghc>=9.6.3
+BUILDLINK_ABI_DEPENDS.ghc+=    ghc>=9.6.3
+BUILDLINK_PKGSRCDIR.ghc?=      ../../lang/ghc96
+
+.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/ghc96/distinfo
diff -u /dev/null pkgsrc/lang/ghc96/distinfo:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/distinfo  Mon Oct 23 08:06:48 2023
@@ -0,0 +1,61 @@
+$NetBSD: distinfo,v 1.1 2023/10/23 08:06:48 pho Exp $
+
+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-solaris2.tar.xz) = 1d70d79ad765f0222e27f0a98915231d75dcb61b1ba4fb044ab531bc9930dc5f
+SHA512 (ghc-9.2.1-boot-x86_64-unknown-solaris2.tar.xz) = 7e55f4a002808aa1ae3c6053b129f0f0c0ac2d9f6b9ad5e4fc7c0fa9a09defeea2ed46a7e8d4c5a81213b631aacfa4cdd92b3bc724a6ee4de8b9d201840f3185
+Size (ghc-9.2.1-boot-x86_64-unknown-solaris2.tar.xz) = 69490428 bytes
+BLAKE2s (ghc-9.4.7-boot-aarch64-unknown-netbsd.tar.xz) = a691117b405b9f7954b954acc382b3357a9ff8c98151514c82d18d83da397940
+SHA512 (ghc-9.4.7-boot-aarch64-unknown-netbsd.tar.xz) = 1c917a52a020be3a1878f9d7e8e4c47d31180e54248c127a60706c1053a95b2d8a487f79e7fb5daa725178f271a7cc17e4e7b47ce2119f8546e259c63b9864d8
+Size (ghc-9.4.7-boot-aarch64-unknown-netbsd.tar.xz) = 90305900 bytes
+BLAKE2s (ghc-9.4.7-boot-hadrian.tar.gz) = 046c19d703e7a4ca5db28a69d3fd4f7b4cefe08cec0c81d00dcf106561839ae7
+SHA512 (ghc-9.4.7-boot-hadrian.tar.gz) = 9d7adeaf00c8eace027d1289aa4c1de7cf2b2c3b52fbcfb12a1d496f8ed897b9d1bf128c64e24d2971d4663f591a602556274f446badabed750ed5809b97600f
+Size (ghc-9.4.7-boot-hadrian.tar.gz) = 1501569 bytes
+BLAKE2s (ghc-9.4.7-boot-i386-unknown-freebsd.tar.xz) = f81c97f117156e8d4f1e7cec33a0e969a78ff1be7c9a5ebf212b9e521c1c23f4
+SHA512 (ghc-9.4.7-boot-i386-unknown-freebsd.tar.xz) = b32a9d4c6423cd858dcbd4f07e68d3ef49b879323b9eee36c6495574e15881ea70ff2aa3c02897165d6d9872693f4ee11c4fe86b613b49a7864ca4730ebbc865
+Size (ghc-9.4.7-boot-i386-unknown-freebsd.tar.xz) = 78875476 bytes
+BLAKE2s (ghc-9.4.7-boot-x86_64-apple-darwin.tar.xz) = 2ee9f0deb331b7ac3fbbb8dd6acb595b23329bfc3ee95c16faf9dba378f11525
+SHA512 (ghc-9.4.7-boot-x86_64-apple-darwin.tar.xz) = 5abedf9427a73b229beffdd6b1085bb11db100e7222b1e66b46a2cce72235d9c0152c4fd5c433676b3e132db277adf9f6a4267e60fcf48d1902ba50dbac81fa5
+Size (ghc-9.4.7-boot-x86_64-apple-darwin.tar.xz) = 111036360 bytes
+BLAKE2s (ghc-9.4.7-boot-x86_64-unknown-freebsd.tar.xz) = 9356f28874c23beb64472241f301079b66ad0de010af186c75c5f05d7df91206
+SHA512 (ghc-9.4.7-boot-x86_64-unknown-freebsd.tar.xz) = b40be23acea89133d2ec5049b920d3de9585c5cef7913a3b15623a00fa34f1ef51aafc33e7294b031621bcde2f3996c9a8c43f1b0f680903bbf1b1ba48e107fb
+Size (ghc-9.4.7-boot-x86_64-unknown-freebsd.tar.xz) = 77145928 bytes
+BLAKE2s (ghc-9.4.7-boot-x86_64-unknown-netbsd.tar.xz) = b920b6b54f5c1c6ab5fcbad14298ae742942e14da8105831df535926b9b9f529
+SHA512 (ghc-9.4.7-boot-x86_64-unknown-netbsd.tar.xz) = 4821dbf8f50c42a3427322c7488a07738d41da2236102571fc3051fd4d41a7a75754a1b27769365fc7f9d01ba0af65b87e51933077b3c36c2084ee3053479040
+Size (ghc-9.4.7-boot-x86_64-unknown-netbsd.tar.xz) = 77029664 bytes
+BLAKE2s (ghc-9.6.3-src.tar.xz) = 37591e3c04a97568e13928fa236774650bc7619f0a61f32e1598e22a2d7b08cb
+SHA512 (ghc-9.6.3-src.tar.xz) = 91f1a695746669b81f0102ad163d622ad43a1f09d95d104ef294be7896e47beeccb41294349bc45b50b0d84fe3fca013506eabd9d49cccb27176db1d934477e8
+Size (ghc-9.6.3-src.tar.xz) = 29346888 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) = dbad8dc9c1949e5fa7491dcb0f8648d0b70f5803
+SHA1 (patch-hadrian_bootstrap_src_Main.hs) = 70d7095c672c5e0e39ea08ff1beb2494e15e6143
+SHA1 (patch-hadrian_src_Builder.hs) = 6f831c10d9b1941068d832bae1bb65c8d3678c84
+SHA1 (patch-hadrian_src_Oracles_Setting.hs) = 498d1f810fa2f57151909eb672b73f137f1a7b01
+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) = 1db5c293a9f5691a5009b1a6d4ae9bf0a7109c2c
+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) = 30baa7f76f20d449feea0f634ca6b90e04d9481e
+SHA1 (patch-libraries_base_configure) = 4e02082cdfde8d927d12f3d2f3d98ace6d4ee116
+SHA1 (patch-libraries_ghc-boot_GHC_BaseDir.hs) = 27336cee41ba343c452a90ed004ba1ef2261482c
+SHA1 (patch-libraries_process_cbits_posix_fork__exec.c) = 8bc8aa1a3cfe8101257f77da98e5f877c59a36b0
+SHA1 (patch-libraries_terminfo_configure.ac) = 507a96209e32017faa96557d21a140bdb8f0b5c3
+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) = 414f0310793bf184cdac7546e3f81fee4821a05f
+SHA1 (patch-libraries_unix_System_Posix_Env_ByteString.hsc) = a579c00d7d5d7ffbb73f6499e09588d6417be123
+SHA1 (patch-libraries_unix_System_Posix_Signals.hsc) = ee59a04571881382bcfd9fc82bf196ff86a40ed5
+SHA1 (patch-m4_fptools__set__haskell__platform__vars.m4) = 8c7a7ab965f4df8a68bedb35c32ee32c59ac2c94
+SHA1 (patch-rts_linker_MMap.c) = c2abd34b8d39bb8f508a54bf3db25f53e113e45b
+SHA1 (patch-rts_linker_MMap.h) = 8228fabcdaeb1511191da9fc614ff94d3eee8fbd
+SHA1 (patch-utils_genprimopcode_Main.hs) = aff614cad3b7584ea7de069c0a0e77acd7c7ceef
+SHA1 (patch-utils_haddock_driver_Main.hs) = 26b015d3aef9fdff66e66c8e3d9a370a2dbd7067
+SHA1 (patch-utils_haddock_haddock.cabal) = c8a244f2f341b736b65b218590d1a3a8309f55ba
Index: pkgsrc/lang/ghc96/options.mk
diff -u /dev/null pkgsrc/lang/ghc96/options.mk:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/options.mk        Mon Oct 23 08:06:48 2023
@@ -0,0 +1,65 @@
+# $NetBSD: options.mk,v 1.1 2023/10/23 08:06:48 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 TOOL_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/ghc96/files/BOOTSTRAP.md
diff -u /dev/null pkgsrc/lang/ghc96/files/BOOTSTRAP.md:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/files/BOOTSTRAP.md        Mon Oct 23 08:06:48 2023
@@ -0,0 +1,93 @@
+<!-- $NetBSD: BOOTSTRAP.md,v 1.1 2023/10/23 08:06:48 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
+% ../../../files/extract-vanilla-package-db ./packages.conf
+(The next command fails with an error but you can safely ignore it.)
+% cabal build --package-db=clear --package-db=./packages.conf --only-configure
+% cp dist-newstyle/cache/plan.json bootstrap/plan-${BOOT_VERSION}.json
+% cd ./bootstrap
+% cabal build --allow-newer
+% cabal run -v0 --allow-newer hadrian-bootstrap-gen \
+      -- 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/ghc96/files/UserSettings.hs
diff -u /dev/null pkgsrc/lang/ghc96/files/UserSettings.hs:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/files/UserSettings.hs     Mon Oct 23 08:06:48 2023
@@ -0,0 +1,66 @@
+-- $NetBSD: UserSettings.hs,v 1.1 2023/10/23 08:06:48 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/ghc96/files/extract-vanilla-package-db
diff -u /dev/null pkgsrc/lang/ghc96/files/extract-vanilla-package-db:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/files/extract-vanilla-package-db  Mon Oct 23 08:06:48 2023
@@ -0,0 +1,29 @@
+#!/bin/sh
+set -eu
+
+# This script extracts the package DB originally came from GHC you are
+# using. Only needed when you create a hadrian bootstrap archive.
+
+if [ "$#" -lt 1 ]; then
+    echo >&2 "Usage: $0 PKG_DB_DIR"
+    exit
+fi
+PKG_DB_DIR="$1"
+
+mkdir -p "$PKG_DB_DIR"
+pkg_info -qL ghc | {
+    conf_dir_path=
+    while read path; do
+        conf_dir_removed="${path#*/package.conf.d/}"
+        if [ "$conf_dir_removed" != "$path" ]; then
+            echo "Copying ${path}..."
+            if [ "$conf_dir_path" = "" ]; then
+                conf_dir_path="${path%/${conf_dir_removed}}"
+            fi
+            sed -e "s|\\\${pkgroot}|${conf_dir_path}/..|g" \
+                < "${path}" \
+                > "${PKG_DB_DIR}/${conf_dir_removed}"
+        fi
+    done
+}
+ghc-pkg --package-db="$PKG_DB_DIR" recache

Index: pkgsrc/lang/ghc96/patches/patch-compiler_GHC_Driver_Pipeline_Execute.hs
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-compiler_GHC_Driver_Pipeline_Execute.hs:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-compiler_GHC_Driver_Pipeline_Execute.hs     Mon Oct 23 08:06:48 2023
@@ -0,0 +1,17 @@
+$NetBSD: patch-compiler_GHC_Driver_Pipeline_Execute.hs,v 1.1 2023/10/23 08:06:48 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/ghc96/patches/patch-compiler_GHC_SysTools_Process.hs
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-compiler_GHC_SysTools_Process.hs:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-compiler_GHC_SysTools_Process.hs    Mon Oct 23 08:06:48 2023
@@ -0,0 +1,32 @@
+$NetBSD: patch-compiler_GHC_SysTools_Process.hs,v 1.1 2023/10/23 08:06:48 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/ghc96/patches/patch-configure.ac
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-configure.ac:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-configure.ac        Mon Oct 23 08:06:48 2023
@@ -0,0 +1,17 @@
+$NetBSD: patch-configure.ac,v 1.1 2023/10/23 08:06:48 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/ghc96/patches/patch-hadrian_bindist_Makefile
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-hadrian_bindist_Makefile:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-hadrian_bindist_Makefile    Mon Oct 23 08:06:48 2023
@@ -0,0 +1,17 @@
+$NetBSD: patch-hadrian_bindist_Makefile,v 1.1 2023/10/23 08:06:48 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/ghc96/patches/patch-hadrian_bootstrap_bootstrap.py
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-hadrian_bootstrap_bootstrap.py:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-hadrian_bootstrap_bootstrap.py      Mon Oct 23 08:06:48 2023
@@ -0,0 +1,49 @@
+$NetBSD: patch-hadrian_bootstrap_bootstrap.py,v 1.1 2023/10/23 08:06:48 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.
+
+The hack to shake.cabal can be removed when [1] gets merged and GHC adopts
+it in hadrian/bootstrap/*.json.
+
+[1]: https://github.com/ndmitchell/shake/pull/836
+
+--- hadrian/bootstrap/bootstrap.py.orig        2023-09-21 11:30:31.000000000 +0000
++++ hadrian/bootstrap/bootstrap.py
+@@ -185,7 +185,27 @@ 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.
++    # https://github.com/ndmitchell/shake/pull/836
++    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)
++
++    # 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()
+@@ -481,6 +501,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()
+ 
+         print(dedent(f'''
Index: pkgsrc/lang/ghc96/patches/patch-hadrian_bootstrap_src_Main.hs
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-hadrian_bootstrap_src_Main.hs:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-hadrian_bootstrap_src_Main.hs       Mon Oct 23 08:06:48 2023
@@ -0,0 +1,27 @@
+$NetBSD: patch-hadrian_bootstrap_src_Main.hs,v 1.1 2023/10/23 08:06:48 pho Exp $
+
+Fix build with cabal-install-parsers >= 0.6. This doesn't affect normal
+builds. It's only for creating Hadrian bootstrap source archives.
+
+TODO: Upstream this.
+
+--- hadrian/bootstrap/src/Main.hs.orig 2023-09-21 11:30:31.000000000 +0000
++++ hadrian/bootstrap/src/Main.hs
+@@ -1,3 +1,5 @@
++{-# Language CPP #-}
++
+ module Main (main) where
+ 
+ import Control.Monad      (when)
+@@ -85,7 +87,11 @@ main2 meta plan = do
+                         return
+                             ( Hackage
+                             , Just $ fromIntegral (I.riRevision relInfo)
++#if MIN_VERSION_cabal_install_parsers(0, 6, 0)
++                            , P.sha256FromByteString $ I.getSHA256 $ I.riCabalHash relInfo
++#else
+                             , P.sha256FromByteString $ I.getSHA256 $ I.riCabal relInfo
++#endif
+                             )
+ 
+                     Nothing -> case P.uType unit of
Index: pkgsrc/lang/ghc96/patches/patch-hadrian_src_Builder.hs
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-hadrian_src_Builder.hs:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-hadrian_src_Builder.hs      Mon Oct 23 08:06:48 2023
@@ -0,0 +1,52 @@
+$NetBSD: patch-hadrian_src_Builder.hs,v 1.1 2023/10/23 08:06:48 pho Exp $
+
+Hunk #0, #2:
+    This is pkgsrc-specific. 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.
+
+Hunk #1:
+
+    primop.txt contains Unicode characters. Don't assume the current locale
+    is "*.UTF-8". TODO: Upstream this.
+
+    > _build/stage0/compiler/build/primops.txt: hGetContents: invalid argument (cannot decode byte sequence starting from 226)
+
+--- hadrian/src/Builder.hs.orig        2023-09-21 11:30:31.000000000 +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
+@@ -333,8 +334,8 @@ instance H.Builder Builder where
+                 GenApply -> captureStdout
+ 
+                 GenPrimopCode -> do
+-                    stdin <- readFile' input
+-                    Stdout stdout <- cmd' (Stdin stdin) [path] buildArgs
++                    need [input]
++                    Stdout stdout <- cmd' (FileStdin input) [path] buildArgs
+                     -- see Note [Capture stdout as a ByteString]
+                     writeFileChangedBS output stdout
+ 
+@@ -383,6 +384,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/ghc96/patches/patch-hadrian_src_Oracles_Setting.hs
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-hadrian_src_Oracles_Setting.hs:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-hadrian_src_Oracles_Setting.hs      Mon Oct 23 08:06:48 2023
@@ -0,0 +1,42 @@
+$NetBSD: patch-hadrian_src_Oracles_Setting.hs,v 1.1 2023/10/23 08:06:48 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.
+
+Merge request: https://gitlab.haskell.org/ghc/ghc/-/merge_requests/9767
+
+--- 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/ghc96/patches/patch-hadrian_src_Rules_BinaryDist.hs
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-hadrian_src_Rules_BinaryDist.hs:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-hadrian_src_Rules_BinaryDist.hs     Mon Oct 23 08:06:48 2023
@@ -0,0 +1,73 @@
+$NetBSD: patch-hadrian_src_Rules_BinaryDist.hs,v 1.1 2023/10/23 08:06:48 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/ghc96/patches/patch-hadrian_src_Settings_Builders_Ghc.hs
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-hadrian_src_Settings_Builders_Ghc.hs:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-hadrian_src_Settings_Builders_Ghc.hs        Mon Oct 23 08:06:48 2023
@@ -0,0 +1,75 @@
+$NetBSD: patch-hadrian_src_Settings_Builders_Ghc.hs,v 1.1 2023/10/23 08:06:48 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/ghc96/patches/patch-hadrian_src_Settings_Default.hs
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-hadrian_src_Settings_Default.hs:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-hadrian_src_Settings_Default.hs     Mon Oct 23 08:06:48 2023
@@ -0,0 +1,19 @@
+$NetBSD: patch-hadrian_src_Settings_Default.hs,v 1.1 2023/10/23 08:06:48 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/ghc96/patches/patch-hadrian_src_Settings_Packages.hs
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-hadrian_src_Settings_Packages.hs:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-hadrian_src_Settings_Packages.hs    Mon Oct 23 08:06:49 2023
@@ -0,0 +1,49 @@
+$NetBSD: patch-hadrian_src_Settings_Packages.hs,v 1.1 2023/10/23 08:06:49 pho Exp $
+
+Hunk #0, #1:
+  Don't assume we always build the threaded RTS. TODO: Upstream this.
+
+Hunk #2:
+  Hadrian does something unholy on i386 to gain speed but it seems to be
+  incompatible with LLD. Disable the speed hack to work around a linkage
+  failure. Ideally we should do this by detecting the type of linker but
+  not the OS.
+
+--- hadrian/src/Settings/Packages.hs.orig      2023-09-21 11:30:31.000000000 +0000
++++ hadrian/src/Settings/Packages.hs
+@@ -33,6 +33,7 @@ packageArgs = do
+       -- NB: in this function, "stage" is the stage of the compiler we are
+       -- using to build, but ghcDebugAssertions wants the stage of the compiler
+       -- we are building, which we get using succStage.
++    rtsWays          <- getRtsWays
+ 
+     mconcat
+         --------------------------------- base ---------------------------------
+@@ -163,7 +164,17 @@ packageArgs = do
+ 
+         -------------------------------- haddock -------------------------------
+         , package haddock ?
+-          builder (Cabal Flags) ? arg "in-ghc-tree"
++          builder (Cabal Flags) ? mconcat
++          [ arg "in-ghc-tree"
++          , ifM stage0
++                -- We build a threaded haddock on stage 1 if the
++                -- bootstrapping compiler supports it.
++                (threadedBootstrapper `cabalFlag` "threaded")
++
++                -- We build a threaded haddock on stage N, N>1 if the
++                -- configuration calls for it.
++                (any (wayUnit Threaded) rtsWays `cabalFlag` "threaded")
++          ]
+ 
+         ---------------------------------- text --------------------------------
+         , package text ? mconcat
+@@ -440,7 +451,7 @@ rtsPackageArgs = package rts ? do
+ speedHack :: Action Bool
+ speedHack = do
+     i386   <- anyTargetArch ["i386"]
+-    goodOS <- not <$> anyTargetOs ["darwin", "solaris2"]
++    goodOS <- not <$> anyTargetOs ["darwin", "solaris2", "freebsd"]
+     return $ i386 && goodOS
+ 
+ -- See @rts/ghc.mk@.
Index: pkgsrc/lang/ghc96/patches/patch-libraries_Cabal_Cabal_src_Distribution_Simple_GHC.hs
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-libraries_Cabal_Cabal_src_Distribution_Simple_GHC.hs:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-libraries_Cabal_Cabal_src_Distribution_Simple_GHC.hs        Mon Oct 23 08:06:49 2023
@@ -0,0 +1,33 @@
+$NetBSD: patch-libraries_Cabal_Cabal_src_Distribution_Simple_GHC.hs,v 1.1 2023/10/23 08:06:49 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/ghc96/patches/patch-libraries_base_GHC_Event_KQueue.hsc
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-libraries_base_GHC_Event_KQueue.hsc:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-libraries_base_GHC_Event_KQueue.hsc Mon Oct 23 08:06:49 2023
@@ -0,0 +1,16 @@
+$NetBSD: patch-libraries_base_GHC_Event_KQueue.hsc,v 1.1 2023/10/23 08:06:49 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/ghc96/patches/patch-libraries_base_System_CPUTime_Posix_Times.hsc
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-libraries_base_System_CPUTime_Posix_Times.hsc:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-libraries_base_System_CPUTime_Posix_Times.hsc       Mon Oct 23 08:06:49 2023
@@ -0,0 +1,16 @@
+$NetBSD: patch-libraries_base_System_CPUTime_Posix_Times.hsc,v 1.1 2023/10/23 08:06:49 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/ghc96/patches/patch-libraries_base_System_Environment.hs
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-libraries_base_System_Environment.hs:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-libraries_base_System_Environment.hs        Mon Oct 23 08:06:49 2023
@@ -0,0 +1,23 @@
+$NetBSD: patch-libraries_base_System_Environment.hs,v 1.1 2023/10/23 08:06:49 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/ghc96/patches/patch-libraries_base_System_Environment_ExecutablePath.hsc
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-libraries_base_System_Environment_ExecutablePath.hsc:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-libraries_base_System_Environment_ExecutablePath.hsc        Mon Oct 23 08:06:49 2023
@@ -0,0 +1,70 @@
+$NetBSD: patch-libraries_base_System_Environment_ExecutablePath.hsc,v 1.1 2023/10/23 08:06:49 pho Exp $
+
+Support executablePath on Solaris.
+
+Merge request:
+https://gitlab.haskell.org/ghc/ghc/-/merge_requests/9768
+
+--- 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/ghc96/patches/patch-libraries_base_configure
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-libraries_base_configure:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-libraries_base_configure    Mon Oct 23 08:06:49 2023
@@ -0,0 +1,18 @@
+$NetBSD: patch-libraries_base_configure,v 1.1 2023/10/23 08:06:49 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/ghc96/patches/patch-libraries_ghc-boot_GHC_BaseDir.hs
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-libraries_ghc-boot_GHC_BaseDir.hs:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-libraries_ghc-boot_GHC_BaseDir.hs   Mon Oct 23 08:06:49 2023
@@ -0,0 +1,85 @@
+$NetBSD: patch-libraries_ghc-boot_GHC_BaseDir.hs,v 1.1 2023/10/23 08:06:49 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.
+
+Merge request:
+https://gitlab.haskell.org/ghc/ghc/-/merge_requests/9768
+
+--- libraries/ghc-boot/GHC/BaseDir.hs.orig     2023-09-21 11:30:31.000000000 +0000
++++ libraries/ghc-boot/GHC/BaseDir.hs
+@@ -12,7 +12,11 @@
+ -- 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?]
+ 
+@@ -20,11 +24,9 @@ import Data.List (stripPrefix)
+ import Data.Maybe (listToMaybe)
+ 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
+ 
+@@ -43,17 +45,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
+ --
+@@ -65,14 +73,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/ghc96/patches/patch-libraries_process_cbits_posix_fork__exec.c
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-libraries_process_cbits_posix_fork__exec.c:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-libraries_process_cbits_posix_fork__exec.c  Mon Oct 23 08:06:49 2023
@@ -0,0 +1,20 @@
+$NetBSD: patch-libraries_process_cbits_posix_fork__exec.c,v 1.1 2023/10/23 08:06:49 pho Exp $
+
+Ensure _POSIX_PTHREAD_SEMANTICS is defined on SunOS.
+
+Pull request:
+https://github.com/haskell/process/pull/274
+
+--- libraries/process/cbits/posix/fork_exec.c.orig     2023-08-21 03:50:41.000000000 +0000
++++ libraries/process/cbits/posix/fork_exec.c
+@@ -1,6 +1,10 @@
+ /* ensure that execvpe is provided if possible */
+ #define _GNU_SOURCE 1
+ 
++#ifdef __sun
++#define _POSIX_PTHREAD_SEMANTICS
++#endif
++
+ #include "common.h"
+ 
+ #if defined(HAVE_FORK)
Index: pkgsrc/lang/ghc96/patches/patch-libraries_terminfo_configure.ac
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-libraries_terminfo_configure.ac:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-libraries_terminfo_configure.ac     Mon Oct 23 08:06:49 2023
@@ -0,0 +1,15 @@
+$NetBSD: patch-libraries_terminfo_configure.ac,v 1.1 2023/10/23 08:06:49 pho Exp $
+
+Don't use "==" as it's a Bash-ism. TODO: Upstream this.
+
+--- libraries/terminfo/configure.ac.orig       2023-10-23 02:48:49.253512773 +0000
++++ libraries/terminfo/configure.ac
+@@ -18,7 +18,7 @@ if test "x$curses_libraries" != "xNONE";
+   TERMINFO_LIB_DIRS=$curses_libraries
+ fi
+ 
+-if test "x$curses_library" == "xNONE"; then
++if test "x$curses_library" = "xNONE"; then
+ AC_PROG_CC()
+ 
+ AC_CHECK_LIB(tinfow, setupterm, HaveLibCurses=YES; LibCurses=tinfow,
Index: pkgsrc/lang/ghc96/patches/patch-libraries_time_lib_Data_Time_Clock_Internal_CTimespec.hsc
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-libraries_time_lib_Data_Time_Clock_Internal_CTimespec.hsc:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-libraries_time_lib_Data_Time_Clock_Internal_CTimespec.hsc   Mon Oct 23 08:06:49 2023
@@ -0,0 +1,23 @@
+$NetBSD: patch-libraries_time_lib_Data_Time_Clock_Internal_CTimespec.hsc,v 1.1 2023/10/23 08:06:49 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/ghc96/patches/patch-libraries_time_lib_Data_Time_Clock_Internal_CTimeval.hs
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-libraries_time_lib_Data_Time_Clock_Internal_CTimeval.hs:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-libraries_time_lib_Data_Time_Clock_Internal_CTimeval.hs     Mon Oct 23 08:06:49 2023
@@ -0,0 +1,33 @@
+$NetBSD: patch-libraries_time_lib_Data_Time_Clock_Internal_CTimeval.hs,v 1.1 2023/10/23 08:06:49 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/ghc96/patches/patch-libraries_unix_System_Posix_Env.hsc
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-libraries_unix_System_Posix_Env.hsc:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-libraries_unix_System_Posix_Env.hsc Mon Oct 23 08:06:49 2023
@@ -0,0 +1,16 @@
+$NetBSD: patch-libraries_unix_System_Posix_Env.hsc,v 1.1 2023/10/23 08:06:49 pho Exp $
+
+Suppress linker warnings about compatibility symbols by using "capi"
+instead of "ccall".
+
+--- libraries/unix/System/Posix/Env.hsc.orig   2023-09-21 11:31:41.000000000 +0000
++++ libraries/unix/System/Posix/Env.hsc
+@@ -141,7 +141,7 @@ putEnv keyvalue = do s <- newFilePath ke
+                      -- becomes part of the environment. #7342
+                      throwErrnoIfMinus1_ "putenv" (c_putenv s)
+ 
+-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/ghc96/patches/patch-libraries_unix_System_Posix_Env_ByteString.hsc
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-libraries_unix_System_Posix_Env_ByteString.hsc:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-libraries_unix_System_Posix_Env_ByteString.hsc      Mon Oct 23 08:06:49 2023
@@ -0,0 +1,16 @@
+$NetBSD: patch-libraries_unix_System_Posix_Env_ByteString.hsc,v 1.1 2023/10/23 08:06:49 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/ghc96/patches/patch-libraries_unix_System_Posix_Signals.hsc
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-libraries_unix_System_Posix_Signals.hsc:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-libraries_unix_System_Posix_Signals.hsc     Mon Oct 23 08:06:49 2023
@@ -0,0 +1,24 @@
+$NetBSD: patch-libraries_unix_System_Posix_Signals.hsc,v 1.1 2023/10/23 08:06:49 pho Exp $
+
+Suppress linker warnings about compatibility symbols.
+
+--- libraries/unix/System/Posix/Signals.hsc.orig       2023-09-21 11:31:41.000000000 +0000
++++ libraries/unix/System/Posix/Signals.hsc
+@@ -848,7 +848,7 @@ awaitSignal maybe_sigset = do
+ 
+ #if defined(HAVE_SIGNAL_H)
+ 
+-foreign import ccall unsafe "sigsuspend"
++foreign import capi unsafe "signal.h sigsuspend"
+   c_sigsuspend :: Ptr CSigset -> IO CInt
+ 
+ foreign import capi unsafe "signal.h sigdelset"
+@@ -860,7 +860,7 @@ foreign import capi unsafe "signal.h sig
+ foreign import capi unsafe "signal.h sigismember"
+   c_sigismember :: Ptr CSigset -> CInt -> IO CInt
+ 
+-foreign import ccall unsafe "sigpending"
++foreign import capi unsafe "signal.h sigpending"
+   c_sigpending :: Ptr CSigset -> IO CInt
+ 
+ #endif // HAVE_SIGNAL_H
Index: pkgsrc/lang/ghc96/patches/patch-m4_fptools__set__haskell__platform__vars.m4
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-m4_fptools__set__haskell__platform__vars.m4:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-m4_fptools__set__haskell__platform__vars.m4 Mon Oct 23 08:06:49 2023
@@ -0,0 +1,29 @@
+$NetBSD: patch-m4_fptools__set__haskell__platform__vars.m4,v 1.1 2023/10/23 08:06:49 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/ghc96/patches/patch-rts_linker_MMap.c
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-rts_linker_MMap.c:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-rts_linker_MMap.c   Mon Oct 23 08:06:49 2023
@@ -0,0 +1,128 @@
+$NetBSD: patch-rts_linker_MMap.c,v 1.1 2023/10/23 08:06:49 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.
+
+    Merge request:
+    https://gitlab.haskell.org/ghc/ghc/-/merge_requests/9769
+
+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.
+
+    Merge request:
+    https://gitlab.haskell.org/ghc/ghc/-/merge_requests/9769
+
+    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     2022-12-23 16:19:02.000000000 +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,17 +390,27 @@ 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();
+     }
+ 
+     /* Use MAP_32BIT if appropriate */
+-    if (region->end <= (void *) 0xffffffff) {
++    if (region && region->end <= (void *) 0xffffffff) {
+         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/ghc96/patches/patch-rts_linker_MMap.h
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-rts_linker_MMap.h:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-rts_linker_MMap.h   Mon Oct 23 08:06:49 2023
@@ -0,0 +1,15 @@
+$NetBSD: patch-rts_linker_MMap.h,v 1.1 2023/10/23 08:06:49 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/ghc96/patches/patch-utils_genprimopcode_Main.hs
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-utils_genprimopcode_Main.hs:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-utils_genprimopcode_Main.hs Mon Oct 23 08:06:49 2023
@@ -0,0 +1,29 @@
+$NetBSD: patch-utils_genprimopcode_Main.hs,v 1.1 2023/10/23 08:06:49 pho Exp $
+
+primops.txt contains Unicode characters. Don't assume the current locale is
+"*.UTF-8". TODO: Upstream this.
+
+> LC_ALL=C ./genprimopcode --data-decl < ./primops.txt
+> genprimopcode: <stdin>: hGetContents: invalid argument (cannot decode byte sequence starting from 226)
+
+--- utils/genprimopcode/Main.hs.orig   2023-10-23 03:34:51.628735818 +0000
++++ utils/genprimopcode/Main.hs
+@@ -13,6 +13,7 @@ import Data.Char
+ import Data.List (union, intersperse, intercalate, nub)
+ import Data.Maybe ( catMaybes )
+ import System.Environment ( getArgs )
++import System.IO ( hGetContents, hSetEncoding, stdin, utf8 )
+ 
+ vecOptions :: Entry -> [(String,String,Int)]
+ vecOptions i =
+@@ -116,7 +117,9 @@ main = getArgs >>= \args ->
+                    ++ unlines (map ("            "++) known_args)
+                   )
+        else
+-       do s <- getContents
++       do let input = stdin
++          hSetEncoding input utf8
++          s <- hGetContents input
+           case parse s of
+              Left err -> error ("parse error at " ++ (show err))
+              Right p_o_specs@(Info _ _)
Index: pkgsrc/lang/ghc96/patches/patch-utils_haddock_driver_Main.hs
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-utils_haddock_driver_Main.hs:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-utils_haddock_driver_Main.hs        Mon Oct 23 08:06:49 2023
@@ -0,0 +1,19 @@
+$NetBSD: patch-utils_haddock_driver_Main.hs,v 1.1 2023/10/23 08:06:49 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/ghc96/patches/patch-utils_haddock_haddock.cabal
diff -u /dev/null pkgsrc/lang/ghc96/patches/patch-utils_haddock_haddock.cabal:1.1
--- /dev/null   Mon Oct 23 08:06:49 2023
+++ pkgsrc/lang/ghc96/patches/patch-utils_haddock_haddock.cabal Mon Oct 23 08:06:49 2023
@@ -0,0 +1,27 @@
+$NetBSD: patch-utils_haddock_haddock.cabal,v 1.1 2023/10/23 08:06:49 pho Exp $
+
+Don't assume we always build the threaded RTS.
+
+Pull request:
+https://github.com/haskell/haddock/pull/1575
+
+--- 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