summaryrefslogtreecommitdiff
path: root/configure.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2009-04-27 17:29:05 +0000
committerAlberto Ruiz <aruiz@um.es>2009-04-27 17:29:05 +0000
commit03cab9651b0c3d4de1f1830c9ff5cebfd7fbb3aa (patch)
tree6d12e220f5c0851d02ed2194fe2c31b4f9d97575 /configure.hs
parent0c2c887de10702206ee645452a86674500314948 (diff)
first version of configure(.hs)
Diffstat (limited to 'configure.hs')
-rw-r--r--configure.hs90
1 files changed, 90 insertions, 0 deletions
diff --git a/configure.hs b/configure.hs
new file mode 100644
index 0000000..3b0aaa3
--- /dev/null
+++ b/configure.hs
@@ -0,0 +1,90 @@
1#! /usr/bin/env runhaskell
2{- configure.hs for hmatrix
3 ------------------------
4
5 GSL and LAPACK may require auxiliary libraries which depend on OS,
6 distribution, and implementation. This script tries to to find out
7 the correct link command for your system.
8 Suggestions and contributions are welcome.
9
10 By default we try to link -lgsl -llapack. This works in ubuntu/debian,
11 both with and without ATLAS.
12 If this fails we try different sets of additional libraries which are
13 known to work in some systems.
14
15 The desired libraries can also be explicitly given by the user using cabal
16 flags (e.g., -fmkl, -faccelerate) or --configure-option=link:lib1,lib2,lib3,...
17
18-}
19
20import System
21import Data.List(isPrefixOf)
22import Distribution.Simple.LocalBuildInfo
23import Distribution.Simple.Configure
24import Distribution.PackageDescription
25
26-- possible additional dependencies for the desired libs (by default gsl lapack)
27
28opts = [ "" -- Ubuntu/Debian
29 , "blas"
30 , "blas cblas"
31 , "cblas"
32 , "gslcblas"
33 , "blas gslcblas"
34 , "f77blas cblas atlas gcc_s" -- Arch Linux (older version of atlas-lapack)
35 , "blas gslcblas gfortran" -- Arch Linux with normal blas and lapack
36 ]
37
38-- compile a simple program with symbols from GSL and LAPACK with the given libs
39testprog libs fmks = "echo \"int main(){zgesvd_(); gsl_sf_gamma();}\" > /tmp/dummy.c; gcc /tmp/dummy.c "
40 ++ f1 libs ++ " " ++ f2 fmks ++ " > /dev/null 2> /dev/null"
41
42f1 = unwords . map ("-l"++) . words
43f2 = unwords . map ("-framework "++) . words
44
45check libs fmks = (ExitSuccess ==) `fmap` system (testprog libs fmks)
46
47-- test different configurations until the first one works
48try _ _ [] = return Nothing
49try b f (opt:rest) = do
50 ok <- check (b ++ " " ++ opt) f
51 if ok then return (Just opt)
52 else try b f rest
53
54-- read --configure-option=link:lib1,lib2,lib3,etc
55linkop = "link:"
56getUserLink = concatMap (g . drop (length linkop)) . filter (isPrefixOf linkop)
57 where g = map cs
58 cs ',' = ' '
59 cs x = x
60
61main = do
62 putStr "Checking foreign libraries..."
63
64 args <- getArgs
65 Just bInfo <- maybeGetPersistBuildConfig "dist"
66
67 let Just lib = library . localPkgDescr $ bInfo
68 base = unwords . extraLibs . libBuildInfo $ lib
69 fwks = unwords . frameworks . libBuildInfo $ lib
70 auxpref = getUserLink args
71
72 -- We extract the desired libs from hmatrix.cabal (using a cabal flags)
73 -- and from a posible --configure-option=link:lib1,lib2,lib3
74 -- by default the desired libs are gsl lapack.
75
76 let pref = if null (words (base ++ " " ++ auxpref)) then "gsl lapack" else auxpref
77 fullOpts = map ((pref++" ")++) opts
78
79 r <- try base fwks fullOpts
80 case r of
81 Nothing -> do
82 putStrLn " FAIL"
83 putStrLn " *** Sorry, I can't link gsl and lapack."
84 putStrLn " *** Please make sure that the appropriate -dev packages are installed."
85 putStrLn " *** You can also specify the required libraries using"
86 putStrLn " *** cabal install hmatrix --configure-option=link:lib1,lib2,lib3,etc."
87 writeFile "hmatrix.buildinfo" ("buildable: False\n")
88 Just ops -> do
89 putStrLn " OK"
90 writeFile "hmatrix.buildinfo" ("extra-libraries: " ++ ops++"\n")