What’s needed to bootstrap GHC with hugs?

Having a go at building compiler98 I first run into a missing hmakerc error:

derptop:/usr/src/nhc98-1.22/src/compiler98# NHC98COMP=${NHCDIR}/hugs-nhc make HC=${NHCDIR}/script/nhc98
mkdir -p /usr/src/nhc98-1.22/targets/x86_64-Linux/obj/compiler98
mkdir -p /usr/src/nhc98-1.22/targets/x86_64-Linux/obj/compiler98/Derive
mkdir -p /usr/src/nhc98-1.22/targets/x86_64-Linux/obj/compiler98/Parse
mkdir -p /usr/src/nhc98-1.22/targets/x86_64-Linux/obj/compiler98/Type
mkdir -p /usr/src/nhc98-1.22/targets/x86_64-Linux/obj/compiler98/Util
rm -f /usr/src/nhc98-1.22/targets/x86_64-Linux/obj/compiler98/nhc98 /usr/src/nhc98-1.22/targets/x86_64-Linux/obj/compiler98/hbc /usr/src/nhc98-1.22/targets/x86_64-Linux/obj/compiler98/ghc*
#make cleanC
touch "/usr/src/nhc98-1.22/targets/x86_64-Linux/obj/compiler98/gcc"
/usr/src/nhc98-1.22/script/hmake -hc=/usr/src/nhc98-1.22/script/nhc98 -H16M -K2M +CTS -H16M -CTS -package containers -package filepath -package packedstring -package base  -d /usr/src/nhc98-1.22/targets/x86_64-Linux/obj/compiler98 MainNhc98
Config file /usr/src/nhc98-1.22/lib/x86_64-Linux/hmakerc does not exist.
  Try running 'hmake-config new' first.
Stop - hmake dependency error.

So here’s one that I cobbled together after repeatedly trying MkConfig. I’ve no idea how much of it is required, but it silences the error, and seems to work in the next step:

derptop:/usr/src/nhc98-1.22/src/compiler98# cat ../../lib/x86_64-Linux/hmakerc
HmakeConfig
  { defaultCompiler = "/usr/src/nhc98-1.22/script/nhc98"
  , knownCompilers =
    [ CompilerConfig
      { compilerStyle = nhc98
      , compilerPath = "/usr/src/nhc98-1.22/script/nhc98"
      , compilerVersion = "/usr/src/nhc98-1.22/lib/x86_64/config:"
      , includePaths = ["/usr/src/nhc98-1.22/include"]
      , cppSymbols = ["__NHC__=981"]
      , extraCompilerFlags = []
      , isHaskell98 = True
      }
    , DynCompiler { compilerPath = "lib/x86_64-Linux/cpphs" }
    , DynCompiler { compilerPath = "lib/x86_64-Linux/runhs" }
    ]
  }

Try a build again, and we’re now missing some includes.

derptop:/usr/src/nhc98-1.22/src/compiler98# NHC98COMP=${NHCDIR}/hugs-nhc make HC=${NHCDIR}/script/nhc98

/usr/src/nhc98-1.22/script/hmake -hc=/usr/src/nhc98-1.22/script/nhc98 -H16M -K2M +CTS -H16M -CTS -package containers -package filepath -package packedstring -package base  -d /usr/src/nhc98-1.22/targets/x86_64-Linux/obj/compiler98 MainNhc98

Warning: package(s) base, packedstring, filepath, containers not available in /usr/src/nhc98-1.22/include
Can't find module Foreign in user directories
	.
  Or in installed libraries/packages at
	/usr/src/nhc98-1.22/include
  Asked for by: Error.hs
  Fix using the -I, -P, or -package flags.

Stop - hmake dependency error.

Edit the hmakerc includes path. Repeat until the errors about missing Data.PackedString and Data.Set, go away:

HmakeConfig
  { defaultCompiler = "/usr/src/nhc98-1.22/script/nhc98"
  , knownCompilers =
    [ CompilerConfig
      { compilerStyle = nhc98
      , compilerPath = "/usr/src/nhc98-1.22/script/nhc98"
      , compilerVersion = "/usr/src/nhc98-1.22/lib/x86_64/config:"
      , includePaths = ["/usr/src/nhc98-1.22/include", "/usr/src/nhc98-1.22/include/packages/base", "/usr/src/nhc98-1.22/include/packages/packedstring", "/usr/src/nhc98-1.22/include/packages/containers"]
      , cppSymbols = ["__NHC__=981"]
      , extraCompilerFlags = []
      , isHaskell98 = True
      }
    , DynCompiler { compilerPath = "lib/x86_64-Linux/cpphs" }
    , DynCompiler { compilerPath = "lib/x86_64-Linux/runhs" }
    ]
  }

Build again, and now we’re getting somewhere:

derptop:/usr/src/nhc98-1.22/src/compiler98# NHC98COMP=${NHCDIR}/hugs-nhc make HC=${NHCDIR}/script/nhc98
/usr/src/nhc98-1.22/script/hmake -hc=/usr/src/nhc98-1.22/script/nhc98 -H16M -K2M +CTS -H16M -CTS -package containers -package filepath -package packedstring -package base  -d /usr/src/nhc98-1.22/targets/x86_64-Linux/obj/compiler98 MainNhc98
The program ran out of heap memory.  (Current heapsize is 400000 bytes.)
You can set a bigger size with e.g. +RTS -H4M -RTS (4M = four megabytes).
GC stats:
    Only 32 words after gc, need 32 words.
  Used  2031223 words of heap.  Moved 33296188 words of heap in 303 gcs.
  32 words to next gc.  Max live after gc: 116297 words.
Insufficient heap memory.
Stop - hmake dependency error.
make: *** [/usr/src/nhc98-1.22/lib/x86_64-Linux/nhc98comp] Error 255

We’ve seen this before with the CTypes source file being too large.