Can Cabal use GHC's preprocessor?

Isaac Jones ijones at syntaxpolice.org
Mon Jul 11 01:37:24 EDT 2005


Brian Smith <brianlsmith at gmail.com> 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.

peace,

  isaac


More information about the Libraries mailing list