using ghc with make

Simon Marlow simonmarhaskell at
Tue Apr 18 06:37:12 EDT 2006

Frederik Eaton wrote:

> I have a project which currently uses Cabal, and I would like to
> switch to using a plain Makefile. 
> I have two examples of projects that use Makefiles, darcs and jhc, but
> they both appear to hand-code the list of dependencies for
> executables. The "-M" option to ghc should let us do this
> automatically, but either because of a deficiency in GHC or in GNU
> Make, that looks to be impossible or difficult. Does anyone have
> experience with this?

Yes, GHC's build system works like this.  We don't use --make at all 
when building GHC itself.  However, I want to switch to using Cabal to 
build the libraries.  Eventually I envisage using Cabal to build more 
parts of the GHC tree.

There's certainly no reason that you can't use ghc -M with GNU make, and 
that's something we will continue to support.  What problems are you having?

> Since I'm not using the multi-compiler features of Cabal, I think it
> shouldn't be too hard to get the project-specific part of my Makefile
> down to the size of the .cabal file.

Sure, but you also have a quite a lot of build system infrastructure to 
get right.  Incedentally, this is exactly what Cabal was meant to avoid.

> - I want to be able to rebuild specific targets, rather than building
> everything every time

Multiple Cabal packages tied together with a simple Makefile could do 
this, no?

> - I want better dependency inference, for instance I don't want to
> relink every executable every time I do a build (I think this is fixed
> in newer versions of ghc, but not the one I use)

Yes, fixed in 6.4.2

The comments about --make are interesting: ceratinly we're aware that it 
has a scalability problem, and it certainly isn't conducive to a 
frequent edit/compile/test cycle, which is one reason we don't use it in 
GHC.  However, for a straight single-CPU build, from scratch, for a 
large program, and if you have a lot of memory, it is much faster than 
make.  I don't have figures for GHC to hand, but I believe it is on the 
order of a factor of 2 or 3.  I would expect 'make -j4' to definitely 
win on a 4-core box.  We do have experimental patches for GHC to make 
--make work across multiple CPUs too, but you don't get linear speedup 
(single-threaded GC is one bottleneck).

I think it would be prudent at some point to make Cabal build without 
--make and to add multiprocessor support.

FWIW, I don't think 'ghc -c Foo.hs Bar.hs' goes any faster than 
separately compiling the two files, it doesn't cache anything between 
the two.


More information about the Glasgow-haskell-users mailing list