!
Each of the following subsections describes one of the idioms that we use in the build system. There are a handful of such idioms, and when you've understood them all you'll be able to understand most of the code you'll find in the build system. We'll describe the idioms first, and then get on to the specifics of how we build GHC.
Historical note: this is the third major revision of the GHC build system. The first incarnation was based on "jmake", a derivative of X11's "imake", which is based on using the C preprocessor to add macro capabilities and #include to plain make. The second incarnation used GNU make's extensions for including makefiles (but lost the ability to use macros, since at the time GNU make didn't have support for general macros). In this third revision, we use even more of GNU make's extensions, and we make a fundamental change to the design, as described in the next section. file which typically contains the build instructions for that directory.
- The top-level of the build system is in Makefile and ghc.mk.
- Other parts of the build system are in mk/*.mk:.
Idiom: variable names
Now that our build system is one giant Makefile, all our variables share the same namespace. Where previously we might have had a variable that contained a list of the Haskell source files called HS_SRCS, now we have one of these for each directory_build_;.
Idiom: inc1.mk : Makefile echo "X = C" >$@ ifneq "$(PHASE)" "0").
- Phase 1: the second time we invoke make, we can be sure that inc1.mk is up-to-date and proceed to generate inc2.mk. If this changes inc2.mk, then make automatically re-invokes itself, repeating Phase 1.
We could have abandoned make's automatic re-invocation mechanism altogether, and used three phases, but in practice it's very convenient to use the automatic re-invocation in the final phase. However no automatic re-invocation should happen in any phase except the final one...