<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I would be happy to work around it if I could, but I can&#39;t. As far as I can tell, I can&#39;t pass any flags to Haddock via the Cabal file. I would love to tell Hackage to run Haddock like so, &quot;cabal haddock --haddock-option=--optghc=-D__HADDOCK__&quot;, but I don&#39;t know how.<br>

</blockquote></div><br>Let&#39;s suppose that I do actually want to define __HADDOCK__ for my library. Can I do this with a user-defined hook using the Cabal library?<br><br><span style="font-family: courier new,monospace;">main :: IO ()</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">main = defaultMainWithHooks hooks where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; hooks = simpleUserHooks { haddockHook = haddockHook&#39; }</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">-- Define CPP __HADDOCK__ macro when running haddock.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">haddockHook&#39; p l h f =</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">&nbsp; do putStrLn (&quot;f=\&quot;&quot; ++ show f ++ &quot;\&quot;&quot;)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp; putStrLn (&quot;f&#39;=\&quot;&quot; ++ show f&#39; ++ &quot;\&quot;&quot;)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp; haddock p l (hookedPreProcessors h) f&#39;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; where</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; -- The Haddock flag to pass a flag to GHC to define the macro.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; <b>define__HADDOCK__ = (&quot;haddock&quot;,[&quot;--optghc=-D__HADDOCK__&quot;])</b></span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; -- Add the flag to the the other flags.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; f&#39; = f `mappend` emptyHaddockFlags { haddockProgramArgs = [define__HADDOCK__] }</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;">I got the value for define__HADDOCK__ from passing the &quot;--haddock-option=--optghc=-D__HADDOCK__&quot; flag at the command line.<br><br>If I run &quot;cabal haddock --verbose=3&quot;, I get:<br>

<br><span style="font-family: courier new,monospace;">f=&quot;HaddockFlags {haddockProgramPaths = [], haddockProgramArgs = [], haddockHoogle = Flag False, haddockHtmlLocation = NoFlag, haddockExecutables = Flag False, haddockInternal = Flag False, haddockCss = NoFlag, haddockHscolour = Flag False, haddockHscolourCss = NoFlag, haddockDistPref = Flag &quot;dist&quot;, haddockVerbosity = Flag Deafening}&quot;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">f&#39;=&quot;HaddockFlags {haddockProgramPaths = [], haddockProgramArgs = <b>[(&quot;haddock&quot;,[&quot;--optghc=-D__HADDOCK__&quot;])]</b>, haddockHoogle = Flag False, haddockHtmlLocation = NoFlag, haddockExecutables = Flag False, haddockInternal = Flag False, haddockCss = NoFlag, haddockHscolour = Flag False, haddockHscolourCss = NoFlag, haddockDistPref = Flag &quot;dist&quot;, haddockVerbosity = Flag Deafening}&quot;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">[...]</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">(&quot;/.../haddock&quot;,[&quot;--html&quot;, ...</span><br>

<br>My flag shows up in f&#39; but not in the actual call to haddock. Thus, it doesn&#39;t work.<br><br>With &quot;cabal haddock --verbose=3 --haddock-option=--optghc=-D__HADDOCK__&quot;, I get:<br><br><span style="font-family: courier new,monospace;">f=&quot;HaddockFlags {haddockProgramPaths = [], haddockProgramArgs = [<b>(&quot;haddock&quot;,[&quot;--optghc=-D__HADDOCK__&quot;])]</b>, haddockHoogle = Flag False, haddockHtmlLocation = NoFlag, haddockExecutables = Flag False, haddockInternal = Flag False, haddockCss = NoFlag, haddockHscolour = Flag False, haddockHscolourCss = NoFlag, haddockDistPref = Flag &quot;dist&quot;, haddockVerbosity = Flag Deafening}&quot;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">f&#39;=&quot;HaddockFlags {haddockProgramPaths = [], haddockProgramArgs = <b>[(&quot;haddock&quot;,[&quot;--optghc=-D__HADDOCK__&quot;]),(&quot;haddock&quot;,[&quot;--optghc=-D__HADDOCK__&quot;])]</b>, haddockHoogle = Flag False, haddockHtmlLocation = NoFlag, haddockExecutables = Flag False, haddockInternal = Flag False, haddockCss = NoFlag, haddockHscolour = Flag False, haddockHscolourCss = NoFlag, haddockDistPref = Flag &quot;dist&quot;, haddockVerbosity = Flag Deafening}&quot;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">[...]</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">(&quot;/.../haddock&quot;,[<b>&quot;--optghc=-D__HADDOCK__&quot;</b>,&quot;--html&quot;, ...</span><br style="font-family: courier new,monospace;">

<br>Now, the command-line flag shows up in all 3. And, of course, it works.<br><br>Is there something wrong with my hook code?<br><br>Regards,<br>Sean<br>