tags:

views:

43

answers:

1

I'm trying to write a Haskell program which requires the output of external programs (such as lame, the mp3 encoder). While declaring dependency on a library is easy in cabal, how can one declare dependency on an executable?

+2  A: 

You can't currently add a dependency in the .cabal file for external executables, other than a list of known build tools (see build-tools: alex for example).

You can however specify build-type: Configure, and then use a separate configure script to search for any additional binaries (for example, an autoconf-based configure script is perfectly fine, and can be used to set constants in your source).

Note that searching for a runtime dependency -- such as a lame encoder -- at compile time may be a bad idea, as the build and run environments are different on many package systems. It might be a better idea to dynamically search for required binaries at program startup.

For example, hmp3 hunts for mpg321 with

     mmpg <- findExecutable (MPG321 :: String)

where MPG321 is the name of the program determined via a ./configure option. For more information, see the haddocks:

http://hackage.haskell.org/packages/archive/directory/latest/doc/html/System-Directory.html#v:findExecutable

Don Stewart
Does Cabal offer anything like a "post-install hook" that would allow, for example, to try to install an mp3 encoder at the time that the Cabal package is installed, rather than built?
Norman Ramsey
You can add hooks in the Setup.hs to script up any phase like that, but ideally installing external programs would be left to the package system (.deb or .rpm etc), which know how to find and build non-Haskell dependencies.
Don Stewart