-make

Simon Marlow simonmar@microsoft.com
Wed, 25 Apr 2001 11:28:17 +0100


> I have two questions on  ghc-5.00  -make.
>=20
> The User's Guide says in Section 4.5 that it is simpler to use=20
> -make  than the Makefile technique.=20
>=20
> 1. I try       ghc -make Main.hs
>           =20
> with  Main.hs  containing   main =3D putStr "hello\n"
>=20
> (in ghc-5.00, binary, i386-unknown, Linux), =20
> and it reports
>                ghc-5.00: unrecognised flag: -make
> - ? =20

The flag is actually '--make' (note the double dash).  Apparently the
documentation system has some problems rendering the double dash in
printed mode.

> 2. How to simplify (eliminate?) Makefile.
> -----------------------------------------
>=20
> My project has many .hs files  in the directories =20
>    ./source/
>    ./source/auxil/
>    ./source/pol/factor/
>    ...
> `make ...' compiles them putting  .hi, .o  files into  ./export/,
> then, applies `ar' to make  .a  library.
> To do all this, Makefile includes the rules like=20
>=20
>   .hs.o:
>          $(HC) -c $< $(HCFlags)
> =20
> and applies the compiler $(HC) with the flags
>=20
>       ...  -syslib data  -recomp ...
>       -i$(E) -odir $(E)  -ohi $(E)/$(notdir $*).hi  $($*_flags)
>       ...
> Now, this Makefile does not work under  ghc-5.00,  because second
>   compilation cannot find  .hi  file of the first compilation:
>=20
>   ..ghc -c source/auxil/Prelude_.hs -fglasgow-exts ...
>    -recomp -iexport -odir export  -ohi        export/Prelude_.hi =20
>    +RTS -G3 -F1.5 -M29m -RTS -Onot
>   ...
>   ..ghc -c source/parse/Iparse_.hs -fglasgow-exts ...
>    -recomp -iexport -odir export  -ohi        export/Iparse_.hi=20
>    +RTS -G3 -F1.5 -M29m -RTS -Onot
>=20
>   source/parse/Iparse_.hs:20:
>     failed to load interface for `Prelude_':
>         Bad interface file: export/Iparse_.hi
>             does not exist

This is indeed a bug: -ohi doesn't work properly in 5.00.  I'm fixing it
right now.

> Also what  -make  can do to replace some large part of Makefile.
> For=20
> (a) Makefile has rather odd language, it is not good to force the
>     functional programmer to look into it,
> (b) one has to think of Makefile versions for different operation=20
>     systems.

The simplest way to work is to put the objects and .hi files in the same
directory as the source.  Then you can use --make like this:

	$ ghc --make -i<dir1>:<dir2>:... Main

to put the objects in a single directory, you can use -odir <dir>.
Unfortunately the .hi files can't be saved elsewhere when using --make.

Cheers,
	Simon