Cabal and c2hs

Isaac Jones ijones at syntaxpolice.org
Sat Apr 30 13:51:26 EDT 2005


Dominic Steinitz <dominic.steinitz at blueyonder.co.uk> writes:

> Isaac,
>
> Thanks for your prompt response. I did have a look at these references before 
> I posted and didn't find them very enlightening. 

Was the example test case I gave you helpful?  We sorta didn't put the
UserHooks in the docs too much because they are a feature that we're
not as sure about in the long-term; they're trying to support a lot of
different kinds of things, and it'll take time to make sure we get
them right.  In the meantime, maybe I'll add a little documentation
with the warning that things might change.

> BTW I discovered a bug in the .chs handler. You have "-o " rather than "-o". I 
> can try and send a patch but it might be easier if you edit the file 
> yourself.

Does "-o " not work?  According to the help output, it's correct:

Usage: c2hs [ option... ] [header-file] binding-file

  -C CPPOPTS  --cppopts=CPPOPTS   pass CPPOPTS to the C preprocessor
  -c CPP      --cpp=CPP           use executable CPP to invoke C preprocessor
  -d TYPE     --dump=TYPE         dump internal information (for debugging)
  -h, -?      --help              brief help (the present message)
  -i INCLUDE  --include=INCLUDE   include paths for .chi files
  -k          --keep              keep pre-processed C header
  -o FILE     --output=FILE       output result to FILE (should end in .hs)
  -v          --version           show version information
              --old-ffi[=OLDFFI]  use the FFI without `Ptr a'

> import Distribution.Simple
> import Distribution.Simple.Utils(rawSystemPath)
>
> main =
>    defaultMainWithHooks
>       defaultUserHooks {
>          hookedPreProcessors =
>             [("chs", \_ _ -> myPpC2hs)]
>       }
>
> myPpC2hs inFile outFile verbose
>     = rawSystemPath verbose "c2hs" ["-o" ++ outFile, "ip_icmp.h", inFile]

That looks fine.  You could just use "system" instead of
rawSystemPath, but since you found it, that's cool.

I don't use c2hs myself; is there any pattern to the .h files we might
want to preprocess?  Any way to derive it from the sources or the
module names?  I'm not sure how better to support the kind of thing
you need.

peace,

  isaac


More information about the Libraries mailing list