Can Cabal use GHC's preprocessor?

Simon Marlow simonmar at
Thu Jul 14 08:56:00 EDT 2005

On 11 July 2005 06:37, Isaac Jones wrote:

> Brian Smith <brianlsmith at> writes:
>> I have some source files which need CPP style preprocessing. Since I
>> am using GHC, I would like to automatically use GHC's preprocessor
>> instead of having to download and install cpphs. For example, I want
>> to "runghc ./Setup.hs haddock" without cpphs installed. However,
>> references to cpphs are hard-coded into Cabal. What is the best way
>> to go about accomplishing this?
> I believe that if you say "ghc-options: -cpp" or whatever it is, then
> it should use the "built-in" one for building.  Don't list CPP as an
> extension in this case.  This may mess up the preprocessing during the
> haddock command, fwiw.
> I'd recommend against doing this, though.  The "built-in" one actually
> just calls cpp, which does not accept all legal Haskell code.
> Sticking to hscpp will help your code to be more portable as well.
> Another option is to patch the PreProcess.hs module to check to see if
> cpphs exists and if not, to use "raw" cpp, or cpp through ghc or
> something.  If someone does this, they should also patch the sanity
> checker to add a warning.

I've fixed this now (as per your last paragraph above), and done some
rudimentary testing.  I didn't add a warning though; perhaps we should,
but since it's using the same preprocessor that will be used when
compiling with GHC anyway, I'm not sure a warning will be terribly

I hope this can sneak into the Cabal release, but don't worry if not.


More information about the Libraries mailing list