[Haskell-cafe] Compiling with NHC98

Glynn Clements glynn at gclements.plus.com
Sun May 8 07:00:20 EDT 2005


Daniel Carrera wrote:

> > I haven't used NHC so I can't guarantee this will work, but try doing
> > something like this:
> > 
> >     $ nhc98 -c RC4.hs
> >     $ nhc98 -c prng.hs
> >     $ nhc98 RC4.o prng.o -o prng
> 
> Yay! It does. And I just put it in a makefile:
> 
> ---<daniel's makefile>----
> COMPILER=nhc98
> 
> RC4.o:
>          $(COMPILER) -c RC4.hs
> 
> prng.o:
>          $(COMPILER) -c prng.hs
> 
> prng: RC4.o  prng.o
>          $(COMPILER) RC4.o prng.o -o prng
> ---<daniel's makefile>----

This can fail with a parallel make, which may try to compile RC4.hs
and prng.hs concurrently. It can also fail if you rebuild after
modifying any of the files, as it won't realise that it needs to
re-compile. To handle that, you need to be more precise about the
dependencies, i.e.:

	RC4.o RC4.hi: RC4.hs
		$(HC) -c RC4.hs
	
	prng.o prng.hi: prng.hs RC4.hi
		$(HC) -c prng.hs

	prng: RC4.o  prng.o
		$(HC) RC4.o prng.o -o prng

With most make programs (e.g. GNU make), you can use pattern rules to
avoid repeating the commands, e.g.:

	# how to compile any .hs file to produce .o and .hi files
	%.o %.hi: %.hs
		$(HC) -c $<

	# how to build the prng program
	prng: RC4.o prng.o
		$(HC) -o $@ $+

	# note that prng.o depends upon RC4.hi
	prng.o: RC4.hi

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the Haskell-Cafe mailing list