pkgsrc-WIP-changes archive

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

ghc7: add



Module Name:	pkgsrc-wip
Committed By:	Thomas Klausner <wiz%NetBSD.org@localhost>
Pushed By:	wiz
Date:		Wed Feb 12 13:35:56 2025 +0100
Changeset:	97c43d92886f7c77b082dbf7326527765d237913

Modified Files:
	Makefile
Added Files:
	ghc7/BOOTSTRAP.txt
	ghc7/DEINSTALL
	ghc7/DESCR
	ghc7/INSTALL
	ghc7/Makefile
	ghc7/bootstrap.mk
	ghc7/buildlink3.mk
	ghc7/distinfo
	ghc7/files/bootstrap.build.mk
	ghc7/patches/patch-configure
	ghc7/patches/patch-ghc.mk
	ghc7/patches/patch-libraries_base_GHC_Event_KQueue.hsc
	ghc7/patches/patch-libraries_base_System_Environment.hs
	ghc7/patches/patch-libraries_base_configure.ac
	ghc7/patches/patch-libraries_time_lib_Data_Time_Clock_CTimeval.hs
	ghc7/patches/patch-libraries_unix_System_Posix_Env.hsc
	ghc7/patches/patch-libraries_unix_System_Posix_Env_ByteString.hsc
	ghc7/patches/patch-libraries_unix_System_Posix_Files_Common.hsc
	ghc7/patches/patch-libraries_unix_System_Posix_Signals.hsc
	ghc7/patches/patch-libraries_unix_include_execvpe.h
	ghc7/patches/patch-rts_PosixSource.h
	ghc7/patches/patch-rts_ghc.mk
	ghc7/patches/patch-rules_build-package-way.mk
	ghc7/patches/patch-rules_distdir-way-opts.mk

Log Message:
ghc7: add

Requested by a Darwin-powerpc user.

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=97c43d92886f7c77b082dbf7326527765d237913

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

diffstat:
 Makefile                                           |   1 +
 ghc7/BOOTSTRAP.txt                                 |  20 ++
 ghc7/DEINSTALL                                     |   9 +
 ghc7/DESCR                                         |  15 ++
 ghc7/INSTALL                                       |   8 +
 ghc7/Makefile                                      | 195 +++++++++++++++
 ghc7/bootstrap.mk                                  | 269 +++++++++++++++++++++
 ghc7/buildlink3.mk                                 |  18 ++
 ghc7/distinfo                                      |  35 +++
 ghc7/files/bootstrap.build.mk                      |  41 ++++
 ghc7/patches/patch-configure                       |  15 ++
 ghc7/patches/patch-ghc.mk                          |  38 +++
 .../patch-libraries_base_GHC_Event_KQueue.hsc      |  16 ++
 .../patch-libraries_base_System_Environment.hs     |  23 ++
 ghc7/patches/patch-libraries_base_configure.ac     |  60 +++++
 ...-libraries_time_lib_Data_Time_Clock_CTimeval.hs |  33 +++
 .../patch-libraries_unix_System_Posix_Env.hsc      |  24 ++
 ...-libraries_unix_System_Posix_Env_ByteString.hsc |  24 ++
 ...ch-libraries_unix_System_Posix_Files_Common.hsc |  35 +++
 .../patch-libraries_unix_System_Posix_Signals.hsc  |  38 +++
 .../patches/patch-libraries_unix_include_execvpe.h |  15 ++
 ghc7/patches/patch-rts_PosixSource.h               |  15 ++
 ghc7/patches/patch-rts_ghc.mk                      |  14 ++
 ghc7/patches/patch-rules_build-package-way.mk      |  14 ++
 ghc7/patches/patch-rules_distdir-way-opts.mk       |  27 +++
 25 files changed, 1002 insertions(+)

diffs:
diff --git a/Makefile b/Makefile
index 48fcf97e18..dda742f4a7 100644
--- a/Makefile
+++ b/Makefile
@@ -1236,6 +1236,7 @@ SUBDIR+=	ggz-gtk-games
 SUBDIR+=	ggz-server
 SUBDIR+=	gh-dash
 SUBDIR+=	ghc-core
+SUBDIR+=	ghc7
 SUBDIR+=	ghdl-dev
 SUBDIR+=	ghdl-yosys-plugin
 SUBDIR+=	ghmm
