Dynamically formed list of modules in a Cabal package?

Dimitry Golubovsky golubovsky at gmail.com
Thu Jul 9 12:50:43 EDT 2009


Is this possible to have a list of modules (in the other-modules field
of Cabal package description) be formed dynamically?

It is a common situation when a Haskell module in a Cabal package is
created as a result of preprocessing e. g. by cpp or hsc2hs. This
covers the case of one non-Haskell source and one Haskell module.

Another scenario, when ffipkg (or domconv*) is used, results in
several files (C headers or IDL files) converted to any unpredictable
number of Haskell modules (approx. one per C structure/union in the
case of ffipkg, or one per IDL interface in the case of domconv).
These modules often have meaningless names (esp. in the case of
ffipkg) and are not to be used outside of the package that depends on
them. So it is not possible to pre-hardcode them all in the
hand-written Cabal file.

How can Cabal be instructed to add those modules to the list of
modules defined in the "other-modules" field of package description?

A possible solution might be to create a "private" package before the
"main" package is configured, and include the private package into the
list of build-depends of the main package. This approach was used for
the webidl** package [1] by adding a pre-configuration hook that goes
into a sub-directory and builds the private package out of C library
headers [2]. This is not a very good solution because private packages
will occupy the global package namespace while not being usable by any
package other than their main package.

A much better solution (one that I am seeking) would be to tell Cabal
at some point (via hook, before the configure step starts) that there
are more modules in the package that mentioned in the other-modules
field. How can this be done?

Thanks for any ideas.

* for applications that run in a web browser via conversion to
Javascript and use IDL-defined DOM interfaces
** this package incorporates an IDL lexer generated with flex and used via FFI

[1] http://hackage.haskell.org/package/webidl, also see the build log
at http://hackage.haskell.org/packages/archive/webidl/0.1.1/logs/success/ghc-6.10
[2] http://code.haskell.org/yc2js/webidl/Setup.hs
Dimitry Golubovsky

Anywhere on the Web

More information about the Libraries mailing list