diff options
author | Alberto Ruiz <aruiz@um.es> | 2011-03-02 10:34:29 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2011-03-02 10:34:29 +0000 |
commit | 52178710b4c5d2a2bdd9b612d7174e0a79ffe01f (patch) | |
tree | 974b1099acd5fb3a89416e7bda3919227a267680 /configure.hs | |
parent | 11b5d06fba6105b5da1306569a298ebdde51af79 (diff) |
import Configure.hs from Setup.lhs to be compiled with the same version of Cabal
Diffstat (limited to 'configure.hs')
-rw-r--r-- | configure.hs | 145 |
1 files changed, 0 insertions, 145 deletions
diff --git a/configure.hs b/configure.hs deleted file mode 100644 index bced948..0000000 --- a/configure.hs +++ /dev/null | |||
@@ -1,145 +0,0 @@ | |||
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.Process | ||
21 | import System.Exit | ||
22 | import System.Environment | ||
23 | import System.Directory(createDirectoryIfMissing) | ||
24 | import Data.List(isPrefixOf, intercalate) | ||
25 | import Distribution.Simple.LocalBuildInfo | ||
26 | import Distribution.Simple.Configure | ||
27 | import Distribution.PackageDescription | ||
28 | |||
29 | -- possible additional dependencies for the desired libs (by default gsl lapack) | ||
30 | |||
31 | opts = [ "" -- 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 | -- compile a simple program with symbols from GSL and LAPACK with the given libs | ||
43 | testprog bInfo buildInfo libs fmks = | ||
44 | "echo \"#include <gsl/gsl_sf_gamma.h>\nint main(){zgesvd_(); gsl_sf_gamma(5);}\"" | ||
45 | ++" > " ++ (buildDir bInfo) ++ "/dummy.c; gcc " | ||
46 | ++ (join $ ccOptions buildInfo) ++ " " | ||
47 | ++ (join $ cppOptions buildInfo) ++ " " | ||
48 | ++ (join $ map ("-I"++) $ includeDirs buildInfo) ++ " " | ||
49 | ++ (buildDir bInfo) ++ "/dummy.c -o " | ||
50 | ++ (buildDir bInfo) ++ "/dummy " | ||
51 | ++ (join $ map ("-L"++) $ extraLibDirs buildInfo) ++ " " | ||
52 | ++ (prepend "-l" $ libs) ++ " " | ||
53 | ++ (prepend "-framework " fmks) ++ " > /dev/null 2> /dev/null" | ||
54 | |||
55 | join = intercalate " " | ||
56 | prepend x = unwords . map (x++) . words | ||
57 | |||
58 | check bInfo buildInfo libs fmks = (ExitSuccess ==) `fmap` system (testprog bInfo buildInfo libs fmks) | ||
59 | |||
60 | -- simple test for GSL | ||
61 | gsl bInfo buildInfo = "echo \"#include <gsl/gsl_sf_gamma.h>\nint main(){gsl_sf_gamma(5);}\"" | ||
62 | ++" > " ++ (buildDir bInfo) ++ "/dummy.c; gcc " | ||
63 | ++ (join $ ccOptions buildInfo) ++ " " | ||
64 | ++ (join $ cppOptions buildInfo) ++ " " | ||
65 | ++ (join $ map ("-I"++) $ includeDirs buildInfo) ++ " " | ||
66 | ++ (buildDir bInfo) ++ "/dummy.c -o " | ||
67 | ++ (buildDir bInfo) ++ "/dummy " | ||
68 | ++ (join $ map ("-L"++) $ extraLibDirs buildInfo) ++ " -lgsl -lgslcblas" | ||
69 | ++ " > /dev/null 2> /dev/null" | ||
70 | |||
71 | -- test for gsl >= 1.12 | ||
72 | gsl112 bInfo buildInfo = | ||
73 | "echo \"#include <gsl/gsl_sf_exp.h>\nint main(){gsl_sf_exprel_n_CF_e(1,1,0);}\"" | ||
74 | ++" > " ++ (buildDir bInfo) ++ "/dummy.c; gcc " | ||
75 | ++ (buildDir bInfo) ++ "/dummy.c " | ||
76 | ++ (join $ ccOptions buildInfo) ++ " " | ||
77 | ++ (join $ cppOptions buildInfo) ++ " " | ||
78 | ++ (join $ map ("-I"++) $ includeDirs buildInfo) | ||
79 | ++" -o " ++ (buildDir bInfo) ++ "/dummy " | ||
80 | ++ (join $ map ("-L"++) $ extraLibDirs buildInfo) ++ " -lgsl -lgslcblas" | ||
81 | ++ " > /dev/null 2> /dev/null" | ||
82 | |||
83 | |||
84 | checkCommand c = (ExitSuccess ==) `fmap` system c | ||
85 | |||
86 | -- test different configurations until the first one works | ||
87 | try _ _ _ _ [] = return Nothing | ||
88 | try l i b f (opt:rest) = do | ||
89 | ok <- check l i (b ++ " " ++ opt) f | ||
90 | if ok then return (Just opt) | ||
91 | else try l i b f rest | ||
92 | |||
93 | -- read --configure-option=link:lib1,lib2,lib3,etc | ||
94 | linkop = "link:" | ||
95 | getUserLink = concatMap (g . drop (length linkop)) . filter (isPrefixOf linkop) | ||
96 | where g = map cs | ||
97 | cs ',' = ' ' | ||
98 | cs x = x | ||
99 | |||
100 | main = do | ||
101 | info <- maybeGetPersistBuildConfig "dist" | ||
102 | case info of | ||
103 | Nothing -> putStrLn "Please run \"cabal clean\" first." >> exitFailure | ||
104 | Just bInfo -> mainOk bInfo | ||
105 | |||
106 | mainOk bInfo = do | ||
107 | putStr "Checking foreign libraries..." | ||
108 | args <- getArgs | ||
109 | |||
110 | let Just lib = library . localPkgDescr $ bInfo | ||
111 | buildInfo = libBuildInfo lib | ||
112 | base = unwords . extraLibs $ buildInfo | ||
113 | fwks = unwords . frameworks $ buildInfo | ||
114 | auxpref = getUserLink args | ||
115 | |||
116 | -- We extract the desired libs from hmatrix.cabal (using a cabal flags) | ||
117 | -- and from a posible --configure-option=link:lib1,lib2,lib3 | ||
118 | -- by default the desired libs are gsl lapack. | ||
119 | |||
120 | let pref = if null (words (base ++ " " ++ auxpref)) then "gsl lapack" else auxpref | ||
121 | fullOpts = map ((pref++" ")++) opts | ||
122 | |||
123 | -- create the build directory (used for tmp files) if necessary | ||
124 | createDirectoryIfMissing True $ buildDir bInfo | ||
125 | |||
126 | r <- try bInfo buildInfo base fwks fullOpts | ||
127 | case r of | ||
128 | Nothing -> do | ||
129 | putStrLn " FAIL" | ||
130 | g <- checkCommand $ gsl bInfo buildInfo | ||
131 | if g | ||
132 | then putStrLn " *** Sorry, I can't link LAPACK." | ||
133 | else putStrLn " *** Sorry, I can't link GSL." | ||
134 | putStrLn " *** Please make sure that the appropriate -dev packages are installed." | ||
135 | putStrLn " *** You can also specify the required libraries using" | ||
136 | putStrLn " *** cabal install hmatrix --configure-option=link:lib1,lib2,lib3,etc." | ||
137 | writeFile "hmatrix.buildinfo" ("buildable: False\n") | ||
138 | Just ops -> do | ||
139 | putStrLn " OK" | ||
140 | g <- checkCommand $ gsl112 bInfo buildInfo | ||
141 | writeFile "hmatrix.buildinfo" $ "extra-libraries: " ++ | ||
142 | ops ++ "\n" ++ | ||
143 | if g | ||
144 | then "" | ||
145 | else "cc-options: -DGSL110\n" | ||