<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Distribution.Simple.PreProcess</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[ window.onload = function () {pageLoad();setSynopsis("mini_Distribution-Simple-PreProcess.html");}; //]]> </script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">Cabal-1.14.0: A framework for packaging Haskell software</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Portability</th><td>portable</td></tr><tr><th>Maintainer</th><td>cabal-devel@haskell.org</td></tr><tr><th>Safe Haskell</th><td>None</td></tr></table><p class="caption">Distribution.Simple.PreProcess</p></div><div id="description"><p class="caption">Description</p><div class="doc"><p>This defines a <code><a href="Distribution-Simple-PreProcess.html#t:PreProcessor">PreProcessor</a></code> abstraction which represents a pre-processor that can transform one kind of file into another. There is also a <code><a href="Distribution-Simple-PreProcess.html#t:PPSuffixHandler">PPSuffixHandler</a></code> which is a combination of a file extension and a function for configuring a <code><a href="Distribution-Simple-PreProcess.html#t:PreProcessor">PreProcessor</a></code>. It defines a bunch of known built-in preprocessors like <code>cpp</code>, <code>cpphs</code>, <code>c2hs</code>, <code>hsc2hs</code>, <code>happy</code>, <code>alex</code> etc and lists them in <code><a href="Distribution-Simple-PreProcess.html#v:knownSuffixHandlers">knownSuffixHandlers</a></code>. On top of this it provides a function for actually preprocessing some sources given a bunch of known suffix handlers. This module is not as good as it could be, it could really do with a rewrite to address some of the problems we have with pre-processors. </p></div></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"><li class="src short"><a href="#v:preprocessComponent">preprocessComponent</a> :: <a href="Distribution-PackageDescription.html#t:PackageDescription">PackageDescription</a> -> <a href="Distribution-Simple-LocalBuildInfo.html#t:Component">Component</a> -> <a href="Distribution-Simple-LocalBuildInfo.html#t:LocalBuildInfo">LocalBuildInfo</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a> -> <a href="Distribution-Verbosity.html#t:Verbosity">Verbosity</a> -> [<a href="Distribution-Simple-PreProcess.html#t:PPSuffixHandler">PPSuffixHandler</a>] -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:knownSuffixHandlers">knownSuffixHandlers</a> :: [<a href="Distribution-Simple-PreProcess.html#t:PPSuffixHandler">PPSuffixHandler</a>]</li><li class="src short"><a href="#v:ppSuffixes">ppSuffixes</a> :: [<a href="Distribution-Simple-PreProcess.html#t:PPSuffixHandler">PPSuffixHandler</a>] -> [<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>]</li><li class="src short"><span class="keyword">type</span> <a href="#t:PPSuffixHandler">PPSuffixHandler</a> = (<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>, <a href="Distribution-PackageDescription.html#t:BuildInfo">BuildInfo</a> -> <a href="Distribution-Simple-LocalBuildInfo.html#t:LocalBuildInfo">LocalBuildInfo</a> -> <a href="Distribution-Simple-PreProcess.html#t:PreProcessor">PreProcessor</a>)</li><li class="src short"><span class="keyword">data</span> <a href="#t:PreProcessor">PreProcessor</a> = <a href="#v:PreProcessor">PreProcessor</a> {<ul class="subs"><li><a href="#v:platformIndependent">platformIndependent</a> :: <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a></li><li><a href="#v:runPreProcessor">runPreProcessor</a> :: (<a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a>, <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a>) -> (<a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a>, <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a>) -> <a href="Distribution-Verbosity.html#t:Verbosity">Verbosity</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> ()</li></ul>}</li><li class="src short"><a href="#v:mkSimplePreProcessor">mkSimplePreProcessor</a> :: (<a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a> -> <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a> -> <a href="Distribution-Verbosity.html#t:Verbosity">Verbosity</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> ()) -> (<a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a>, <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a>) -> (<a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a>, <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a>) -> <a href="Distribution-Verbosity.html#t:Verbosity">Verbosity</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:runSimplePreProcessor">runSimplePreProcessor</a> :: <a href="Distribution-Simple-PreProcess.html#t:PreProcessor">PreProcessor</a> -> <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a> -> <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a> -> <a href="Distribution-Verbosity.html#t:Verbosity">Verbosity</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:ppCpp">ppCpp</a> :: <a href="Distribution-PackageDescription.html#t:BuildInfo">BuildInfo</a> -> <a href="Distribution-Simple-LocalBuildInfo.html#t:LocalBuildInfo">LocalBuildInfo</a> -> <a href="Distribution-Simple-PreProcess.html#t:PreProcessor">PreProcessor</a></li><li class="src short"><a href="#v:ppCpp-39-">ppCpp'</a> :: [<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>] -> <a href="Distribution-PackageDescription.html#t:BuildInfo">BuildInfo</a> -> <a href="Distribution-Simple-LocalBuildInfo.html#t:LocalBuildInfo">LocalBuildInfo</a> -> <a href="Distribution-Simple-PreProcess.html#t:PreProcessor">PreProcessor</a></li><li class="src short"><a href="#v:ppGreenCard">ppGreenCard</a> :: <a href="Distribution-PackageDescription.html#t:BuildInfo">BuildInfo</a> -> <a href="Distribution-Simple-LocalBuildInfo.html#t:LocalBuildInfo">LocalBuildInfo</a> -> <a href="Distribution-Simple-PreProcess.html#t:PreProcessor">PreProcessor</a></li><li class="src short"><a href="#v:ppC2hs">ppC2hs</a> :: <a href="Distribution-PackageDescription.html#t:BuildInfo">BuildInfo</a> -> <a href="Distribution-Simple-LocalBuildInfo.html#t:LocalBuildInfo">LocalBuildInfo</a> -> <a href="Distribution-Simple-PreProcess.html#t:PreProcessor">PreProcessor</a></li><li class="src short"><a href="#v:ppHsc2hs">ppHsc2hs</a> :: <a href="Distribution-PackageDescription.html#t:BuildInfo">BuildInfo</a> -> <a href="Distribution-Simple-LocalBuildInfo.html#t:LocalBuildInfo">LocalBuildInfo</a> -> <a href="Distribution-Simple-PreProcess.html#t:PreProcessor">PreProcessor</a></li><li class="src short"><a href="#v:ppHappy">ppHappy</a> :: <a href="Distribution-PackageDescription.html#t:BuildInfo">BuildInfo</a> -> <a href="Distribution-Simple-LocalBuildInfo.html#t:LocalBuildInfo">LocalBuildInfo</a> -> <a href="Distribution-Simple-PreProcess.html#t:PreProcessor">PreProcessor</a></li><li class="src short"><a href="#v:ppAlex">ppAlex</a> :: <a href="Distribution-PackageDescription.html#t:BuildInfo">BuildInfo</a> -> <a href="Distribution-Simple-LocalBuildInfo.html#t:LocalBuildInfo">LocalBuildInfo</a> -> <a href="Distribution-Simple-PreProcess.html#t:PreProcessor">PreProcessor</a></li><li class="src short"><a href="#v:ppUnlit">ppUnlit</a> :: <a href="Distribution-Simple-PreProcess.html#t:PreProcessor">PreProcessor</a></li></ul></div><div id="interface"><h1>Documentation</h1><div class="top"><p class="src"><a name="v:preprocessComponent" class="def">preprocessComponent</a> :: <a href="Distribution-PackageDescription.html#t:PackageDescription">PackageDescription</a> -> <a href="Distribution-Simple-LocalBuildInfo.html#t:Component">Component</a> -> <a href="Distribution-Simple-LocalBuildInfo.html#t:LocalBuildInfo">LocalBuildInfo</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a> -> <a href="Distribution-Verbosity.html#t:Verbosity">Verbosity</a> -> [<a href="Distribution-Simple-PreProcess.html#t:PPSuffixHandler">PPSuffixHandler</a>] -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Apply preprocessors to the sources from <code><a href="Distribution-PackageDescription.html#v:hsSourceDirs">hsSourceDirs</a></code> for a given component (lib, exe, or test suite). </p></div></div><div class="top"><p class="src"><a name="v:knownSuffixHandlers" class="def">knownSuffixHandlers</a> :: [<a href="Distribution-Simple-PreProcess.html#t:PPSuffixHandler">PPSuffixHandler</a>]</p><div class="doc"><p>Standard preprocessors: GreenCard, c2hs, hsc2hs, happy, alex and cpphs. </p></div></div><div class="top"><p class="src"><a name="v:ppSuffixes" class="def">ppSuffixes</a> :: [<a href="Distribution-Simple-PreProcess.html#t:PPSuffixHandler">PPSuffixHandler</a>] -> [<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>]</p><div class="doc"><p>Convenience function; get the suffixes of these preprocessors. </p></div></div><div class="top"><p class="src"><span class="keyword">type</span> <a name="t:PPSuffixHandler" class="def">PPSuffixHandler</a> = (<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>, <a href="Distribution-PackageDescription.html#t:BuildInfo">BuildInfo</a> -> <a href="Distribution-Simple-LocalBuildInfo.html#t:LocalBuildInfo">LocalBuildInfo</a> -> <a href="Distribution-Simple-PreProcess.html#t:PreProcessor">PreProcessor</a>)</p><div class="doc"><p>A preprocessor for turning non-Haskell files with the given extension into plain Haskell source files. </p></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:PreProcessor" class="def">PreProcessor</a> </p><div class="doc"><p>The interface to a preprocessor, which may be implemented using an external program, but need not be. The arguments are the name of the input file, the name of the output file and a verbosity level. Here is a simple example that merely prepends a comment to the given source file: </p><pre> ppTestHandler :: PreProcessor ppTestHandler = PreProcessor { platformIndependent = True, runPreProcessor = mkSimplePreProcessor $ \inFile outFile verbosity -> do info verbosity (inFile++" has been preprocessed to "++outFile) stuff <- readFile inFile writeFile outFile ("-- preprocessed as a test\n\n" ++ stuff) return ExitSuccess </pre><p>We split the input and output file names into a base directory and the rest of the file name. The input base dir is the path in the list of search dirs that this file was found in. The output base dir is the build dir where all the generated source files are put. </p><p>The reason for splitting it up this way is that some pre-processors don't simply generate one output .hs file from one input file but have dependencies on other genereated files (notably c2hs, where building one .hs file may require reading other .chi files, and then compiling the .hs file may require reading a generated .h file). In these cases the generated files need to embed relative path names to each other (eg the generated .hs file mentions the .h file in the FFI imports). This path must be relative to the base directory where the genereated files are located, it cannot be relative to the top level of the build tree because the compilers do not look for .h files relative to there, ie we do not use "-I .", instead we use "-I dist/build" (or whatever dist dir has been set by the user) </p><p>Most pre-processors do not care of course, so mkSimplePreProcessor and runSimplePreProcessor functions handle the simple case. </p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:PreProcessor" class="def">PreProcessor</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div class="subs fields"><p class="caption">Fields</p><dl><dt class="src"><a name="v:platformIndependent" class="def">platformIndependent</a> :: <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a></dt><dd class="doc empty"> </dd><dt class="src"><a name="v:runPreProcessor" class="def">runPreProcessor</a> :: (<a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a>, <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a>) -> (<a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a>, <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a>) -> <a href="Distribution-Verbosity.html#t:Verbosity">Verbosity</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> ()</dt><dd class="doc empty"> </dd></dl><div class="clear"></div></div></td></tr></table></div></div><div class="top"><p class="src"><a name="v:mkSimplePreProcessor" class="def">mkSimplePreProcessor</a> :: (<a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a> -> <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a> -> <a href="Distribution-Verbosity.html#t:Verbosity">Verbosity</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> ()) -> (<a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a>, <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a>) -> (<a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a>, <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a>) -> <a href="Distribution-Verbosity.html#t:Verbosity">Verbosity</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> ()</p></div><div class="top"><p class="src"><a name="v:runSimplePreProcessor" class="def">runSimplePreProcessor</a> :: <a href="Distribution-Simple-PreProcess.html#t:PreProcessor">PreProcessor</a> -> <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a> -> <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a> -> <a href="Distribution-Verbosity.html#t:Verbosity">Verbosity</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> ()</p></div><div class="top"><p class="src"><a name="v:ppCpp" class="def">ppCpp</a> :: <a href="Distribution-PackageDescription.html#t:BuildInfo">BuildInfo</a> -> <a href="Distribution-Simple-LocalBuildInfo.html#t:LocalBuildInfo">LocalBuildInfo</a> -> <a href="Distribution-Simple-PreProcess.html#t:PreProcessor">PreProcessor</a></p></div><div class="top"><p class="src"><a name="v:ppCpp-39-" class="def">ppCpp'</a> :: [<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>] -> <a href="Distribution-PackageDescription.html#t:BuildInfo">BuildInfo</a> -> <a href="Distribution-Simple-LocalBuildInfo.html#t:LocalBuildInfo">LocalBuildInfo</a> -> <a href="Distribution-Simple-PreProcess.html#t:PreProcessor">PreProcessor</a></p></div><div class="top"><p class="src"><a name="v:ppGreenCard" class="def">ppGreenCard</a> :: <a href="Distribution-PackageDescription.html#t:BuildInfo">BuildInfo</a> -> <a href="Distribution-Simple-LocalBuildInfo.html#t:LocalBuildInfo">LocalBuildInfo</a> -> <a href="Distribution-Simple-PreProcess.html#t:PreProcessor">PreProcessor</a></p></div><div class="top"><p class="src"><a name="v:ppC2hs" class="def">ppC2hs</a> :: <a href="Distribution-PackageDescription.html#t:BuildInfo">BuildInfo</a> -> <a href="Distribution-Simple-LocalBuildInfo.html#t:LocalBuildInfo">LocalBuildInfo</a> -> <a href="Distribution-Simple-PreProcess.html#t:PreProcessor">PreProcessor</a></p></div><div class="top"><p class="src"><a name="v:ppHsc2hs" class="def">ppHsc2hs</a> :: <a href="Distribution-PackageDescription.html#t:BuildInfo">BuildInfo</a> -> <a href="Distribution-Simple-LocalBuildInfo.html#t:LocalBuildInfo">LocalBuildInfo</a> -> <a href="Distribution-Simple-PreProcess.html#t:PreProcessor">PreProcessor</a></p></div><div class="top"><p class="src"><a name="v:ppHappy" class="def">ppHappy</a> :: <a href="Distribution-PackageDescription.html#t:BuildInfo">BuildInfo</a> -> <a href="Distribution-Simple-LocalBuildInfo.html#t:LocalBuildInfo">LocalBuildInfo</a> -> <a href="Distribution-Simple-PreProcess.html#t:PreProcessor">PreProcessor</a></p></div><div class="top"><p class="src"><a name="v:ppAlex" class="def">ppAlex</a> :: <a href="Distribution-PackageDescription.html#t:BuildInfo">BuildInfo</a> -> <a href="Distribution-Simple-LocalBuildInfo.html#t:LocalBuildInfo">LocalBuildInfo</a> -> <a href="Distribution-Simple-PreProcess.html#t:PreProcessor">PreProcessor</a></p></div><div class="top"><p class="src"><a name="v:ppUnlit" class="def">ppUnlit</a> :: <a href="Distribution-Simple-PreProcess.html#t:PreProcessor">PreProcessor</a></p></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.11.0</p></div></body></html>