Skip to content

Instantly share code, notes, and snippets.

@lpsmith
Created February 6, 2014 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lpsmith/8837629 to your computer and use it in GitHub Desktop.
Save lpsmith/8837629 to your computer and use it in GitHub Desktop.
import Distribution.Simple
import Distribution.Simple.Setup
import Distribution.Simple.LocalBuildInfo
import Distribution.PackageDescription
import Distribution.Version
import Text.Groom
-- This checks the direct dependency of the bytestring package being
-- compiled against to set the bytestring_has_itoa_c and
-- bytestring_has_builder flags accordingly.
main = defaultMainWithHooks simpleUserHooks {
confHook = \pkg flags -> do
putStr "pkg:\n\n"
putStr (groom pkg)
putStr "\n\n\nflags:\n\n"
putStr (groom flags)
if null (configConstraints flags)
then do
lbi <- confHook simpleUserHooks pkg flags
putStr "\n\n\nlbi:\n\n"
putStr (groom lbi)
putStr "\n"
return lbi
else do
let bytestring_version =
case [ versionBranch v
| (Dependency pkg ver) <- configConstraints flags
, pkg == PackageName "bytestring"
, (Just v) <- [isSpecificVersion ver] ]
of
[v] -> v
vs -> error ("error detecting bytestring version " ++ show vs)
putStr "\n\n\nbytestring_version: "
putStr (groom bytestring_version)
let has_itoa_c = ( FlagName "bytestring_has_itoa_c"
, bytestring_version >= [0,10] )
let has_builder = ( FlagName "bytestring_has_builder"
, bytestring_version >= [0,10,4] )
let update fs gs =
fs ++ [ g | g <- gs, not $ any (\f -> fst f == fst g) fs]
let flags' = flags { configConfigurationsFlags =
update [has_itoa_c, has_builder]
(configConfigurationsFlags flags) }
putStr "\n\nconfigConfigurationsFlags flags':\n\n"
putStr (groom (configConfigurationsFlags flags'))
putStr "\n\n"
lbi' <- confHook simpleUserHooks pkg flags'
putStr "\n\nlbi':\n\n"
putStr (groom lbi')
putStr "\n"
return lbi'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment