This repository has been archived by the owner on Jan 25, 2024. It is now read-only.
forked from haskellari/postgresql-libpq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Setup.hs
executable file
·74 lines (61 loc) · 1.93 KB
/
Setup.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
{-# LANGUAGE CPP #-}
#ifndef MIN_VERSION_Cabal
#define MIN_VERSION_Cabal(x,y,z) 0
#endif
import Distribution.Simple
import Distribution.Simple.Setup
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)
#if MIN_VERSION_Cabal(2,0,0)
import Distribution.Types.UnqualComponentName
#endif
flag :: String -> FlagName
#if MIN_VERSION_Cabal(2,0,0)
flag = mkFlagName
#else
flag = FlagName
#endif
#if MIN_VERSION_Cabal(2,0,0)
unqualComponentName :: String -> UnqualComponentName
unqualComponentName = mkUnqualComponentName
#else
unqualComponentName :: String -> String
unqualComponentName = id
#endif
#if !MIN_VERSION_Cabal(2,2,0)
unFlagAssignment :: [(FlagName, Bool)] -> [(FlagName, Bool)]
unFlagAssignment = id
#endif
main = defaultMainWithHooks simpleUserHooks {
confHook = \pkg flags -> do
if lookup (flag "use-pkg-config")
(unFlagAssignment (configConfigurationsFlags flags)) == Just True
then do
confHook simpleUserHooks pkg flags
else do
lbi <- confHook simpleUserHooks pkg flags
bi <- psqlBuildInfo lbi
return lbi {
localPkgDescr = updatePackageDescription
(Just bi, [(unqualComponentName "runtests", bi)]) (localPkgDescr lbi)
}
}
psqlBuildInfo :: LocalBuildInfo -> IO BuildInfo
psqlBuildInfo lbi = do
(pgconfigProg, _) <- requireProgram verbosity
(simpleProgram "pg_config") (withPrograms lbi)
let pgconfig = getProgramOutput 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