summaryrefslogtreecommitdiff
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
parent0c2c887de10702206ee645452a86674500314948 (diff)
first version of configure(.hs)
-rw-r--r--Setup.lhs6
-rw-r--r--configure3
-rw-r--r--configure.hs90
-rw-r--r--hmatrix.cabal38
4 files changed, 107 insertions, 30 deletions
diff --git a/Setup.lhs b/Setup.lhs
index 6b32049..9b055c9 100644
--- a/Setup.lhs
+++ b/Setup.lhs
@@ -1,4 +1,8 @@
1#! /usr/bin/env runhaskell 1#! /usr/bin/env runhaskell
2 2
3> import Distribution.Simple 3> import Distribution.Simple
4> main = defaultMain 4> import System(system)
5
6> main = defaultMainWithHooks autoconfUserHooks {runTests = t}
7
8> t _ _ _ _ = system ( "runhaskell examples/tests.hs") >> return()
diff --git a/configure b/configure
new file mode 100644
index 0000000..b93aee9
--- /dev/null
+++ b/configure
@@ -0,0 +1,3 @@
1#! /bin/sh
2
3runhaskell configure.hs $* \ No newline at end of file
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")
diff --git a/hmatrix.cabal b/hmatrix.cabal
index b283bca..8235753 100644
--- a/hmatrix.cabal
+++ b/hmatrix.cabal
@@ -1,5 +1,5 @@
1Name: hmatrix 1Name: hmatrix
2Version: 0.5.1.1 2Version: 0.5.1.2
3License: GPL 3License: GPL
4License-file: LICENSE 4License-file: LICENSE
5Author: Alberto Ruiz 5Author: Alberto Ruiz
@@ -14,9 +14,11 @@ Category: Math
14tested-with: GHC ==6.10.2 14tested-with: GHC ==6.10.2
15 15
16cabal-version: >=1.2 16cabal-version: >=1.2
17build-type: Simple 17build-type: Custom
18extra-source-files: lib/Numeric/LinearAlgebra/Tests/quickCheckCompat.h 18extra-source-files: lib/Numeric/LinearAlgebra/Tests/quickCheckCompat.h
19 19
20extra-source-files: configure configure.hs README INSTALL
21extra-tmp-files: hmatrix.buildinfo
20 22
21flag splitBase 23flag splitBase
22 description: Choose the new smaller, split-up base package. 24 description: Choose the new smaller, split-up base package.
@@ -30,9 +32,8 @@ flag accelerate
30 default: False 32 default: False
31 33
32flag unsafe 34flag unsafe
33 description: Compile the library with bound checking disabled. 35 description: Compile the library with bound checking disabled.
34 default: False 36 default: False
35
36 37
37library 38library
38 if flag(splitBase) 39 if flag(splitBase)
@@ -117,30 +118,9 @@ library
117 extra-libraries: gsl mkl_lapack mkl_intel_lp64 mkl_sequential mkl_core 118 extra-libraries: gsl mkl_lapack mkl_intel_lp64 mkl_sequential mkl_core
118 else 119 else
119 extra-libraries: gsl mkl_lapack mkl_intel mkl_sequential mkl_core 120 extra-libraries: gsl mkl_lapack mkl_intel mkl_sequential mkl_core
120 else 121
121 if flag(accelerate) 122 if flag(accelerate)
122 frameworks: Accelerate 123 frameworks: Accelerate
123 extra-libraries: gsl 124 extra-libraries: gsl
124 else
125
126 extra-libraries: gsl lapack
127
128 -- Include additional libraries if they are
129 -- required by your system to link -lgsl -llapack
130
131 -- (In ubuntu/debian cblas is included in blas,
132 -- which is automatically linked by lapack, so
133 -- nothing more is required.)
134
135 -- Examples:
136
137 -------- if blas/cblas are not automatically linked by lapack:
138 -- blas cblas
139
140 -------- Nonoptimized cblas included in gsl:
141 -- gslcblas
142 125
143 -------- Arch Linux with atlas-lapack: 126-- the extra-libraries required for gsl and lapack are automatically detected by configure(.hs)
144 -- f77blas cblas atlas gcc_s
145 -------- Arch Linux with normal blas and lapack:
146 -- blas gslcblas gfortran