
Suppose I write some code that can work with Gtk2hs or wxHaskell. How do I go about making that into a package? Specifically, how do I make it so that you don't have to install Gtk2hs *and* wxHaskell to build it? Do I have to actually make it into two seperate packages to do that? Also, supposing we have another package which requires the first, but doesn't care whether it's using Gtk2hs or wxHaskell. How do I do that? Obviously the answer depends on what happens in the previous step. If I make two seperate packages, for example, and they both export the same module, can I just add optional dependancies on both? Does Cabal support that? Not that I'm attempting to *do* this, you understand. I'd just like to know if it's possible...

On Sun, Jan 17, 2010 at 10:09:14AM +0000, Andrew Coppin wrote:
Suppose I write some code that can work with Gtk2hs or wxHaskell. How do I go about making that into a package?
Specifically, how do I make it so that you don't have to install Gtk2hs *and* wxHaskell to build it? Do I have to actually make it into two seperate packages to do that?
You just need to add a flag 'gtk2hs' and then construct the Build-Depends depending on the value of the flag. However, if e.g. that flag is by default True, then users of wxHaskell will have to manually change its value. I.e. it is not automatic based on what the user has on his system.
Also, supposing we have another package which requires the first, but doesn't care whether it's using Gtk2hs or wxHaskell. How do I do that? Obviously the answer depends on what happens in the previous step. If I make two seperate packages, for example, and they both export the same module, can I just add optional dependancies on both? Does Cabal support that?
Just depend on the package :), how the first package was compiled is out of the scope of the second one.
Not that I'm attempting to *do* this, you understand. I'd just like to know if it's possible...
Another possibility is to factor out your API into an abstract interface (maybe using type classes). Then you would have firstpackage-base firstpackage-wx firstpackage-gtk secondpackage (depending on firstpackage-base) But then you only factor your problem to your outmost package, say, myapp (depends on -wx or -gtk depending on a flag) HTH, -- Felipe.

Suppose I write some code that can work with Gtk2hs or wxHaskell. How do I go about making that into a package?
You just need to add a flag 'gtk2hs' and then construct the Build-Depends depending on the value of the flag. However, if e.g. that flag is by default True, then users of wxHaskell will have to manually change its value. I.e. it is not automatic based on what the user has on his system.
Not true. The value of the flag *is* determined automatically based on what packages you already have on your system. For instance, if your cabal file says Flag hasGTK Default: True Library if hasGTK Build-Depends: gtk2hs else Build-Depends: wxHaskell and your installed system has wx but not gtk, then it will still select the wx branch, regardless of the value of the flag default. The only meaning of the default value is, if *both* possible solutions could potentially build successfully, then which one will be preferred. Regards, Malcolm
participants (3)
-
Andrew Coppin
-
Felipe Lessa
-
Malcolm Wallace