Go to the first, previous, next, last section, table of contents.

Re-directing the compilation output(s)

When compiling a Haskell module, GHC may produce several files of output (usually two).

One file is usually an interface file. The name of the interface file follows the Haskell module name, i.e., if compiling `bar/Foo.hs', and it implements `module Bar ...', the interface file would normally be `bar/Bar.hi'.

The interface output may be directed to another file `bar2/Wurble.iface' with the option `-ohi bar2/Wurble.iface' (not recommended).

NOTE: Having the name of the interface file follow the module name and not the file name, means that working with tools such as `make(1)' become harder. `make' implicitly assumes that any output files produced by processing a translation unit will have file names that can be derived from the file name of the translation unit. For instance, pattern rules becomes unusable.

To avoid generating an interface file at all, use a `-nohi' option.

The compiler does not overwrite an existing `.hi' interface file if the new one is byte-for-byte the same as the old one; this is friendly to `make'. When an interface does change, it is often enlightening to be informed. The `-hi-diffs' option will make `ghc' run `diff' on the old and new `.hi' files. You can also record the difference in the interface file itself, the `-keep-hi-diffs' option takes care of that.

The `.hi' files from GHC 2.xx contain "usage" information which changes often and uninterestingly. If you really want to see these changes reported, you need to use the `-hi-diffs-with-usages' option.

GHC's non-interface output normally goes into a `.hc', `.o', etc., file, depending on the last-run compilation phase. The option `-o foo' re-directs the output of that last-run phase to file `foo'.

Note: this "feature" can be counterintuitive: `ghc -C -o foo.o foo.hs' will put the intermediate C code in the file `foo.o', name notwithstanding!

EXOTICA: But the `-o' option isn't of much use if you have several input files... Non-interface output files are normally put in the same directory as their corresponding input file came from. You may specify that they be put in another directory using the `-odir <dir>' (the "Oh, dear" option). For example:

% ghc -c parse/Foo.hs parse/Bar.hs gurgle/Bumble.hs -odir `arch`

The output files, `Foo.o', `Bar.o', and `Bumble.o' would be put into a subdirectory named after the architecture of the executing machine (`sun4', `mips', etc). The directory must already exist; it won't be created.

Note that the `-odir' option does not affect where the interface files are put. In the above example, they would still be put in `parse/Foo.hi', `parse/Bar.hi', and `gurgle/Bumble.hi'.

MORE EXOTICA: The `-osuf <suffix>' will change the `.o' file suffix for object files to whatever you specify. (We use this in compiling the prelude.)

Similarly, the `-hisuf <suffix>' will change the `.hi' file suffix for non-system interface files. This can be useful when you are trying to compile a program several ways, all in the same directory. The suffix given is used for all interfaces files written, and for all non-system interface files that your read.

The `-hisuf'/`-osuf' game is useful if you want to compile a program with both GHC and HBC (say) in the same directory. Let HBC use the standard `.hi'/`.o' suffixes; add `-hisuf g_hi -osuf g_o' to your `make' rule for GHC compiling...

NB: A change from 0.26 and before: Before, you might have said `-hisuf _g.hi -osuf _g.o'; now, the `.' is assumed and you specify what comes after it. (This is a more portable solution for the long term.)

FURTHER EXOTICA: If you are doing a normal `.hs'-to-`.o' compilation but would like to hang onto the intermediate `.hc' C file, just throw in a `-keep-hc-file-too' option. If you would like to look at the assembler output, toss in a `-keep-s-file-too', too.

SAVING GHC STDERR OUTPUT: Sometimes, you may cause GHC to be rather chatty on standard error; with `-fshow-import-specs', for example. You can instruct GHC to append this output to a particular log file with a `-odump <blah>' option.

TEMPORARY FILES: If you have trouble because of running out of space in `/tmp/' (or wherever your installation thinks temporary files should go), you may use the `-tmpdir <dir>' option to specify an alternate directory. For example, `-tmpdir .' says to put temporary files in the current working directory.

BETTER IDEA FOR TEMPORARY FILES: Use your `TMPDIR' environment variable. Set it to the name of the directory where temporary files should be put. GCC and other programs will honour the `TMPDIR' variable as well.

EVEN BETTER IDEA: Set the `TMPDIR' variable when building GHC, and never worry about `TMPDIR' again. (see the build documentation).


Go to the first, previous, next, last section, table of contents.