summaryrefslogtreecommitdiff
path: root/Config.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2014-05-08 08:48:12 +0200
committerAlberto Ruiz <aruiz@um.es>2014-05-08 08:48:12 +0200
commit1925c123d7d8184a1d2ddc0a413e0fd2776e1083 (patch)
treefad79f909d9c3be53d68e6ebd67202650536d387 /Config.hs
parenteb3f702d065a4a967bb754977233e6eec408fd1f (diff)
empty hmatrix-base
Diffstat (limited to 'Config.hs')
-rw-r--r--Config.hs154
1 files changed, 0 insertions, 154 deletions
diff --git a/Config.hs b/Config.hs
deleted file mode 100644
index 5145d1a..0000000
--- a/Config.hs
+++ /dev/null
@@ -1,154 +0,0 @@
1{-
2 GSL and LAPACK may require auxiliary libraries which depend on OS,
3 distribution, and implementation. This script tries to to find out
4 the correct link command for your system.
5 Suggestions and contributions are welcome.
6
7 By default we try to link -lgsl -llapack. This works in ubuntu/debian,
8 both with and without ATLAS.
9 If this fails we try different sets of additional libraries which are
10 known to work in some systems.
11
12 The desired libraries can also be explicitly given by the user using cabal
13 flags (e.g., -fmkl, -faccelerate) or --configure-option=link:lib1,lib2,lib3,...
14
15-}
16
17module Config(config) where
18
19import System.Process
20import System.Exit
21import System.Environment
22import System.Directory(createDirectoryIfMissing)
23import System.FilePath((</>))
24import Data.List(isPrefixOf, intercalate)
25import Distribution.Simple.LocalBuildInfo
26import Distribution.Simple.Configure
27import Distribution.PackageDescription
28
29-- possible additional dependencies for the desired libs (by default gsl lapack)
30
31opts = [ "" -- Ubuntu/Debian
32 , "blas"
33 , "blas cblas"
34 , "cblas"
35 , "gslcblas"
36 , "blas gslcblas"
37 , "f77blas"
38 , "f77blas cblas atlas gcc_s" -- Arch Linux (older version of atlas-lapack)
39 , "blas gslcblas gfortran" -- Arch Linux with normal blas and lapack
40 ]
41
42-- location of test program
43testProgLoc bInfo = buildDir bInfo </> "dummy.c"
44testOutLoc bInfo = buildDir bInfo </> "dummy"
45
46-- write test program
47writeTestProg bInfo contents = writeFile (testProgLoc bInfo) contents
48
49-- compile, discarding error messages
50compile cmd = do
51 let processRecord = (shell $ unwords cmd) { std_out = CreatePipe
52 , std_err = CreatePipe }
53 ( _, _, _, h) <- createProcess processRecord
54 waitForProcess h
55
56-- command to compile the test program
57compileCmd bInfo buildInfo = [ "gcc "
58 , (unwords $ ccOptions buildInfo)
59 , (unwords $ cppOptions buildInfo)
60 , (unwords $ map ("-I"++) $ includeDirs buildInfo)
61 , testProgLoc bInfo
62 , "-o"
63 , testOutLoc bInfo
64 , (unwords $ map ("-L"++) $ extraLibDirs buildInfo)
65 ]
66
67-- compile a simple program with symbols from GSL and LAPACK with the given libs
68testprog bInfo buildInfo libs fmks = do
69 writeTestProg bInfo "#include <gsl/gsl_sf_gamma.h>\nint main(){dgemm_(); zgesvd_(); gsl_sf_gamma(5);}"
70 compile $ compileCmd bInfo
71 buildInfo
72 ++ [ (prepend "-l" $ libs)
73 , (prepend "-framework " fmks) ]
74
75prepend x = unwords . map (x++) . words
76
77check bInfo buildInfo libs fmks = (ExitSuccess ==) `fmap` testprog bInfo buildInfo libs fmks
78
79-- simple test for GSL
80gsl bInfo buildInfo = do
81 writeTestProg bInfo "#include <gsl/gsl_sf_gamma.h>\nint main(){gsl_sf_gamma(5);}"
82 compile $ compileCmd bInfo buildInfo ++ ["-lgsl", "-lgslcblas"]
83
84-- test for gsl >= 1.12
85gsl112 bInfo buildInfo = do
86 writeTestProg bInfo "#include <gsl/gsl_sf_exp.h>\nint main(){gsl_sf_exprel_n_CF_e(1,1,0);}"
87 compile $ compileCmd bInfo buildInfo ++ ["-lgsl", "-lgslcblas"]
88
89-- test for odeiv2
90gslodeiv2 bInfo buildInfo = do
91 writeTestProg bInfo "#include <gsl/gsl_odeiv2.h>\nint main(){return 0;}"
92 compile $ compileCmd bInfo buildInfo ++ ["-lgsl", "-lgslcblas"]
93
94checkCommand c = (ExitSuccess ==) `fmap` c
95
96-- test different configurations until the first one works
97try _ _ _ _ [] = return Nothing
98try l i b f (opt:rest) = do
99 ok <- check l i (b ++ " " ++ opt) f
100 if ok then return (Just opt)
101 else try l i b f rest
102
103-- read --configure-option=link:lib1,lib2,lib3,etc
104linkop = "--configure-option=link:"
105getUserLink = concatMap (g . drop (length linkop)) . filter (isPrefixOf linkop)
106 where g = map cs
107 cs ',' = ' '
108 cs x = x
109
110config :: LocalBuildInfo -> IO HookedBuildInfo
111
112config bInfo = do
113 putStr "Checking foreign libraries..."
114 args <- getArgs
115
116 let Just lib = library . localPkgDescr $ bInfo
117 buildInfo = libBuildInfo lib
118 base = unwords . extraLibs $ buildInfo
119 fwks = unwords . frameworks $ buildInfo
120 auxpref = getUserLink args
121
122 -- We extract the desired libs from hmatrix.cabal (using a cabal flags)
123 -- and from a posible --configure-option=link:lib1,lib2,lib3
124 -- by default the desired libs are gsl lapack.
125
126 let pref = if null (words (base ++ " " ++ auxpref)) then "gsl lapack" else auxpref
127 fullOpts = map ((pref++" ")++) opts
128
129 -- create the build directory (used for tmp files) if necessary
130 createDirectoryIfMissing True $ buildDir bInfo
131
132 r <- try bInfo buildInfo base fwks fullOpts
133
134 case r of
135 Nothing -> do
136 putStrLn " FAIL"
137 g <- checkCommand $ gsl bInfo buildInfo
138 if g
139 then putStrLn " *** Sorry, I can't link LAPACK."
140 else putStrLn " *** Sorry, I can't link GSL."
141 putStrLn " *** Please make sure that the appropriate -dev packages are installed."
142 putStrLn " *** You can also specify the required libraries using"
143 putStrLn " *** cabal install hmatrix --configure-option=link:lib1,lib2,lib3,etc."
144 return (Just emptyBuildInfo { buildable = False }, [])
145 Just ops -> do
146 putStrLn $ " OK " ++ ops
147 g1 <- checkCommand $ gsl112 bInfo buildInfo
148 let op1 = if g1 then "" else "-DGSL110"
149 g2 <- checkCommand $ gslodeiv2 bInfo buildInfo
150 let op2 = if g2 then "" else "-DGSLODE1"
151 opts = filter (not.null) [op1,op2]
152 let hbi = emptyBuildInfo { extraLibs = words ops, ccOptions = opts }
153 return (Just hbi, [])
154