building a helper binary with cabal

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Sat May 17 18:48:25 EDT 2008


On Wed, 2008-04-02 at 21:07 -0700, Evan Martin wrote:
> I got caught up in other things, so I'm also late to reply.
> 
> Here's the whole story now, so you don't have to reskim the archive.
> My program has a helper executable that's built with gcc.  I want to
> install it alongside my Haskell binary.  I can write a post-copy hook
> like this:
> 
> > creplChildCopy :: Args -> CopyFlags -> PackageDescription
> >                -> LocalBuildInfo -> IO ()
> > creplChildCopy args flags desc buildinfo = do
> >   print "copy hook"
> >   let dirs = absoluteInstallDirs desc buildinfo (copyDest flags)
> >   print ("copying child to ", libexecdir dirs </> creplChildName)
> >   copyFileVerbose (copyVerbose flags) (creplChildPath buildinfo)
> >                   (libexecdir dirs </> creplChildName)
> 
> And then run it like this:
> 
> $ ./Setup.lhs copy -v3
> directory dist/doc/html/c-repl does exist: False
> Creating /home/martine/.local/share/doc/c-repl-0.1 (and its parents)
> copy LICENSE to /home/martine/.local/share/doc/c-repl-0.1/LICENSE
> Installing: /home/martine/.local/bin
> Creating /home/martine/.local/bin (and its parents)
> copy dist/build/c-repl/c-repl to /home/martine/.local/bin/c-repl
> "copy hook"
> ("copying child to ","/home/martine/.local/libexec/c-repl-child")
> copy dist/build/c-repl-child to /home/martine/.local/libexec/c-repl-child
> Setup.lhs: /home/martine/.local/libexec: copyFile: does not exist (No
> such file or directory)
> 
> That fails because this "libexec" dir doesn't exist.
> 
> My questions are:
> 1) Is it my responsibility to create the libexec dir if it doesn't exist?

At the moment, yes. Though Cabal knows of the libexec dir it doesn't
actually use it at all for anything yet. We have no particular support
for private binaries that you'd want to install into the libexec dir.

> 2) How can I get the "copy" phase to run as part of "install"?

>From my reading of the code, the copyHook is only run by the copy action
and not the install action as I previously suggested. So you'd have to
override the instHook rather than the copyHook.

> 3) Do you have advice on installed vs. uninstalled paths?  Currently
> to facilitate development when getting the path to that executable I
> do something like this (where "Paths" is the module generated by
> cabal):

We recently added support for finding data files when the package is in
the build tree rather than in its final installed location. We do that
by having the Paths_foo module check an env var which if set provides
the datadir. There's no reason we could not generalise that and support
it for each of bindir, libdir, libexec dir etc.

If that would help you perhaps you could file a ticket.

Duncan



More information about the Libraries mailing list