diff --git a/ghc7/BOOTSTRAP.txt b/ghc7/BOOTSTRAP.txt
new file mode 100644
index 0000000000..0542f28f00
--- /dev/null
+++ b/ghc7/BOOTSTRAP.txt
@@ -0,0 +1,20 @@
+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 "cd lang/ghc7; make clean; make bootstrap"
+on the target platform and you'll have a bootkit for the target.
+
+--
+
+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.
diff --git a/ghc7/DEINSTALL b/ghc7/DEINSTALL
new file mode 100644
index 0000000000..dae09d89ea
--- /dev/null
+++ b/ghc7/DEINSTALL
@@ -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
diff --git a/ghc7/DESCR b/ghc7/DESCR
new file mode 100644
index 0000000000..48f53e1642
--- /dev/null
+++ b/ghc7/DESCR
@@ -0,0 +1,15 @@
+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 7.10.x release series, which is the last
+version that can bootstrap with 7.6.x. It will probably be removed
+once we make a separate package for GHC 8.0.x and get enough bootstrap
+kits for it.
diff --git a/ghc7/INSTALL b/ghc7/INSTALL
new file mode 100644
index 0000000000..a1c8ec4669
--- /dev/null
+++ b/ghc7/INSTALL
@@ -0,0 +1,8 @@
+#!/bin/sh
+#
+
+case ${STAGE} in
+    POST-INSTALL)
+        ${PKG_PREFIX}/bin/ghc-pkg recache
+        ;;
+esac
diff --git a/ghc7/Makefile b/ghc7/Makefile
new file mode 100644
index 0000000000..f4e73f742d
--- /dev/null
+++ b/ghc7/Makefile
@@ -0,0 +1,195 @@
+# $NetBSD: Makefile,v 1.56 2023/06/06 12:41:43 riastradh Exp $
+# -----------------------------------------------------------------------------
+# Package metadata
+#
+DISTNAME=	ghc-7.10.3-src
+PKGREVISION=	8
+PKGNAME=	${DISTNAME:S/-src$//}
+CATEGORIES=	lang
+MASTER_SITES=	https://downloads.haskell.org/~ghc/${PKGVERSION_NOREV}/
+EXTRACT_SUFX=	.tar.xz
+
+MAINTAINER=	pho%cielonegro.org@localhost
+HOMEPAGE=	https://www.haskell.org/ghc/
+COMMENT=	Compiler for the functional language Haskell - 7.10 Release Series
+LICENSE=	modified-bsd
+
+MKPIE_SUPPORTED=	no
+
+# GHC requires GHC to build itself. Formerly we could work around this
+# bootstrapping problem by creating a special archive containing C
+# sources compiled from Haskell sources, but that's no longer
+# possible. So we have to prepare stripped-down binaries sufficient to
+# bootstrap compilers for each platforms. If you want to build them
+# yourself, follow instructions in BOOTSTRAP.txt and ./bootstrap.mk
+BROKEN_EXCEPT_ON_PLATFORM+= \
+	Darwin-*-powerpc \
+	FreeBSD-*-i386 \
+	NetBSD-*-x86_64 \
+	SunOS-*-i386 \
+	SunOS-*-x86_64
+
+
+# -----------------------------------------------------------------------------
+# Distfiles
+#
+DISTFILES=	${DEFAULT_DISTFILES}
+WRKSRC=		${WRKDIR}/${PKGNAME_NOREV}
+
+# We don't want to extract all of the DISTFILEs.
+EXTRACT_ONLY=	${DEFAULT_DISTFILES}
+
+
+# -----------------------------------------------------------------------------
+# Tools
+#
+# The runtime dependency on perl is due to the evil splitter
+# (lib/${PKGNAME_NOREV}/ghc-split).
+USE_TOOLS+=			autoconf gmake gzip perl:run
+GNU_CONFIGURE=			yes
+USE_GNU_CONFIGURE_HOST=		no
+USE_LIBTOOL=			yes
+
+CONFIGURE_ARGS.common= \
+	--with-gcc=${CC:Q} \
+	--with-ld=${LD:Q} \
+	--with-curses-includes=${BUILDLINK_PREFIX.curses:Q}/${BUILDLINK_INCDIRS.curses:Q} \
+	--with-curses-libraries=${BUILDLINK_PREFIX.curses:Q}/${BUILDLINK_LIBDIRS.curses:Q} \
+	--with-gmp-includes=${BUILDLINK_PREFIX.gmp:Q}/${BUILDLINK_INCDIRS.gmp:Q} \
+	--with-gmp-libraries=${BUILDLINK_PREFIX.gmp:Q}/${BUILDLINK_LIBDIRS.gmp:Q} \
+	--with-iconv-includes=${BUILDLINK_PREFIX.iconv:Q}/${BUILDLINK_INCDIRS.iconv:Q} \
+	--with-iconv-libraries=${BUILDLINK_PREFIX.iconv:Q}/${BUILDLINK_LIBDIRS.iconv:Q} \
+	--with-system-libffi \
+	--with-ffi-includes=${BUILDLINK_PREFIX.libffi:Q}/${BUILDLINK_INCDIRS.libffi:Q} \
+	--with-ffi-libraries=${BUILDLINK_PREFIX.libffi:Q}/${BUILDLINK_LIBDIRS.libffi:Q}
+
+CONFIGURE_ARGS+=	${CONFIGURE_ARGS.common}
+
+CONFIGURE_ENV+= \
+	ac_cv_path_fp_prog_ar=${AR:Q} \
+	ac_cv_path_READELF=readelf \
+	PerlCmd=${PERL5:Q}
+
+# LDFLAGS is 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: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 runtime system of GHC (rts) tends to conflict with PaX MPROTECT
+# because it needs to generate various kinds of code at run time. The
+# RTS linker, whose job is to load *static* objects at run time,
+# doesn't play nice with ASLR either. This means most executables
+# produced by GHC need them to be disabled. Perhaps we should patch
+# rts/sm/Storage.c so that it uses ffi_closure_alloc(3) on every
+# platform, not just Linux, and also drop support for static library
+# loading and switch to dynamic libraries entirely.
+.for f in ghc ghc-pkg haddock hpc hsc2hs runghc
+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:Q}/libraries/base        && autoconf
+	${RUN} cd ${WRKSRC:Q}/libraries/integer-gmp && autoconf
+
+# Define the target "pre-configure" and non-standard "bootstrap".
+.include "../../lang/ghc7/bootstrap.mk"
+
+# Our pre-configure phase installs a bindist of bootstrapping compiler
+# directly into TOOLS_DIR so that ./configure can find it.
+
+# Here we generate mk/build.mk dynamically.
+post-configure:
+	${RUN} ${RM} -f ${WRKSRC:Q}/mk/build.mk
+
+# If there is HsColour in the PATH, GHC's build system tries to use it
+# without even checking if it really works. That's not what we
+# appreciate.
+	${RUN} ${ECHO} "HSCOLOUR_SRCS     = NO" >> ${WRKSRC:Q}/mk/build.mk
+
+# Don't even think of PDF.
+	${RUN} ${ECHO} "BUILD_DOCBOOK_PS  = NO" >> ${WRKSRC:Q}/mk/build.mk
+	${RUN} ${ECHO} "BUILD_DOCBOOK_PDF = NO" >> ${WRKSRC:Q}/mk/build.mk
+
+
+# -----------------------------------------------------------------------------
+# Installation/removal hooks
+#
+
+# Substitutions for INSTALL and DEINSTALL that handles package.cache.
+FILES_SUBST+=	GHC_VERSION=${PKGVERSION_NOREV}
+
+# We don't want package.cache to be in the PLIST.
+post-install:
+	${RM} -f ${DESTDIR:Q}${PREFIX:Q}/lib/${PKGNAME_NOREV}/package.conf.d/package.cache
+
+
+# -----------------------------------------------------------------------------
+# 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:Q}${PREFIX:Q} && \
+		${FIND} * \( -type f -o -type l \) | ${SORT};
+
+
+# -----------------------------------------------------------------------------
+# Sanity checks
+#
+
+# There is an unused script which don't pass the portability test.
+CHECK_PORTABILITY_SKIP+=	distrib/prep-bin-dist-mingw
+
+# ghc57207_0.s: failed to add inputs for merge: Resource temporarily unavailable
+CTF_FILES_SKIP+=		*/libHS*-ghc${PKGVERSION_NOREV}.*
+
+# ld: fatal: relocation error ... relocation requires reference symbol
+STRIP_FILES_SKIP+=		lib/${PKGNAME_NOREV}/libHSrts.a
+
+
+# -----------------------------------------------------------------------------
+# Dependencies
+#
+TOOL_DEPENDS+=	libxslt-[0-9]*:../../textproc/libxslt
+TOOL_DEPENDS+=	docbook-xsl-[0-9]*:../../textproc/docbook-xsl
+
+# NetBSD 9.x have libcurses with a newer major version than the
+# bootstrap kit is linked against. For now, work around this with
+# compat libraries.
+#
+# In a sandboxed build environment, we have to reach over to the
+# installed libraries themselves, since the symlinks compatXX adds
+# to the /usr tree can't be applied.
+.if ${OPSYS} == "NetBSD" && ${OPSYS_VERSION} >= 090000
+TOOL_DEPENDS+=	compat80-[0-9]*:../../emulators/compat80
+ALL_ENV+=	LD_LIBRARY_PATH=${PREFIX:Q}/emul/netbsd/usr/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"
diff --git a/ghc7/bootstrap.mk b/ghc7/bootstrap.mk
new file mode 100644
index 0000000000..90b44c2267
--- /dev/null
+++ b/ghc7/bootstrap.mk
@@ -0,0 +1,269 @@
+# $NetBSD: bootstrap.mk,v 1.33 2023/06/06 12:41:43 riastradh Exp $
+# -----------------------------------------------------------------------------
+# Select a bindist of bootstrapping compiler on a per-platform basis.
+#
+# BOOT_ARCHIVE
+#   This variable is set to the name of compressed archive file of a
+#   bootstrapping compiler for the current platform.
+#
+# BOOT_VERSION
+#   Version of the bootstrapping compiler to use. This can be
+#   overriden for specific platforms.
+#
+.include "../../mk/bsd.prefs.mk"
+
+# Notes on version dependencies:
+# * GHC 8.8.1 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.
+
+.if !empty(MACHINE_PLATFORM:MDarwin-*-powerpc) || make(distinfo) || make (makesum) || make(mdi)
+BOOT_VERSION:=	7.6.3
+BOOT_ARCHIVE:=	ghc-${BOOT_VERSION}-boot-powerpc-apple-darwin.tar.xz
+DISTFILES:=	${DISTFILES} ${BOOT_ARCHIVE} # Available in LOCAL_PORTS
+.endif
+
+.if !empty(MACHINE_PLATFORM:MFreeBSD-*-i386) || make(distinfo) || make (makesum) || make(mdi)
+BOOT_VERSION:=	7.10.3
+BOOT_ARCHIVE:=	ghc-${BOOT_VERSION}-boot-i386-unknown-freebsd.tar.xz
+DISTFILES:=	${DISTFILES} ${BOOT_ARCHIVE} # Available in LOCAL_PORTS
+.endif
+
+.if !empty(MACHINE_PLATFORM:MNetBSD-*-x86_64) || make(distinfo) || make (makesum) || make(mdi)
+BOOT_VERSION:=	7.10.3
+BOOT_ARCHIVE:=	ghc-${BOOT_VERSION}-boot-x86_64-unknown-netbsd.tar.xz
+DISTFILES:=	${DISTFILES} ${BOOT_ARCHIVE} # Available in LOCAL_PORTS
+.endif
+
+.if !empty(MACHINE_PLATFORM:MSunOS-*-i386) || make(distinfo) || make (makesum) || make(mdi)
+BOOT_VERSION:=	7.6.3
+BOOT_ARCHIVE:=	ghc-${BOOT_VERSION}-boot-i386-unknown-solaris2.tar.xz
+DISTFILES:=	${DISTFILES} ${BOOT_ARCHIVE} # Available in LOCAL_PORTS
+.endif
+
+.if !empty(MACHINE_PLATFORM:MSunOS-*-x86_64) || make(distinfo) || make (makesum) || make(mdi)
+BOOT_VERSION:=		7.6.3
+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}
+.endif
+
+.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
+
+# Existence of libelf makes LeadingUnderscore being "NO", which is
+# incorrect for this platform. See ${WRKSRC}/aclocal.m4
+# (FP_LEADING_UNDERSCORE)
+.if ${OPSYS} == "Darwin"
+CONFLICTS+=	libelf-[0-9]*
+.endif
+
+# current bootstrap binary kit for SmartOS is built with ncurses5
+.if !empty(MACHINE_PLATFORM:MSunOS-*) && !empty(OS_VARIANT:U:MSmartOS)
+TOOL_DEPENDS+=	ncurses>=5.0:../../devel/ncurses
+.endif
+
+
+# -----------------------------------------------------------------------------
+# The "pre-configure" hook
+#
+# Install a bootstrapping compiler directly into TOOLS_DIR so that
+# ./configure can find it.
+#
+USE_TOOLS+=	gmake xzcat xz gtar
+
+pre-configure:
+	${RUN}${TEST} -f ${DISTDIR:Q}/${DIST_SUBDIR:Q}/${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:Q}/build-extract
+	${RUN}cd ${WRKDIR:Q}/build-extract && \
+		${XZCAT} ${DISTDIR:Q}/${DIST_SUBDIR:Q}/${BOOT_ARCHIVE} | \
+		${GTAR} -xf -
+
+# It is important to install the stage-0 compiler with our rpath flags
+# configured, otherwise it will produce executables with no rpath and
+# fail in the configure phase.
+	@${PHASE_MSG} "Preparing bootstrapping compiler for ${PKGNAME}"
+	${RUN}cd ${WRKDIR:Q}/build-extract/ghc-${BOOT_VERSION}-boot && \
+		${PKGSRC_SETENV} ${CONFIGURE_ENV} ${SH} ./configure \
+			--prefix=${TOOLS_DIR:Q} && \
+		${PKGSRC_SETENV} ${MAKE_ENV} ${MAKE_PROGRAM} install
+
+
+# -----------------------------------------------------------------------------
+# An unusual target "bootstrap"
+#
+# Build a bootstrapping compiler using an already installed GHC. This
+# can certainly be impossible if you don't have one. It's absolutely
+# important to build it with the fewest possible run-time
+# dependencies, otherwise the resulting binary can easily get
+# unusable.
+
+# We don't want our bootkits to have a run-time dependency on
+# libgcc. In fact GHC's implementation of Haskell exception handling
+# does not depend on libgcc's facilities so it is attractive to do the
+# same for "normal" build... but we can't. This is because Haskell
+# programs may call C functions via FFI, and those C functions may
+# call C++ functions in turn, possibly in a different shared library.
+.include "../../mk/compiler.mk"
+.if make(bootstrap) && !empty(CC_VERSION:Mgcc-*)
+# But on some platforms, gcc automagically inserts a dependency on a
+# shared libgcc when -lpthread is given, which is seemingly
+# unavoidable.
+LDFLAGS+=	-static-libgcc
+.endif
+
+# Gather information about packages on which bootkit depends. It will
+# be used in the post-bootstrap phase.
+BOOT_GHC_DEPS:=		curses iconv
+BOOT_GHC_PKGSRC_DEPS:=	# empty
+.for pkg in ${BOOT_GHC_DEPS}
+
+# NOTE: pkglint(1) complains for including these builtin.mk files,
+# telling that we must include buildlink3.mk instead. But then how do
+# we get variables like USE_BUILTIN.${pkg} defined before including
+# ../../mk/bsd.pkg.mk, given that ../../mk/bsd.buildlink3.mk isn't
+# protected against multiple inclusion?
+CHECK_BUILTIN.${pkg}:=	yes
+.  if ${pkg} == "curses"
+.    include "../../mk/curses.builtin.mk"
+.  elif ${pkg} == "iconv"
+.    include "../../converters/libiconv/builtin.mk"
+.  endif
+CHECK_BUILTIN.${pkg}:=	no
+
+# BOOT_GHC_PKGSRC_DEPS is a list of packages whose pkgsrc version is
+# preferred over native one, either by user or ../../mk/platform
+.  if ${PREFER.${pkg}} == "pkgsrc"
+BOOT_GHC_PKGSRC_DEPS+=	${pkg}
+.  endif
+.endfor
+
+# Compiler wrappers must not remove -I/-L flags for the installed
+# GHC's libdir, otherwise the GHC we are going to use for building our
+# bootstraping kit will not work at all. 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, but for bootkits we can't do
+# that because that would mean bootkits have run-time dependency on
+# it. So we build the bundled one and statically link with it.
+CONFIGURE_ARGS.boot=	${CONFIGURE_ARGS.common}
+CONFIGURE_ARGS.boot+=	--without-system-libffi
+
+.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}/lndir:
+	@${PHASE_MSG} "Building lndir(1) to duplicate the source tree."
+	cd ${WRKSRC:Q}/utils/lndir && \
+		${PKG_CC:Q} lndir.c -o ${.TARGET}
+
+${WRKDIR}/stamp-lndir-boot: ${WRKDIR}/lndir
+	@${PHASE_MSG} "Duplicating the source tree for bootstrapping ${PKGNAME_NOREV}"
+	${MKDIR} ${WRKDIR:Q}/build-boot
+	cd ${WRKDIR:Q}/build-boot && \
+		${WRKDIR}/lndir -silent ../${PKGNAME_NOREV:Q}
+	${TOUCH} ${.TARGET}
+
+${WRKDIR}/stamp-configure-boot: ${WRKDIR}/stamp-lndir-boot
+	@${PHASE_MSG} "Configuring bootstrapping compiler ${PKGNAME_NOREV}"
+	${MKDIR} ${WRKDIR:Q}/build-boot
+	cd ${WRKDIR:Q}/build-boot && \
+		${PKGSRC_SETENV} ${CONFIGURE_ENV} ${SH} ./configure ${CONFIGURE_ARGS.boot} && \
+		${CP} -f ${FILESDIR:Q}/bootstrap.build.mk mk/build.mk
+	${TOUCH} ${.TARGET}
+
+${WRKDIR}/stamp-build-boot: ${WRKDIR}/stamp-configure-boot
+	@${PHASE_MSG} "Building bootstrapping compiler ${PKGNAME_NOREV}"
+	${RUN}cd ${WRKDIR:Q}/build-boot && ${BUILD_MAKE_CMD}
+	${TOUCH} ${.TARGET}
+
+${WRKDIR}/stamp-dist-boot: ${WRKDIR}/stamp-build-boot
+	@${PHASE_MSG} "Creating binary distribution of bootstrapping ${PKGNAME_NOREV}"
+	${RUN}cd ${WRKDIR:Q}/build-boot && ${BUILD_MAKE_CMD} binary-dist
+	${MV} -f ${WRKDIR:Q}/build-boot/${BOOT_ARCHIVE.new} ${WRKDIR:Q}/${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 it 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 !empty(USE_BUILTIN.${pkg}:M[nN][oO])
+	@${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} "=========================================================================="
diff --git a/ghc7/buildlink3.mk b/ghc7/buildlink3.mk
new file mode 100644
index 0000000000..c32496db43
--- /dev/null
+++ b/ghc7/buildlink3.mk
@@ -0,0 +1,18 @@
+# $NetBSD: buildlink3.mk,v 1.14 2022/06/28 11:34:12 wiz Exp $
+
+BUILDLINK_TREE+=	ghc
+
+.if !defined(GHC_BUILDLINK3_MK)
+GHC_BUILDLINK3_MK:=
+
+BUILDLINK_API_DEPENDS.ghc+=	ghc>=7.10.3<8
+BUILDLINK_ABI_DEPENDS.ghc+=	ghc>=7.10.3nb8
+BUILDLINK_PKGSRCDIR.ghc?=	../../lang/ghc7
+
+.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
diff --git a/ghc7/distinfo b/ghc7/distinfo
new file mode 100644
index 0000000000..4525344ce9
--- /dev/null
+++ b/ghc7/distinfo
@@ -0,0 +1,35 @@
+$NetBSD: distinfo,v 1.23 2021/11/21 03:01:59 pho Exp $
+
+BLAKE2s (ghc-7.10.3-boot-i386-unknown-freebsd.tar.xz) = e543cc1de4e350e96b816c9e86ff6d288b44ed7545da2f54958c161fb5fd4fb8
+SHA512 (ghc-7.10.3-boot-i386-unknown-freebsd.tar.xz) = 25a4f97489d9f49602f27b8b8e926c981d8a83c5e0d658dc6e63cc07a0af7702d2ef72b881429d822d219e3a1c5166099982f9eae42aece0a928c96e78e8d48b
+Size (ghc-7.10.3-boot-i386-unknown-freebsd.tar.xz) = 37245976 bytes
+BLAKE2s (ghc-7.10.3-boot-x86_64-unknown-netbsd.tar.xz) = d60ff3f0a1a9be196442f4249c7d216c7a9542e56a768bc5d2afa198566ea290
+SHA512 (ghc-7.10.3-boot-x86_64-unknown-netbsd.tar.xz) = fc00c383062f1506f437f9282ee81a076baad3d569266e1e626cc0f6f7e512f6169f0e60b402cc4a176cfa770c29a132ce1f8cf0aefb1c989824541255fb7643
+Size (ghc-7.10.3-boot-x86_64-unknown-netbsd.tar.xz) = 38203656 bytes
+BLAKE2s (ghc-7.10.3-src.tar.xz) = 56ec4295ce1a49b60d4aaae6d868418e68dba5f6a435ee7fd5ce88a80ac6ba0f
+SHA512 (ghc-7.10.3-src.tar.xz) = a39700ec6cb3396639c8d5349590d56d685777adabdec8ff6877dbce9f5f66daaab27fce205fdf3cceb6219b0a901b7cbe25b6fa228f765c725423b3c36e52b1
+Size (ghc-7.10.3-src.tar.xz) = 11731468 bytes
+BLAKE2s (ghc-7.6.3-boot-i386-unknown-solaris2.tar.xz) = 6ea83ec4d62c22b71ea9fca4f46306ede70cd31e48a5073cf69160353677c4f7
+SHA512 (ghc-7.6.3-boot-i386-unknown-solaris2.tar.xz) = 75df37e649f7d1467fffee1c7d74281dd91d56934537621d4e9f00e6447a45f0f87e91b5e136b1581a9346149e29122fb0a0780ed0b1ddce091c4de44636ba59
+Size (ghc-7.6.3-boot-i386-unknown-solaris2.tar.xz) = 29895032 bytes
+BLAKE2s (ghc-7.6.3-boot-powerpc-apple-darwin.tar.xz) = 3bf8539e3036442caec6972ee29e0768f4e59a2e0d36a700b386dc47bad2c9ee
+SHA512 (ghc-7.6.3-boot-powerpc-apple-darwin.tar.xz) = 5cb62b1571f197d85e6e0506c0fc4fa4d9d5f53405bfd0d8ba1df3bad857710ae818048aa6002df184139d73ab556e1226eb648394c7f9dbe170e540ea8a4cb6
+Size (ghc-7.6.3-boot-powerpc-apple-darwin.tar.xz) = 33660776 bytes
+BLAKE2s (ghc-7.6.3-boot-x86_64-unknown-solaris2.tar.xz) = e8c839a6eb25d7e4f47d10f9122120e8336261ed05d42ad7620fe24b1a05c2b5
+SHA512 (ghc-7.6.3-boot-x86_64-unknown-solaris2.tar.xz) = f253e82beaec3f0f06fdaf48d02d7ceabe43d54582992f0bac68e7be40dd9fbcafee4e84c15a470c3648a3aee16a0ad708a5a409d6c490e5687f9568109e5d46
+Size (ghc-7.6.3-boot-x86_64-unknown-solaris2.tar.xz) = 33541060 bytes
+SHA1 (patch-configure) = dafe8dee52e3e79e1ce9307fb62f283691bdb568
+SHA1 (patch-ghc.mk) = d1131c7582a189775b307b830f860089f5afe346
+SHA1 (patch-libraries_base_GHC_Event_KQueue.hsc) = 8ee5da667a241a05fde3c580d3dc9bdc05aa5f00
+SHA1 (patch-libraries_base_System_Environment.hs) = fd786a7aa2058b5d86d4646e3816fb53ea0bf59f
+SHA1 (patch-libraries_base_configure.ac) = dd6132c5335d7e0421ec2181ebb5a34bb162e255
+SHA1 (patch-libraries_time_lib_Data_Time_Clock_CTimeval.hs) = 79f17fe77cc5469a90c811682a937c8d711d59c5
+SHA1 (patch-libraries_unix_System_Posix_Env.hsc) = 87bcd3b401fce656025777357a26a1ae514fd28d
+SHA1 (patch-libraries_unix_System_Posix_Env_ByteString.hsc) = 2ce83b35734244d49b037f8cac5eaa9d548f778c
+SHA1 (patch-libraries_unix_System_Posix_Files_Common.hsc) = a80945863d7bd8f5f65af5371d3ab090071ea24e
+SHA1 (patch-libraries_unix_System_Posix_Signals.hsc) = 6a2b9a527730ec593b70e827fdc1aaeccc575dad
+SHA1 (patch-libraries_unix_include_execvpe.h) = a134be89b4bdd49eb5c5ed45756eb3a4ce5951a5
+SHA1 (patch-rts_PosixSource.h) = 604608791f33245d9305dcbd6d9d5979fe162f21
+SHA1 (patch-rts_ghc.mk) = 661fe3b57280809f0f00dc449bd4585fafd3f9c0
+SHA1 (patch-rules_build-package-way.mk) = c161044f44fc8a52726492a52366cff7b394f48c
+SHA1 (patch-rules_distdir-way-opts.mk) = 66b0da62629f251a74ca7ca38dcb996dcb555e59
diff --git a/ghc7/files/bootstrap.build.mk b/ghc7/files/bootstrap.build.mk
new file mode 100644
index 0000000000..7a9324a1c2
--- /dev/null
+++ b/ghc7/files/bootstrap.build.mk
@@ -0,0 +1,41 @@
+# -*- makefile-gmake -*-
+#
+# This is a build conf for bootstrapping compilers.
+#
+
+# We don't want any docs.
+HADDOCK_DOCS       = NO
+BUILD_DOCBOOK_HTML = NO
+BUILD_DOCBOOK_PS   = NO
+BUILD_DOCBOOK_PDF  = NO
+BUILD_MAN          = NO
+
+# Enabling evil-splitter reduces bindist size, which is good. However
+# it introduces a run-time dependency on perl, which is unacceptable.
+SplitObjs          = NO
+
+# We only want vanilla libraries and rts. No profiling, no shared
+# libraries, no debugging, no event logging.
+GhcLibWays         = v
+GhcRTSWays         =
+
+# I'm not sure disabling GHCi significantly reduces the bindist size,
+# but we don't need it anyway.
+GhcWithInterpreter = NO
+
+# We don't want in-place GMP to be statically linked as it increases
+# the bindist size. Dynamic linkage is even worse.
+INTEGER_LIBRARY    = integer-simple
+
+# We'd like to distinguish bootstrapping bindists from normal ones.
+BIN_DIST_NAME      = ghc-$(ProjectVersion)-boot
+
+# Don't build or use dynamic Haskell libraries.
+DYNAMIC_GHC_PROGRAMS = NO
+
+# We want our bootkits to be as small as possible, even though `xz
+# -9e' is very slow and consumes about 680 MiB of memory.
+TAR_COMP           = xz
+TAR_COMP_CMD       = $(XZ_CMD)
+TAR_COMP_EXT       = xz
+XZ_CMD             = xz --verbose -9 --extreme
diff --git a/ghc7/patches/patch-configure b/ghc7/patches/patch-configure
new file mode 100644
index 0000000000..242dd69757
--- /dev/null
+++ b/ghc7/patches/patch-configure
@@ -0,0 +1,15 @@
+$NetBSD: patch-configure,v 1.1 2020/02/14 23:36:54 jperkin Exp $
+
+ld: fatal: symbol '__dtrace_HaskellEvent___task-create' is multiply-defined
+
+--- configure.orig	2015-11-30 23:39:05.000000000 +0000
++++ configure
+@@ -9125,7 +9125,7 @@ fi
+ 
+ 
+ if test -n "$DtraceCmd"; then
+-  if test "x$TargetOS_CPP-$TargetVendor_CPP" = "xdarwin-apple" -o "x$TargetOS_CPP-$TargetVendor_CPP" = "xsolaris2-unknown"; then
++  if test "x$TargetOS_CPP-$TargetVendor_CPP" = "xdarwin-apple"; then
+     HaveDtrace=YES
+   fi
+ fi
diff --git a/ghc7/patches/patch-ghc.mk b/ghc7/patches/patch-ghc.mk
new file mode 100644
index 0000000000..febefd2218
--- /dev/null
+++ b/ghc7/patches/patch-ghc.mk
@@ -0,0 +1,38 @@
+$NetBSD: patch-ghc.mk,v 1.3 2021/04/30 18:52:05 pho Exp $
+
+* Use the wrapper scripts for ghc as we can't use the ones from the DESTDIR
+  as the libraries are not in the right place yet.
+
+* Fix building bootkits: we don't generate documentation for them.
+
+--- ghc.mk.orig	2015-10-19 15:59:58.000000000 +0000
++++ ghc.mk
+@@ -897,6 +897,12 @@ endif
+ 
+ INSTALLED_PACKAGE_CONF=$(DESTDIR)$(topdir)/package.conf.d
+ 
++ifneq "$(BINDIST)" "YES"
++# when installing ghc-stage2 we can't run target's
++# 'ghc-pkg' and 'ghc-stage2' but those are needed for registration.
++INSTALLED_GHC_REAL=$(TOP)/inplace/bin/ghc-stage1
++INSTALLED_GHC_PKG_REAL=$(TOP)/utils/ghc-pkg/dist/build/tmp/ghc-pkg
++else
+ # Install packages in the right order, so that ghc-pkg doesn't complain.
+ # Also, install ghc-pkg first.
+ ifeq "$(Windows_Host)" "NO"
+@@ -906,6 +912,7 @@ else
+ INSTALLED_GHC_REAL=$(DESTDIR)$(bindir)/ghc.exe
+ INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(bindir)/ghc-pkg.exe
+ endif
++endif
+ 
+ # Set the INSTALL_DISTDIR_p for each package; compiler is special
+ $(foreach p,$(filter-out compiler,$(INSTALL_PACKAGES)),\
+@@ -989,7 +996,6 @@ $(eval $(call bindist,.,\
+     $(INSTALL_LIBRARY_DOCS) \
+     $(addsuffix /*,$(INSTALL_HTML_DOC_DIRS)) \
+     docs/index.html \
+-    compiler/stage2/doc \
+     $(wildcard libraries/*/dist-install/doc/) \
+     $(wildcard libraries/*/*/dist-install/doc/) \
+     $(filter-out settings,$(INSTALL_LIBS)) \
diff --git a/ghc7/patches/patch-libraries_base_GHC_Event_KQueue.hsc b/ghc7/patches/patch-libraries_base_GHC_Event_KQueue.hsc
new file mode 100644
index 0000000000..6eee011b63
--- /dev/null
+++ b/ghc7/patches/patch-libraries_base_GHC_Event_KQueue.hsc
@@ -0,0 +1,16 @@
+$NetBSD: patch-libraries_base_GHC_Event_KQueue.hsc,v 1.1 2019/12/29 16:59:09 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
diff --git a/ghc7/patches/patch-libraries_base_System_Environment.hs b/ghc7/patches/patch-libraries_base_System_Environment.hs
new file mode 100644
index 0000000000..62282d5120
--- /dev/null
+++ b/ghc7/patches/patch-libraries_base_System_Environment.hs
@@ -0,0 +1,23 @@
+$NetBSD: patch-libraries_base_System_Environment.hs,v 1.1 2019/12/29 16:59:09 pho Exp $
+
+Suppress linker warnings about compatibility syscall wrappers by using
+"capi" instead of "ccall".
+
+--- libraries/base/System/Environment.hs.orig	2019-12-26 18:13:03.344291616 +0000
++++ libraries/base/System/Environment.hs
+@@ -1,5 +1,6 @@
+ {-# LANGUAGE Safe #-}
+ {-# LANGUAGE CPP #-}
++{-# LANGUAGE CApiFFI #-}
+ 
+ -----------------------------------------------------------------------------
+ -- |
+@@ -302,7 +303,7 @@ putEnv keyvalue = do
+   -- enviroment.
+   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
+ 
+ -- | @unSet name@ removes the specified environment variable from the
diff --git a/ghc7/patches/patch-libraries_base_configure.ac b/ghc7/patches/patch-libraries_base_configure.ac
new file mode 100644
index 0000000000..078f32555a
--- /dev/null
+++ b/ghc7/patches/patch-libraries_base_configure.ac
@@ -0,0 +1,60 @@
+$NetBSD: patch-libraries_base_configure.ac,v 1.2 2015/02/16 07:04:58 pho Exp $
+
+Upstream Trac #10093:
+https://ghc.haskell.org/trac/ghc/ticket/10093
+
+Do not clobber CPPFLAGS nor LDFLAGS:
+
+When we are using pkgsrc converters/libiconv, we have libiconv.so in
+${PREFIX}/lib and "-Wl,-R${PREFIX}/lib" in LDFLAGS. In this case
+FP_SEARCH_LIBS_PROTO(iconv) appends "-liconv" to $LIBS so it will be
+linked to any conftest executables that follow, including one which
+will be generated by AC_CHECK_SIZEOF().
+
+The problem is that if libraries listed in $LIBS are in a non-standard
+path while rpath flags are missing (due to LDFLAGS being clobbered in
+this case), conftest executables cannot run even if they can be
+linked. And if anything goes wrong during AC_CHECK_SIZEOF(T), it
+considers sizeof(T) as 0 unless T is known to be an existing type:
+
+  ...
+  checking for library containing iconv... -liconv
+  checking for library containing locale_charset... none required
+  checking size of struct MD5Context... 0
+  ...
+
+This means SIZEOF_STRUCT_MD5CONTEXT gets defined to 0,
+GHC.Fingerprint.fingerprintData allocates 0 bytes on the heap,
+MD5Init/Update/Final corrupts the heap and then Bad Things will
+happen.
+
+--- libraries/base/configure.ac.orig	2013-04-18 21:30:14.000000000 +0000
++++ libraries/base/configure.ac
+@@ -70,13 +70,13 @@ dnl-------------------------------------
+ AC_ARG_WITH([iconv-includes],
+   [AC_HELP_STRING([--with-iconv-includes],
+     [directory containing iconv.h])],
+-    [ICONV_INCLUDE_DIRS=$withval; CPPFLAGS="-I$withval"],
++    [ICONV_INCLUDE_DIRS=$withval; CPPFLAGS="-I$withval $CPPFLAGS"],
+     [ICONV_INCLUDE_DIRS=])
+ 
+ AC_ARG_WITH([iconv-libraries],
+   [AC_HELP_STRING([--with-iconv-libraries],
+     [directory containing iconv library])],
+-    [ICONV_LIB_DIRS=$withval; LDFLAGS="-L$withval"],
++    [ICONV_LIB_DIRS=$withval; LDFLAGS="-L$withval $LDFLAGS"],
+     [ICONV_LIB_DIRS=])
+ 
+ AC_SUBST(ICONV_INCLUDE_DIRS)
+@@ -183,7 +183,10 @@ fi
+ 
+ # Hack - md5.h needs HsFFI.h.  Is there a better way to do this?
+ CFLAGS="-I../../includes $CFLAGS"
+-AC_CHECK_SIZEOF([struct MD5Context], ,[#include "include/md5.h"])
++dnl Calling AC_CHECK_TYPE(T) makes AC_CHECK_SIZEOF(T) abort on failure
++dnl instead of considering sizeof(T) as 0.
++AC_CHECK_TYPE([struct MD5Context], [], [], [#include "include/md5.h"])
++AC_CHECK_SIZEOF([struct MD5Context], [], [#include "include/md5.h"])
+ 
+ AC_SUBST(EXTRA_LIBS)
+ AC_CONFIG_FILES([base.buildinfo])
diff --git a/ghc7/patches/patch-libraries_time_lib_Data_Time_Clock_CTimeval.hs b/ghc7/patches/patch-libraries_time_lib_Data_Time_Clock_CTimeval.hs
new file mode 100644
index 0000000000..14b351b16b
--- /dev/null
+++ b/ghc7/patches/patch-libraries_time_lib_Data_Time_Clock_CTimeval.hs
@@ -0,0 +1,33 @@
+$NetBSD: patch-libraries_time_lib_Data_Time_Clock_CTimeval.hs,v 1.1 2019/12/29 16:59:09 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/CTimeval.hs.orig	2015-07-23 22:04:53.000000000 +0000
++++ libraries/time/lib/Data/Time/Clock/CTimeval.hs
+@@ -1,3 +1,4 @@
++{-# LANGUAGE CApiFFI #-}
+ -- #hide
+ module Data.Time.Clock.CTimeval where
+ 
+@@ -24,7 +25,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
diff --git a/ghc7/patches/patch-libraries_unix_System_Posix_Env.hsc b/ghc7/patches/patch-libraries_unix_System_Posix_Env.hsc
new file mode 100644
index 0000000000..7462dfc731
--- /dev/null
+++ b/ghc7/patches/patch-libraries_unix_System_Posix_Env.hsc
@@ -0,0 +1,24 @@
+$NetBSD: patch-libraries_unix_System_Posix_Env.hsc,v 1.1 2019/12/31 07:10:30 pho Exp $
+
+Suppress linker warnings about compatibility symbols by using "capi"
+instead of "ccall".
+
+--- libraries/unix/System/Posix/Env.hsc.orig	2019-12-31 00:05:02.553011557 +0000
++++ libraries/unix/System/Posix/Env.hsc
+@@ -3,6 +3,7 @@
+ #elif __GLASGOW_HASKELL__ >= 703
+ {-# LANGUAGE Trustworthy #-}
+ #endif
++{-# LANGUAGE CApiFFI #-}
+ -----------------------------------------------------------------------------
+ -- |
+ -- Module      :  System.Posix.Env
+@@ -142,7 +143,7 @@ putEnv keyvalue = do s <- newFilePath ke
+       newFilePath fp = getFileSystemEncoding >>= \enc -> GHC.newCString enc fp
+ #endif
+ 
+-foreign import ccall unsafe "putenv"
++foreign import capi unsafe "stdlib.h putenv"
+    c_putenv :: CString -> IO CInt
+ 
+ {- |The 'setEnv' function inserts or resets the environment variable name in
diff --git a/ghc7/patches/patch-libraries_unix_System_Posix_Env_ByteString.hsc b/ghc7/patches/patch-libraries_unix_System_Posix_Env_ByteString.hsc
new file mode 100644
index 0000000000..2b2acf5f02
--- /dev/null
+++ b/ghc7/patches/patch-libraries_unix_System_Posix_Env_ByteString.hsc
@@ -0,0 +1,24 @@
+$NetBSD: patch-libraries_unix_System_Posix_Env_ByteString.hsc,v 1.1 2019/12/31 07:10:30 pho Exp $
+
+Suppress linker warnings about compatibility symbols by using "capi"
+instead of "ccall".
+
+--- libraries/unix/System/Posix/Env/ByteString.hsc.orig	2019-12-31 00:06:05.528517546 +0000
++++ libraries/unix/System/Posix/Env/ByteString.hsc
+@@ -4,6 +4,7 @@
+ {-# OPTIONS_GHC -fno-warn-trustworthy-safe #-}
+ #endif
+ #endif
++{-# LANGUAGE CApiFFI #-}
+ 
+ -----------------------------------------------------------------------------
+ -- |
+@@ -118,7 +119,7 @@ putEnv :: ByteString -> IO ()
+ putEnv keyvalue = B.useAsCString keyvalue $ \s ->
+   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
diff --git a/ghc7/patches/patch-libraries_unix_System_Posix_Files_Common.hsc b/ghc7/patches/patch-libraries_unix_System_Posix_Files_Common.hsc
new file mode 100644
index 0000000000..19f99641e5
--- /dev/null
+++ b/ghc7/patches/patch-libraries_unix_System_Posix_Files_Common.hsc
@@ -0,0 +1,35 @@
+$NetBSD: patch-libraries_unix_System_Posix_Files_Common.hsc,v 1.1 2019/12/29 16:59:09 pho Exp $
+
+Suppress linker warnings about compatibility syscall wrappers by using
+"capi" instead of "ccall".
+
+--- libraries/unix/System/Posix/Files/Common.hsc.orig	2019-12-26 18:14:23.311242161 +0000
++++ libraries/unix/System/Posix/Files/Common.hsc
+@@ -1,6 +1,7 @@
+ #ifdef __GLASGOW_HASKELL__
+ {-# LANGUAGE Trustworthy #-}
+ #endif
++{-# LANGUAGE CApiFFI #-}
+ -----------------------------------------------------------------------------
+ -- |
+ -- Module      :  System.Posix.Files.Common
+@@ -456,16 +457,16 @@ toCTimeVal t = CTimeVal sec (truncate $ 
+     (sec, frac) = if (frac' < 0) then (sec' - 1, frac' + 1) else (sec', frac')
+     (sec', frac') = properFraction $ toRational t
+ 
+-foreign import ccall unsafe "utimes"
++foreign import capi unsafe "sys/time.h utimes"
+     c_utimes :: CString -> Ptr CTimeVal -> IO CInt
+ 
+ #ifdef HAVE_LUTIMES
+-foreign import ccall unsafe "lutimes"
++foreign import capi unsafe "sys/time.h lutimes"
+     c_lutimes :: CString -> Ptr CTimeVal -> IO CInt
+ #endif
+ 
+ #if HAVE_FUTIMES
+-foreign import ccall unsafe "futimes"
++foreign import capi unsafe "sys/time.h futimes"
+     c_futimes :: CInt -> Ptr CTimeVal -> IO CInt
+ #endif
+ 
diff --git a/ghc7/patches/patch-libraries_unix_System_Posix_Signals.hsc b/ghc7/patches/patch-libraries_unix_System_Posix_Signals.hsc
new file mode 100644
index 0000000000..ba0e0e9194
--- /dev/null
+++ b/ghc7/patches/patch-libraries_unix_System_Posix_Signals.hsc
@@ -0,0 +1,38 @@
+$NetBSD: patch-libraries_unix_System_Posix_Signals.hsc,v 1.2 2019/12/29 16:59:09 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:
+
+  .../libHSunix-2.6.0.1.a(Signals.o): In function `s4SG_info':
+  (.text+0x3a3e): warning: warning: reference to compatibility
+  sigsuspend(); include <signal.h> for correct reference
+  .../libHSunix-2.6.0.1.a(Signals.o): In function `s5uV_info':
+  (.text+0x6adb): warning: warning: reference to compatibility
+  sigpending(); include <signal.h> for 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/unix/System/Posix/Signals.hsc.orig	2015-07-23 22:04:56.000000000 +0000
++++ libraries/unix/System/Posix/Signals.hsc
+@@ -603,7 +603,7 @@ awaitSignal maybe_sigset = do
+   -- XXX My manpage says it can also return EFAULT. And why is ignoring
+   -- EINTR the right thing to do?
+ 
+-foreign import ccall unsafe "sigsuspend"
++foreign import capi unsafe "signal.h sigsuspend"
+   c_sigsuspend :: Ptr CSigset -> IO CInt
+ #endif
+ 
+@@ -638,5 +638,5 @@ foreign import capi unsafe "signal.h sig
+   c_sigismember :: Ptr CSigset -> CInt -> IO CInt
+ #endif /* __HUGS__ */
+ 
+-foreign import ccall unsafe "sigpending"
++foreign import capi unsafe "signal.h sigpending"
+   c_sigpending :: Ptr CSigset -> IO CInt
diff --git a/ghc7/patches/patch-libraries_unix_include_execvpe.h b/ghc7/patches/patch-libraries_unix_include_execvpe.h
new file mode 100644
index 0000000000..b84a80d734
--- /dev/null
+++ b/ghc7/patches/patch-libraries_unix_include_execvpe.h
@@ -0,0 +1,15 @@
+$NetBSD: patch-libraries_unix_include_execvpe.h,v 1.2 2019/12/29 16:59:09 pho Exp $
+
+Don't conflict with builtin execvpe(3).
+
+--- libraries/unix/include/execvpe.h.orig	2015-07-23 22:04:56.000000000 +0000
++++ libraries/unix/include/execvpe.h
+@@ -16,8 +16,6 @@ __hsunix_execvpe(const char *name, char 
+ #if HAVE_EXECVPE
+ # define _GNU_SOURCE
+ # include <unistd.h>
+-extern int
+-execvpe(const char *name, char *const argv[], char *const envp[]);
+ #else
+ # define execvpe(name,argv,envp) __hsunix_execvpe(name,argv,envp)
+ #endif
diff --git a/ghc7/patches/patch-rts_PosixSource.h b/ghc7/patches/patch-rts_PosixSource.h
new file mode 100644
index 0000000000..0b80ec687c
--- /dev/null
+++ b/ghc7/patches/patch-rts_PosixSource.h
@@ -0,0 +1,15 @@
+$NetBSD: patch-rts_PosixSource.h,v 1.2 2019/12/29 16:59:09 pho Exp $
+
+Set _XOPEN_SOURCE correctly on SunOS. Fixed in later versions.
+
+--- rts/PosixSource.h.orig	2013-04-18 21:22:46.000000000 +0000
++++ rts/PosixSource.h
+@@ -11,7 +11,7 @@
+ 
+ #include <ghcplatform.h>
+ 
+-#if defined(freebsd_HOST_OS) || defined(dragonfly_HOST_OS)
++#if defined(freebsd_HOST_OS) || defined(dragonfly_HOST_OS) || (defined(__sun) && __STDC_VERSION__-0 >= 199901L)
+ #define _POSIX_C_SOURCE 200112L
+ #define _XOPEN_SOURCE   600
+ #else
diff --git a/ghc7/patches/patch-rts_ghc.mk b/ghc7/patches/patch-rts_ghc.mk
new file mode 100644
index 0000000000..50f5eee7f4
--- /dev/null
+++ b/ghc7/patches/patch-rts_ghc.mk
@@ -0,0 +1,14 @@
+$NetBSD: patch-rts_ghc.mk,v 1.8 2021/04/30 18:52:05 pho Exp $
+
+This is for Darwin. See the patch to rules/distdir-way-opts.mk.
+
+--- rts/ghc.mk.orig	2015-07-23 22:06:18.000000000 +0000
++++ rts/ghc.mk
+@@ -189,6 +189,7 @@ ifeq "$$(HostOS_CPP)" "mingw32" 
+ $$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) rts/dist/libs.depend rts/dist/build/$$(LIBFFI_DLL)
+ 	"$$(RM)" $$(RM_OPTS) $$@
+ 	"$$(rts_dist_HC)" -this-package-key rts -shared -dynamic -dynload deploy \
++	  -dylib-install-name $$(ghclibdir)/rts/$$(rts_$1_LIB_NAME) \
+ 	  -no-auto-link-packages -Lrts/dist/build -l$$(LIBFFI_NAME) \
+          `cat rts/dist/libs.depend` $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) \
+          $$(rts_dist_$1_GHC_LD_OPTS) \
diff --git a/ghc7/patches/patch-rules_build-package-way.mk b/ghc7/patches/patch-rules_build-package-way.mk
new file mode 100644
index 0000000000..1224ed7b18
--- /dev/null
+++ b/ghc7/patches/patch-rules_build-package-way.mk
@@ -0,0 +1,14 @@
+$NetBSD: patch-rules_build-package-way.mk,v 1.1 2021/04/30 18:52:05 pho Exp $
+
+This is for Darwin. See the patch to rules/distdir-way-opts.mk.
+
+--- rules/build-package-way.mk.orig	2015-07-23 22:06:18.000000000 +0000
++++ rules/build-package-way.mk
+@@ -90,6 +90,7 @@ else
+ $$($1_$2_$3_LIB) : $$($1_$2_$3_ALL_OBJS) $$(ALL_RTS_LIBS) $$($1_$2_$3_DEPS_LIBS)
+ 	$$(call cmd,$1_$2_HC) $$($1_$2_$3_ALL_HC_OPTS) $$($1_$2_$3_GHC_LD_OPTS) $$($1_$2_$3_ALL_OBJS) \
+          -shared -dynamic -dynload deploy \
++	 -dylib-install-name $$(ghclibdir)/$$($1_$2_PACKAGE_KEY)/$$($1_$2_$3_LIB_NAME) \
+ 	 $$(addprefix -l,$$($1_$2_EXTRA_LIBRARIES)) $$(addprefix -L,$$($1_$2_EXTRA_LIBDIRS)) \
+          -no-auto-link-packages \
+          -o $$@
diff --git a/ghc7/patches/patch-rules_distdir-way-opts.mk b/ghc7/patches/patch-rules_distdir-way-opts.mk
new file mode 100644
index 0000000000..5bb74994b4
--- /dev/null
+++ b/ghc7/patches/patch-rules_distdir-way-opts.mk
@@ -0,0 +1,27 @@
+$NetBSD: patch-rules_distdir-way-opts.mk,v 1.1 2021/04/30 18:52:05 pho Exp $
+
+Use correct RPATHs. On ELF we replace "$ORIGIN/../{PACKAGE_ID}" with
+the final installation path.
+
+On Darwin library paths work differently. If an executable (or a
+library) A depends on a library B, the installation path of B is first
+embedded in B, and then the path propagates to A at the time when A is
+linked. So we remove -rpath to libraries here, and do the other half
+in rules/build-package-way.mk and rts/ghc.mk.
+
+--- rules/distdir-way-opts.mk.orig	2015-07-23 22:06:18.000000000 +0000
++++ rules/distdir-way-opts.mk
+@@ -186,11 +186,10 @@ ifneq "$4" "0"
+ ifeq "$$(TargetElf)" "YES"
+ $1_$2_$3_GHC_LD_OPTS += \
+     -fno-use-rpaths \
+-    $$(foreach d,$$($1_$2_TRANSITIVE_DEP_KEYS),-optl-Wl$$(comma)-rpath -optl-Wl$$(comma)'$$$$ORIGIN/../$$d') -optl-Wl,-zorigin
++    $$(foreach d,$$($1_$2_TRANSITIVE_DEP_KEYS),-optl-Wl$$(comma)-rpath -optl-Wl$$(comma)$$(ghclibdir)/$$d)
+ else ifeq "$$(TargetOS_CPP)" "darwin"
+ $1_$2_$3_GHC_LD_OPTS += \
+-    -fno-use-rpaths \
+-    $$(foreach d,$$($1_$2_TRANSITIVE_DEP_KEYS),-optl-Wl$$(comma)-rpath -optl-Wl$$(comma)'@loader_path/../$$d')
++    -fno-use-rpaths
+ endif
+ endif
+ endif


Home | Main Index | Thread Index | Old Index