Chapter 9. Other Haskell utility programs

Table of Contents
9.1. Makefile dependencies in Haskell: using mkdependHS
9.2. Emacs `TAGS' for Haskell: hstags
9.3. “Yacc for Haskell”: happy
9.4. Pretty-printing Haskell: pphs

This section describes other program(s) which we distribute, that help with the Great Haskell Programming Task.

9.1. Makefile dependencies in Haskell: using mkdependHS

You run mkdependHS like this:
mkdependHS [mkdependHS options] [-- GHC options --] srcfile1 [srcfile2 ...]
or
ghc -M [mkdependHS options(prefix with -optdep)] [ GHC options ] srcfile1 [srcfile2 ...]
To see mkdependHS's command-line flags, give it a duff flag, e.g., mkdependHS -help.

In general, if module A contains the line
import B ...blah...
then mkdependHS will generate a dependency line of the form:
A.o : B.hi
If module A contains the line
import {-# SOURCE #-} B ...blah...
then mkdependHS will generate a dependency line of the form:
A.o : B.hi-boot
(See Section 3.7.1 for details of interface files.) If A imports multiple modules, then there will be multiple lines with A.o as the target.

By default, mkdependHS generates all the dependencies, and then concatenates them onto the end of makefile (or Makefile if makefile doesn't exist) bracketed by the lines "# DO NOT DELETE: Beginning of Haskell dependencies" and "# DO NOT DELETE: End of Haskell dependencies". If these lines already exist in the makefile, mkdependHS deletes the old dependencies first.

mkdependHS takes GHC options between -- brackets. It understands the following ones. Any options between -- brackets that it doesn't understand are simply ignored; this way you can feed your Makefile's standard GHC options to mkdependHS un-filtered.

-cpp

Run the C pre-processor over the input files. The default is not to.

-D<blah>

A cpp #define; usual meaning.

-i<dirs>

Add <dirs> (colon-separated) to list of directories to search for "import"ed modules.

-I<dir>

Add <dir> to list of directories to search for .h files (i.e., usual meaning).

-syslib <blah>

This program uses this GHC system library; take appropriate action (e.g., recognise when they are "import"ing a module from that library).

Here are the mkdependHS-specific options (not between --'s):

-v

Be verbose.

-v -v

Be very verbose.

-w

Turn off warnings about interface file shadowing.

-f blah

Use blah as the makefile, rather than makefile or Makefile. If blah doesn't exist, mkdependHS creates it. We often use -f .depend to put the dependencies in .depend and then include the file .depend into Makefile.

-o <osuf>

Use .<osuf> as the "target file" suffix ( default: o). Multiple -o flags are permitted (GHC2.05 onwards). Thus "-o hc -o o" will generate dependencies for .hc and .o files.

-s <suf>

Make extra dependencies that declare that files with suffix .<suf>_<osuf> depend on interface files with suffix .<suf>_hi, or (for {-# SOURCE #-} imports) on .hi-boot. Multiple -s flags are permitted. For example, -o hc -s a -s b will make dependencies for .hc on .hi, .a_hc on .a_hi, and .b_hc on .b_hi. (Useful in conjunction with NoFib "ways".)

--exclude-module=<file>

Regard <file> as "stable"; i.e., exclude it from having dependencies on it.

-x

same as --exclude-module

--exclude-directory=<dirs>

Regard the colon-separated list of directories <dirs> as containing stable, don't generate any dependencies on modules therein.

-Xdirs

same as --exclude-directory.

--include-module=<file>

Regard <file> as not "stable"; i.e., generate dependencies on it (if any). This option is normally used in conjunction with the --exclude-directory option.

--include-prelude

Regard prelude libraries as unstable, i.e., generate dependencies on the prelude modules used (including Prelude). This option is normally only used by the various system libraries. If a -syslib option is used, dependencies will also be generated on the library's interfaces.