-BOOTSTRAP_MAIN_C= ${PKGDIR}/files/bootstrap-main.c
-
-pre-configure: ${WRKDIR}/stamp-bootstrap-ghc
-
-${WRKDIR}/stamp-autoreconf:
- ${RUN} cd ${WRKSRC} && \
- ${PHASE_MSG} "Regenerating configuration scripts for ${PKGNAME}" && \
- ${PERL5} boot && \
- ${TOUCH} ${.TARGET}
-
-${WRKDIR}/stamp-prepare-bootstrap: ${WRKDIR}/stamp-autoreconf
- ${RUN} cd ${WRKDIR} && \
- ${PHASE_MSG} "Preparing bootstrapping compiler for ${PKGNAME}" && \
- ${RM} -rf bootstrap && \
- ${MKDIR} bootstrap && \
- ${GTAR} -cf - ${DISTNAME} | ${GTAR} -C bootstrap -xf - && \
- ${CP} -f ${BOOTSTRAP_MAIN_C} bootstrap/${DISTNAME}/rts/bootstrap-main.c && \
- ${CP} -f ${BOOTSTRAP_CAPI_C} bootstrap/${DISTNAME}/rts/capi-wrappers.c && \
- ${TOUCH} ${.TARGET}
-
-${WRKDIR}/stamp-configure-hc-boot: ${WRKDIR}/stamp-prepare-bootstrap
- ${RUN} cd ${WRKDIR}/bootstrap/${DISTNAME} && \
- ${PHASE_MSG} "Configuring bootstrapping compiler for ${PKGNAME}" && \
- ${SETENV} ${CONFIGURE_ENV} ./configure --enable-hc-boot --with-ghc="" ${CONFIGURE_ARGS} && \
- ${TOUCH} ${.TARGET}
-
-${WRKDIR}/stamp-extract-hc: ${WRKDIR}/stamp-configure-hc-boot
- ${RUN} cd ${WRKDIR}/bootstrap && \
- ${PHASE_MSG} "Extracting bootstrap HC archive for ${PKGNAME}" && \
- if ${TEST} "`${DATE} '+%Y%m%d%H%M'`" -le 200001010000; then \
- ${FAIL_MSG} "Adjust your system clock: `${DATE}`"; \
- fi && \
- ${FIND} ${DISTNAME} -type d -o -type f | ${XARGS} ${TOUCH} -t 200001010000 && \
- ${GTAR} -jxf ${DISTDIR}/${BOOTSTRAP_TARBALL} && \
- (cd ${DISTNAME} && ${SH} mkfiles) && \
- ${TOUCH} ${.TARGET}
-
-${WRKDIR}/bootstrap/${DISTNAME}/mk/build.mk: ${WRKDIR}/stamp-extract-hc
- ${RUN} ${PHASE_MSG} "Creating bootstrapping configuration file for ${PKGNAME}"
- ${RUN} ${CP} -f ${PKGDIR}/files/build.bootstrap.common.mk ${.TARGET}
- ${RUN} ${ECHO} "SRC_CC_OPTS += -I${PREFIX}/include" >> ${.TARGET}
-.if ${OPSYS} == "Darwin"
- ${RUN} ${ECHO} "ghc_stage2_v_EXTRA_CC_OPTS += -L${PREFIX}/lib -lm -liconv" >> ${.TARGET}
- ${RUN} ${ECHO} "utils/ghc-pkg_dist-install_v_EXTRA_CC_OPTS += -L${PREFIX}/lib -lm -liconv -lncurses" >> ${.TARGET}
- ${RUN} ${ECHO} "EXTRA_CC_OPTS += -O2" >> ${.TARGET}
-.elif ${OPSYS} == "FreeBSD" || ${OPSYS} == "NetBSD"
- ${RUN} ${ECHO} "ghc_stage2_v_EXTRA_CC_OPTS += -L${PREFIX}/lib -lm -liconv -lutil -lrt" >> ${.TARGET}
- ${RUN} ${ECHO} "utils/ghc-pkg_dist-install_v_EXTRA_CC_OPTS += -L${PREFIX}/lib -lm -liconv -lutil -lrt -lncurses" >> ${.TARGET}
-# Unregisterised stage0 compiler gets too large (.text section being
-# over 64 MiB) without -Os, exceeding NetBSD/i386's kernel default
-# limitation.
-# Note that stage1 currently doesn't bloat that much (about 42.6
-# MiB), but when it does we have to append CONF_CC_OPTS_STAGE0="-Os"
-# to CONFIGURE_ARGS as well. I guess that's a matter of time :(
- ${RUN} ${ECHO} "EXTRA_CC_OPTS += -Os" >> ${.TARGET}
-.elif ${OPSYS} == "Linux"
- ${RUN} ${ECHO} "ghc_stage2_v_EXTRA_CC_OPTS += -L${PREFIX}/lib -lm -liconv -lrt -ldl" >> ${.TARGET}
- ${RUN} ${ECHO} "utils/ghc-pkg_dist-install_v_EXTRA_CC_OPTS += -L${PREFIX}/lib -lm -liconv -lrt -ldl -lncurses" >> ${.TARGET}
- ${RUN} ${ECHO} "EXTRA_CC_OPTS += -O2" >> ${.TARGET}
+BOOT_TARBALL= ${BOOT_ARCHIVE:C/\.xz$//}
+
+
+# -----------------------------------------------------------------------------
+# The "pre-configure" hook
+#
+# Install a bootstrapping compiler directly into TOOLS_DIR so that
+# ./configure can find it.
+#
+USE_TOOLS+= gmake xzcat
+
+pre-configure:
+ @${PHASE_MSG} "Extracting bootstrapping compiler for ${PKGNAME}"
+ ${RUN} ${MKDIR} ${WRKDIR:Q}/build-extract
+ ${RUN} cd ${WRKDIR:Q}/build-extract && \
+ ${EXTRACT_CMD_DEFAULT} ${DISTDIR:Q}/${DIST_SUBDIR:Q}/${BOOT_ARCHIVE}
+
+ @${PHASE_MSG} "Preparing bootstrapping compiler for ${PKGNAME}"
+ ${RUN} cd ${WRKDIR:Q}/build-extract/${DISTNAME}-boot && \
+ ${SH} ./configure \
+ --prefix=${TOOLS_DIR:Q} \
+ --with-gcc=${CCPATH:Q} && \
+ ${MAKE_PROGRAM} install
+
+
+# -----------------------------------------------------------------------------
+# An unusual target "bootstrap"
+#
+# Build a bootstrapping compiler using an already installed GHC. This
+# can 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.
+#
+.PHONY: bootstrap
+
+.if exists(${WRKDIR}/${DISTNAME}/mk/config.mk)
+bootstrap:
+ @${ERROR_MSG} "You have already configured the package in a way\
+ that building bootstrapping compiler is impossible."
+ @${FAIL_MSG} "Please run \"${MAKE} clean patch\" first."
+
+.elif !exists(${WRKDIR}/${DISTNAME}/rts/ghc.mk.orig)
+bootstrap:
+ @${FAIL_MSG} "Please run \"${MAKE} patch\" first."
+