<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't. As far as I can tell, I can't pass any flags to Haddock via the Cabal file. I would love to tell Hackage to run Haddock like so, "cabal haddock --haddock-option=--optghc=-D__HADDOCK__", but I don't know how.<br>
</blockquote></div><br>Let'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;"> hooks = simpleUserHooks { haddockHook = haddockHook' }</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' p l h f =</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> do putStrLn ("f=\"" ++ show f ++ "\"")</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> putStrLn ("f'=\"" ++ show f' ++ "\"")</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> haddock p l (hookedPreProcessors h) f'</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> where</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> -- 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;"> <b>define__HADDOCK__ = ("haddock",["--optghc=-D__HADDOCK__"])</b></span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> -- Add the flag to the the other flags.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> f' = 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 "--haddock-option=--optghc=-D__HADDOCK__" flag at the command line.<br><br>If I run "cabal haddock --verbose=3", I get:<br>
<br><span style="font-family: courier new,monospace;">f="HaddockFlags {haddockProgramPaths = [], haddockProgramArgs = [], haddockHoogle = Flag False, haddockHtmlLocation = NoFlag, haddockExecutables = Flag False, haddockInternal = Flag False, haddockCss = NoFlag, haddockHscolour = Flag False, haddockHscolourCss = NoFlag, haddockDistPref = Flag "dist", haddockVerbosity = Flag Deafening}"</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">f'="HaddockFlags {haddockProgramPaths = [], haddockProgramArgs = <b>[("haddock",["--optghc=-D__HADDOCK__"])]</b>, haddockHoogle = Flag False, haddockHtmlLocation = NoFlag, haddockExecutables = Flag False, haddockInternal = Flag False, haddockCss = NoFlag, haddockHscolour = Flag False, haddockHscolourCss = NoFlag, haddockDistPref = Flag "dist", haddockVerbosity = Flag Deafening}"</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;">("/.../haddock",["--html", ...</span><br>
<br>My flag shows up in f' but not in the actual call to haddock. Thus, it doesn't work.<br><br>With "cabal haddock --verbose=3 --haddock-option=--optghc=-D__HADDOCK__", I get:<br><br><span style="font-family: courier new,monospace;">f="HaddockFlags {haddockProgramPaths = [], haddockProgramArgs = [<b>("haddock",["--optghc=-D__HADDOCK__"])]</b>, haddockHoogle = Flag False, haddockHtmlLocation = NoFlag, haddockExecutables = Flag False, haddockInternal = Flag False, haddockCss = NoFlag, haddockHscolour = Flag False, haddockHscolourCss = NoFlag, haddockDistPref = Flag "dist", haddockVerbosity = Flag Deafening}"</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">f'="HaddockFlags {haddockProgramPaths = [], haddockProgramArgs = <b>[("haddock",["--optghc=-D__HADDOCK__"]),("haddock",["--optghc=-D__HADDOCK__"])]</b>, haddockHoogle = Flag False, haddockHtmlLocation = NoFlag, haddockExecutables = Flag False, haddockInternal = Flag False, haddockCss = NoFlag, haddockHscolour = Flag False, haddockHscolourCss = NoFlag, haddockDistPref = Flag "dist", haddockVerbosity = Flag Deafening}"</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;">("/.../haddock",[<b>"--optghc=-D__HADDOCK__"</b>,"--html", ...</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>