Permalink
Browse files

Use pg_config to determine include and lib dirs

  • Loading branch information...
1 parent 6255cf7 commit f87160356c1a881c3d4ca11c6be36936db5e1ec4 Grant Monroe committed Oct 6, 2010
Showing with 52 additions and 3 deletions.
  1. +50 −1 Setup.hs
  2. +2 −2 libpq.cabal
View
51 Setup.hs 100644 → 100755
@@ -1,2 +1,51 @@
+#!/usr/bin/env runhaskell
+
import Distribution.Simple
-main = defaultMain
+import Distribution.PackageDescription
+import Distribution.Version
+
+import Distribution.Simple.LocalBuildInfo
+import Distribution.Simple.Program
+import Distribution.Verbosity
+
+import Data.Char (isSpace)
+import Data.List (dropWhile,reverse)
+
+import Control.Monad
+
+main = defaultMainWithHooks simpleUserHooks {
+ hookedPrograms = [pgconfigProgram],
+
+ confHook = \pkg flags -> do
+ lbi <- confHook simpleUserHooks pkg flags
+ bi <- psqlBuildInfo lbi
+
+ return lbi {
+ localPkgDescr = updatePackageDescription
+ (Just bi, [("runtests", bi)]) (localPkgDescr lbi)
+ }
+}
+
+pgconfigProgram = (simpleProgram "pgconfig") {
+ programFindLocation = \verbosity -> do
+ pgconfig <- findProgramLocation verbosity "pgconfig"
+ pg_config <- findProgramLocation verbosity "pg_config"
+ return (pgconfig `mplus` pg_config)
+ }
+
+psqlBuildInfo :: LocalBuildInfo -> IO BuildInfo
+psqlBuildInfo lbi = do
+ (pgconfigProg, _) <- requireProgram verbosity
+ pgconfigProgram (withPrograms lbi)
+ let pgconfig = rawSystemProgramStdout verbosity pgconfigProg
+
+ incDir <- pgconfig ["--includedir"]
+ libDir <- pgconfig ["--libdir"]
+
+ return emptyBuildInfo {
+ extraLibDirs = [strip libDir],
+ includeDirs = [strip incDir]
+ }
+ where
+ verbosity = normal -- honestly, this is a hack
+ strip x = dropWhile isSpace $ reverse $ dropWhile isSpace $ reverse x
View
@@ -16,9 +16,9 @@ Author: Grant Monroe
Maintainer: grant@tnarg.com
-- Copyright:
Category: Database
-Build-type: Simple
+Build-type: Custom
-- Extra-source-files:
-Cabal-version: >=1.2
+Cabal-version: >=1.8
Library
Exposed-modules: Database.PQ

0 comments on commit f871603

Please sign in to comment.