| | 1 | |
| | 2 | |
| | 3 | = Idiom: non-recursive make = |
| | 4 | |
| | 5 | Build systems for large projects often use the technique commonly |
| | 6 | known as "recursive make", where there is a separate `Makefile` in |
| | 7 | each directory that is capable of building that part of the system. |
| | 8 | The `Makefile`s may share some common infrastructure and configuration |
| | 9 | by using GNU '''make''''s `include` directive; this is exactly what the |
| | 10 | previous GHC build system did. However, this design has a number of |
| | 11 | flaws, as described in Peter Miller's |
| | 12 | [http://miller.emu.id.au/pmiller/books/rmch/ Recursive Make Considered Harmful]. |
| | 13 | |
| | 14 | The GHC build system adopts the non-recursive '''make''' idiom. That is, we |
| | 15 | never invoke '''make''' from inside a `Makefile`, and the whole build system |
| | 16 | is effectively a single giant `Makefile`. |
| | 17 | |
| | 18 | This gives us the following advantages: |
| | 19 | |
| | 20 | * Specifying dependencies between different parts of the tree is |
| | 21 | easy. In this way, we can accurately specify many dependencies |
| | 22 | that we could not in the old recursive-make system. This makes it much more likely that when you say "make" |
| | 23 | after modifying parts of the tree or pulling new patches, |
| | 24 | the build system will bring everything up-to-date in the correct order, and leave you with a working |
| | 25 | system. |
| | 26 | |
| | 27 | * More parallelism: dependencies are more fine-grained, and there |
| | 28 | is no need to build separate parts of the system in sequence, so |
| | 29 | the overall effect is that we have more parallelism in the build. |
| | 30 | |
| | 31 | Doesn't this sacrifice modularity? No - we can still split the build |
| | 32 | system into separate files, using GNU '''make''''s `include`. |
| | 33 | |
| | 34 | Specific notes related to this idiom: |
| | 35 | |
| | 36 | * Individual directories usually have a `ghc.mk` file which |
| | 37 | contains the build instructions for that directory. |
| | 38 | |
| | 39 | * Other parts of the build system are in `mk/*.mk` and `rules/*.mk`. |
| | 40 | |
| | 41 | * The top-level `ghc.mk` file includes all the other `*.mk` files in |
| | 42 | the tree. The top-level `Makefile` invokes '''make''' on `ghc.mk` |
| | 43 | (this is the only recursive invocation of '''make'''; see the "phase |
| | 44 | ordering" idiom below). |