$OpenBSD: patch-distrib_hc-build,v 1.5 2005/02/19 03:42:11 dons Exp $
SplitObjs just slows things down, and can overrun ulimits. It does
produce smaller binaries though...

Help ghc find libgmp.a

And GHC produces stack_smash_handler() core dumps on sparc 
unless propolice is turned off. This used to happen on x86, but
has been fixed. Someone want to fix this on sparc?

For some odd reason the existing regex doesn't want to remove all *.o
and *.a files from the libraries. Can't work out why.

Touch some things so that 'make fake' doesn't rebuild the compiler

Make stage=2 after everything else, so as to get a working ghci. Unknown
why ghci doesn't work just via .hc files.

--- distrib/hc-build.orig	Wed Sep  3 05:15:19 2003
+++ distrib/hc-build	Thu Feb 17 19:30:42 2005
@@ -29,20 +29,31 @@ fi
 case "$configopts" in
 *--enable-hc-boot-unregisterised*)
 cat >mk/build.mk <<END
-GhcWithInterpreter=NO
 GhcWithNativeCodeGen=NO
 SplitObjs=NO
-GhcLibWays=
+SRC_HC_OPTS+=-L\$(LOCALBASE)/lib
+SRC_CC_OPTS+=-L\$(LOCALBASE)/lib
+GhcUnregisterised=YES
 END
 ;;
 
 *)
 cat >mk/build.mk <<END
 # empty
+SplitObjs=NO
+SRC_HC_OPTS+=-L\$(LOCALBASE)/lib
+SRC_CC_OPTS+=-L\$(LOCALBASE)/lib
 END
 ;;
 esac
 
+if [ `uname -m` == "sparc" ] ; then
+	echo "SRC_HC_OPTS+=-optc-fno-stack-protector" >> mk/build.mk
+	echo "SRC_CC_OPTS+=-fno-stack-protector" >> mk/build.mk
+fi
+
+export CPPFLAGS="-I${LOCALBASE}/include" LDFLAGS="-L${LOCALBASE}/lib"
+
 echo "*** Building compiler..."
 ./configure --enable-hc-boot $configopts
 
@@ -77,7 +88,7 @@ PRIMOP_BITS="primop-data-decl.hs-incl \
 # Remove the old libraries.  Don't use make clean, because we don't
 # want to delete the .hs files generated from the .hsc files, because
 # we don't have hsc2hs built yet.
-find libraries hslibs | grep '\.\(o\|a\)$' | xargs rm -f
+find libraries hslibs | grep '\.[oa]$' | xargs rm -f
 
 # Do includes and RTS now
 $MAKE -C ghc/includes boot && $MAKE -C ghc/includes all
@@ -95,6 +106,10 @@ $MAKE -C hslibs  boot all
 # The reconfigure step updates a few files, which can lead to
 # unnecessary recompilations.  Touch a bunch of things here to avoid
 # having to recompile stuff that we've already built.
-(cd ghc/compiler; touch $PRIMOP_BITS parser/hschooks.o prelude/PrimOp.o main/Config.hs main/Config.o ghc-*)
+#(cd ghc/compiler/; touch $PRIMOP_BITS main/Config.hs stage1/parser/hschooks.o stage1/prelude/PrimOp.o stage1/main/Config.o stage1/ghc-* ghc-inplace)
 
 # At this point, the tree should be safe to do 'make install' in.
+
+# now, ghci doesn't work when build via .hc, so make stage=2, and build
+# it via .hs
+(cd ghc/compiler; touch prelude/primops.txt ; gmake boot stage=2 && gmake stage=2)
