[Haskell-cafe] HookedBuildInfo and Cabal
Duncan Coutts
duncan.coutts at worc.ox.ac.uk
Thu Jan 8 19:03:57 EST 2009
On Thu, 2009-01-08 at 12:42 -0600, John Goerzen wrote:
> As a more general question, how can one use Cabal to detect PostgreSQL
> paths in a way that works with both GHC 6.8 and 6.10?
Yes:
The following is using "build-type: Simple" in HDBC-postgresql.cabal and
it does not use HDBC-postgresql.buildinfo.in or the other autoconf
files.
Note that I've not actually tested that this builds HDBC-postgresql
fully (I don't have postgres installed). But with a suitable hacked up
pgconfig/pg_config on the $PATH that it does pass the output to ghc,
hsc2hs etc. It works with Cabal-1.2 and 1.6.
I've not done it but you can also require a minimum pgconfig version if
you modify pgconfigProgram below to discover the version number. You'd
put the following in the .cabal file:
build-tools: pgconfig >= 7.3
or whatever.
Duncan
Setup.hs:
import Distribution.Simple
import Distribution.PackageDescription
import Distribution.Version
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Program
import Distribution.Verbosity
import Control.Monad
main = defaultMainWithHooks simpleUserHooks {
hookedPrograms = [pgconfigProgram],
confHook = \pkg flags -> do
lbi <- confHook defaultUserHooks pkg flags
bi <- psqlBuildInfo lbi
return lbi {
localPkgDescr = updatePackageDescription
(Just bi, []) (localPkgDescr lbi)
}
}
pgconfigProgram = (simpleProgram "pgconfig") {
programFindLocation = \verbosity -> do
pgconfig <- findProgramOnPath "pgconfig" verbosity
pg_config <- findProgramOnPath "pg_config" verbosity
return (pgconfig `mplus` pg_config)
}
psqlBuildInfo :: LocalBuildInfo -> IO BuildInfo
psqlBuildInfo lbi = do
(pgconfigProg, _) <- requireProgram verbosity
pgconfigProgram AnyVersion (withPrograms lbi)
let pgconfig = rawSystemProgramStdout verbosity pgconfigProg
incDir <- pgconfig ["--includedir"]
libDir <- pgconfig ["--libdir"]
return emptyBuildInfo {
extraLibDirs = [libDir],
includeDirs = [incDir]
}
where
verbosity = normal -- honestly, this is a hack
More information about the Haskell-Cafe
mailing list