[first stab at preprocessors ijones@syntaxpolice.org**20050210081923] { hunk ./doc/Cabal.xml 5 + Distribution.PreProcess'> hunk ./doc/Cabal.xml 634 - hooks. See &Simple; for details. + hooks. See for details. hunk ./doc/Cabal.xml 962 + + + +
+ Preprocessors and Customization + + As mentioned in , there + are a number of ways to customize your packages. Preprocessors + like cpp allow you to call out to external programs to alter your + source files. "User Hooks" allow you to add your own + functionality before and after a command is run. (see also + &Simple;) + +
+ PreProcessors + + Some more complex packages may require the use of + preprocessors. There is a set of "built-in" preprocessors in + the module Distribution.PreProcess, including Greencard, C2hs, + Hsc2hs, Alex, Happy, and cpphs. + + The behavior of preprocessors is pretty straightforward. + If your package includes module "P", Cabal will first try to + find P.hs or P.lhs. Failing that, it looks for suffixes + relating to known preprocessors, such as P.cpphs. If it finds + P.cpphs, Cabal will generate P.hs from that and build it. + + If you want to use a preprocessor that's not defined in + Distribution.PreProcess.knownSuffixHandlers, you may define your + own and provide them as hooks (see ). A + "SuffixHandler" has the following type. + +type PPSuffixHandler + = (String, -- The extension + BuildInfo -> LocalBuildInfo -> PreProcessor) + +type PreProcessor = FilePath -- Location of source to preprocess + -> FilePath -- Output filename + -> Int -- verbose + -> IO ExitCode + + + For more information see &PreProcess;. + + You might therefore create your own preprocessor which, + for example prepends a comment to the given source file. This + definition would appear in your Setup.lhs file. + + + A Custom PreProcessor + +ppTestHandler :: FilePath -- ^InFile + -> FilePath -- ^OutFile + -> Int -- ^verbose + -> IO ExitCode +ppTestHandler inFile outFile verbose + = do when (verbose > 0) $ + putStrLn (inFile++" has been preprocessed to "++outFile) + stuff <- readFile inFile + writeFile outFile ("-- preprocessed as a test\n\n" ++ stuff) + return ExitSuccess + + + This preprocessor must then be hooked into your Setup + file with the function defaultMainWithHooks. + See for more details. + +
+
+ Hooks + ... }