Hi,

I'm bringing up an old thread, because it's very relevant to my problem.

On Tue, Nov 18, 2008 at 22:30, Duncan Coutts wrote:
On Tue, 2008-11-18 at 01:48 -0800, Jason Dusek wrote:
> I'd like to be able to do something like:
>
>     if (template-haskell < 2.3)
>       cpp-options: -D TH_THE_YOUNGER
>     else
>       cpp-options: -D TH_THE_ELDER
>
>   I guess this kind of thing is not possible at present?

It is possible, in two different ways.

The easiest way is that if you're using Cabal-1.6 then it provides cpp
macros to test the version number of packages you're using.

#if MIN_VERSION_template_haskell(2,3,0)
...
#elseif
...
#endif

The alternative that works back to Cabal-1.2 is to use:

flag newer-th

...
 if flag(newer-th)
   build-depends: template-haskell >= 2.3
   cpp-options: -D TH_THE_ELDER
 else
   build-depends: template-haskell < 2.3
   cpp-options: -D TH_THE_YOUNGER

Either I'm doing something wrong or this doesn't work for cabal-install and GHC 6.8.3. I used the "flag newer-th" approach in EMGM:

  https://svn.cs.uu.nl:12443/viewvc/dgp-haskell/EMGM/tags/emgm-0.2/emgm.cabal?view=markup

[...]

flag th23
   description: Define a CPP flag that enables conditional compilation
                for template-haskell package version 2.3 and newer.


Library

  [...]

   build-depends: base >= 3.0 && < 4.0,
                  template-haskell < 2.4

  -- Include deriveRep for Loc. This was introduced with
  -- template-haskell-2.3, included with GHC 6.10.
  if flag(th23)

    build-depends: template-haskell >= 2.3

    cpp-options: -DTH_LOC_DERIVEREP

  else

    build-depends: template-haskell < 2.3


  [...]

When I run cabal install emgm (with GHC 6.8.3 and either Cabal 1.2 or 1.6), it tries (and fails) to install template-haskell-2.3. That's exactly what I don't want. Any suggestions?

Thanks,
Sean