Shared Haskell .so library with GHC 6.10.4 and Cabal

I wanted to extend an app written in ANSI C with a functionality written in Haskell. This can be somewhat complicated process. If you use GHC 6.12.1 or newer it can supposedly be easily done with -shared flag. Well, I’m not sure how it works there, but installing GHC 6.12.1 is a painful process. Instead I wanted to do the same with GHC 6.10.4. Turns out it can be done with a simple Makefile like this:

Now, this method works in general. However, I wanted to make a .cabal package description, because cabal-install handles some common tasks (like pulling dependencies and cleaning) automatically. This turned out to be little tricky. I had to cheat: the shared library is actually build as executable. Here is the core part of .cabal: