Hierarchical modules and compilation output redirection

Simon Marlow simonmar@microsoft.com
Tue, 15 Oct 2002 16:18:38 +0100

> I am using hierarchical modules with ghc, and I have a bunch of common
> modules used by several projects, which should build on serveral
> platforms.
> Now, assume I have the following:
> .
> |-- Bar
> |   `-- Module.hs
> |-- Foo
> |   `-- Module.hs
> `-- Main.hs
> Main imports both Bar.Module and Foo.module.
> Currently I am using -osuf ARCHITECTURE.o with ghc --make,=20
> which works,
> but clutters the common modules directory with .o files. (I=20
> may want to
> keep it clean.)
> So I want to redirect the output with -odir OUTPUT_DIR
> However it won't work since ghc wll put the compilation output of both
> modules in OUTPUT_DIR/Module.o and subsequently fail to link.

Perhaps -odir should append the full module name as a directory (i.e. =
the default behaviour would be a special case where -odir is ".").

> Is there a way to get the files named Bar.Module.o and Foo.Module.o or
> such? Is there a better way?
> Another thing that would be good would be a way to redirect=20
> output to a
> directory relative to where the source file is, say for instance that
> the output of Bar/Module.hs should be put in Bar/ARCHITECTURE/Module.o
> and the output of Foo/Module.hs should be put in
> Foo/ARCHITECTURE/Module.o.

It sounds like what you want is a way to specify a general mapping =
function from module names to object file names, perhaps in Haskell.  =
Something like

  $ ghc -omap "\m -> $ARCHITECTURE ++ \
                     map (\x -> if x =3D=3D '.' then '/' else x) m ++ \

I'm only kidding, but we could implement this if we wanted :-)

How about having a make rule which just moves the object file to the =
required place after compilation?