diff options
author | Alberto Ruiz <aruiz@um.es> | 2009-04-27 17:29:05 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2009-04-27 17:29:05 +0000 |
commit | 03cab9651b0c3d4de1f1830c9ff5cebfd7fbb3aa (patch) | |
tree | 6d12e220f5c0851d02ed2194fe2c31b4f9d97575 | |
parent | 0c2c887de10702206ee645452a86674500314948 (diff) |
first version of configure(.hs)
-rw-r--r-- | Setup.lhs | 6 | ||||
-rw-r--r-- | configure | 3 | ||||
-rw-r--r-- | configure.hs | 90 | ||||
-rw-r--r-- | hmatrix.cabal | 38 |
4 files changed, 107 insertions, 30 deletions
@@ -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 | |||
3 | runhaskell 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 | |||
20 | import System | ||
21 | import Data.List(isPrefixOf) | ||
22 | import Distribution.Simple.LocalBuildInfo | ||
23 | import Distribution.Simple.Configure | ||
24 | import Distribution.PackageDescription | ||
25 | |||
26 | -- possible additional dependencies for the desired libs (by default gsl lapack) | ||
27 | |||
28 | opts = [ "" -- 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 | ||
39 | testprog 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 | |||
42 | f1 = unwords . map ("-l"++) . words | ||
43 | f2 = unwords . map ("-framework "++) . words | ||
44 | |||
45 | check libs fmks = (ExitSuccess ==) `fmap` system (testprog libs fmks) | ||
46 | |||
47 | -- test different configurations until the first one works | ||
48 | try _ _ [] = return Nothing | ||
49 | try 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 | ||
55 | linkop = "link:" | ||
56 | getUserLink = concatMap (g . drop (length linkop)) . filter (isPrefixOf linkop) | ||
57 | where g = map cs | ||
58 | cs ',' = ' ' | ||
59 | cs x = x | ||
60 | |||
61 | main = 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 @@ | |||
1 | Name: hmatrix | 1 | Name: hmatrix |
2 | Version: 0.5.1.1 | 2 | Version: 0.5.1.2 |
3 | License: GPL | 3 | License: GPL |
4 | License-file: LICENSE | 4 | License-file: LICENSE |
5 | Author: Alberto Ruiz | 5 | Author: Alberto Ruiz |
@@ -14,9 +14,11 @@ Category: Math | |||
14 | tested-with: GHC ==6.10.2 | 14 | tested-with: GHC ==6.10.2 |
15 | 15 | ||
16 | cabal-version: >=1.2 | 16 | cabal-version: >=1.2 |
17 | build-type: Simple | 17 | build-type: Custom |
18 | extra-source-files: lib/Numeric/LinearAlgebra/Tests/quickCheckCompat.h | 18 | extra-source-files: lib/Numeric/LinearAlgebra/Tests/quickCheckCompat.h |
19 | 19 | ||
20 | extra-source-files: configure configure.hs README INSTALL | ||
21 | extra-tmp-files: hmatrix.buildinfo | ||
20 | 22 | ||
21 | flag splitBase | 23 | flag 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 | ||
32 | flag unsafe | 34 | flag 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 | ||
37 | library | 38 | library |
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 | ||