Using --make with -odir and hierarchical modules

Martin Norbäck d95mback@dtek.chalmers.se
15 Jan 2003 17:41:55 +0100


The GHC manual needs to specify what happens when you use -odir and
hierarchical modules with --make.

I posted to the list about this before but it was not resolved:
http://www.haskell.org/pipermail/glasgow-haskell-users/2002-October/004178.html

Here is an example:

.
|-- Library
|   |-- Bar
|   |   `-- Module.hs
|   `-- Foo
|       `-- Module.hs
`-- Program
    |-- Program.hs
    `-- output

Program.hs uses Bar.Module and Foo.Module.

Then, doing cd to Program
# ghc -i../Library --make Program
ghc-5.04.2: chasing modules from: Program
Compiling Bar.Module       ( ../Library/Bar/Module.hs, ../Library/Bar/Module.o )
Compiling Foo.Module       ( ../Library/Foo/Module.hs, ../Library/Foo/Module.o )
Compiling Main             ( Program.hs, ./Program.o )
ghc: linking ...

everything works fine.

Using -odir:

# ghc -i../Library -odir output --make Program
ghc-5.04.2: chasing modules from: Program
Compiling Bar.Module       ( ../Library/Bar/Module.hs, output/Module.o )
Compiling Foo.Module       ( ../Library/Foo/Module.hs, output/Module.o )
Compiling Main             ( Program.hs, output/Program.o )
ghc: linking ...
<LONG LINKER ERROR>

Error, since both modules are compiled to the same file. This should not
happen.

What should be done about it?

Solution 1: -odir is relative to the source directory (files will end up
in Library/Bar/output/Module.o and Library/Foo/output/Module.o).
This is a change of semantics from the earlier behaviour of -odir (files
are put in another place). On the other hand, it may be more natural to
put files relative to their source, like --make without -odir does. The
question remains what to do if -odir is an absolute path.

Solution 2: files put in -odir are put in directories (files will end up
in Program/output/Bar/Module.o and Program/output/Foo/Module.o)
This is also a slight change in semantics, since files are put in
directories. May affect Makefiles that does "ar output/*.o" or similar.

Solution 3: files put in -odir will have their full module name (files
will end up in Program/Output/Bar.Module.o and
Program/Output/Foo.Module.o)
This is an ever lesser change in semantics, and is better than solution
2 in my opinion.

I would recommend using solution 1 if the path name is relative and
solution 3 if it's absolute.

Regards,

	Martin

-- 
Martin Norbäck          d95mback@dtek.chalmers.se              
Kapplandsgatan 40       +46 (0)708 26 33 60                    
S-414 78  GÖTEBORG      http://www.dtek.chalmers.se/~d95mback/
SWEDEN                  OpenPGP ID: 3FA8580B