summaryrefslogtreecommitdiff
path: root/configure.hs
diff options
context:
space:
mode:
Diffstat (limited to 'configure.hs')
-rw-r--r--configure.hs63
1 files changed, 41 insertions, 22 deletions
diff --git a/configure.hs b/configure.hs
index d34cbe8..da18302 100644
--- a/configure.hs
+++ b/configure.hs
@@ -18,7 +18,7 @@
18-} 18-}
19 19
20import System 20import System
21import Data.List(isPrefixOf) 21import Data.List(isPrefixOf, intercalate)
22import Distribution.Simple.LocalBuildInfo 22import Distribution.Simple.LocalBuildInfo
23import Distribution.Simple.Configure 23import Distribution.Simple.Configure
24import Distribution.PackageDescription 24import Distribution.PackageDescription
@@ -36,34 +36,52 @@ opts = [ "" -- Ubuntu/Debian
36 ] 36 ]
37 37
38-- compile a simple program with symbols from GSL and LAPACK with the given libs 38-- compile a simple program with symbols from GSL and LAPACK with the given libs
39testprog libs fmks = "echo \"#include <gsl/gsl_sf_gamma.h>\nint main(){zgesvd_(); gsl_sf_gamma(5);}\"" 39testprog buildInfo libs fmks =
40 ++" > /tmp/dummy.c; gcc /tmp/dummy.c -o /tmp/dummy " 40 "echo \"#include <gsl/gsl_sf_gamma.h>\nint main(){zgesvd_(); gsl_sf_gamma(5);}\""
41 ++ f1 libs ++ " " ++ f2 fmks ++ " > /dev/null 2> /dev/null" 41 ++" > /tmp/dummy.c; gcc "
42 42 ++ (join $ ccOptions buildInfo) ++ " "
43f1 = unwords . map ("-l"++) . words 43 ++ (join $ cppOptions buildInfo) ++ " "
44f2 = unwords . map ("-framework "++) . words 44 ++ (join $ map ("-I"++) $ includeDirs buildInfo)
45 45 ++" /tmp/dummy.c -o /tmp/dummy "
46check libs fmks = (ExitSuccess ==) `fmap` system (testprog libs fmks) 46 ++ (join $ map ("-L"++) $ extraLibDirs buildInfo) ++ " "
47 ++ (prepend "-l" $ libs) ++ " "
48 ++ (prepend "-framework " fmks) ++ " > /dev/null 2> /dev/null"
49
50join = intercalate " "
51prepend x = unwords . map (x++) . words
52
53check buildInfo libs fmks = (ExitSuccess ==) `fmap` system (testprog buildInfo libs fmks)
47 54
48-- simple test for GSL 55-- simple test for GSL
49gsl = "echo \"#include <gsl/gsl_sf_gamma.h>\nint main(){gsl_sf_gamma(5);}\"" 56gsl buildInfo = "echo \"#include <gsl/gsl_sf_gamma.h>\nint main(){gsl_sf_gamma(5);}\""
50 ++" > /tmp/dummy.c; gcc /tmp/dummy.c -o /tmp/dummy -lgsl -lgslcblas" 57 ++" > /tmp/dummy.c; gcc "
58 ++ (join $ ccOptions buildInfo) ++ " "
59 ++ (join $ cppOptions buildInfo) ++ " "
60 ++ (join $ map ("-I"++) $ includeDirs buildInfo)
61 ++ " /tmp/dummy.c -o /tmp/dummy "
62 ++ (join $ map ("-L"++) $ extraLibDirs buildInfo) ++ " -lgsl -lgslcblas"
51 ++ " > /dev/null 2> /dev/null" 63 ++ " > /dev/null 2> /dev/null"
52 64
53-- test for gsl >= 1.12 65-- test for gsl >= 1.12
54gsl112 = "echo \"#include <gsl/gsl_sf_exp.h>\nint main(){gsl_sf_exprel_n_CF_e(1,1,0);}\"" 66gsl112 buildInfo =
55 ++" > /tmp/dummy.c; gcc /tmp/dummy.c -o /tmp/dummy -lgsl -lgslcblas" 67 "echo \"#include <gsl/gsl_sf_exp.h>\nint main(){gsl_sf_exprel_n_CF_e(1,1,0);}\""
68 ++" > /tmp/dummy.c; gcc /tmp/dummy.c "
69 ++ (join $ ccOptions buildInfo) ++ " "
70 ++ (join $ cppOptions buildInfo) ++ " "
71 ++ (join $ map ("-I"++) $ includeDirs buildInfo)
72 ++" -o /tmp/dummy "
73 ++ (join $ map ("-L"++) $ extraLibDirs buildInfo) ++ " -lgsl -lgslcblas"
56 ++ " > /dev/null 2> /dev/null" 74 ++ " > /dev/null 2> /dev/null"
57 75
58 76
59checkCommand c = (ExitSuccess ==) `fmap` system c 77checkCommand c = (ExitSuccess ==) `fmap` system c
60 78
61-- test different configurations until the first one works 79-- test different configurations until the first one works
62try _ _ [] = return Nothing 80try _ _ _ [] = return Nothing
63try b f (opt:rest) = do 81try i b f (opt:rest) = do
64 ok <- check (b ++ " " ++ opt) f 82 ok <- check i (b ++ " " ++ opt) f
65 if ok then return (Just opt) 83 if ok then return (Just opt)
66 else try b f rest 84 else try i b f rest
67 85
68-- read --configure-option=link:lib1,lib2,lib3,etc 86-- read --configure-option=link:lib1,lib2,lib3,etc
69linkop = "link:" 87linkop = "link:"
@@ -79,8 +97,9 @@ main = do
79 Just bInfo <- maybeGetPersistBuildConfig "dist" 97 Just bInfo <- maybeGetPersistBuildConfig "dist"
80 98
81 let Just lib = library . localPkgDescr $ bInfo 99 let Just lib = library . localPkgDescr $ bInfo
82 base = unwords . extraLibs . libBuildInfo $ lib 100 buildInfo = libBuildInfo lib
83 fwks = unwords . frameworks . libBuildInfo $ lib 101 base = unwords . extraLibs $ buildInfo
102 fwks = unwords . frameworks $ buildInfo
84 auxpref = getUserLink args 103 auxpref = getUserLink args
85 104
86 -- We extract the desired libs from hmatrix.cabal (using a cabal flags) 105 -- We extract the desired libs from hmatrix.cabal (using a cabal flags)
@@ -90,11 +109,11 @@ main = do
90 let pref = if null (words (base ++ " " ++ auxpref)) then "gsl lapack" else auxpref 109 let pref = if null (words (base ++ " " ++ auxpref)) then "gsl lapack" else auxpref
91 fullOpts = map ((pref++" ")++) opts 110 fullOpts = map ((pref++" ")++) opts
92 111
93 r <- try base fwks fullOpts 112 r <- try buildInfo base fwks fullOpts
94 case r of 113 case r of
95 Nothing -> do 114 Nothing -> do
96 putStrLn " FAIL" 115 putStrLn " FAIL"
97 g <- checkCommand gsl 116 g <- checkCommand $ gsl buildInfo
98 if g 117 if g
99 then putStrLn " *** Sorry, I can't link LAPACK." 118 then putStrLn " *** Sorry, I can't link LAPACK."
100 else putStrLn " *** Sorry, I can't link GSL." 119 else putStrLn " *** Sorry, I can't link GSL."
@@ -104,7 +123,7 @@ main = do
104 writeFile "hmatrix.buildinfo" ("buildable: False\n") 123 writeFile "hmatrix.buildinfo" ("buildable: False\n")
105 Just ops -> do 124 Just ops -> do
106 putStrLn " OK" 125 putStrLn " OK"
107 g <- checkCommand gsl112 126 g <- checkCommand $ gsl112 buildInfo
108 writeFile "hmatrix.buildinfo" $ "extra-libraries: " ++ 127 writeFile "hmatrix.buildinfo" $ "extra-libraries: " ++
109 ops ++ "\n" ++ 128 ops ++ "\n" ++
110 if g 129 if g