~ubuntu-branches/ubuntu/utopic/haskell-hmatrix/utopic

« back to all changes in this revision

Viewing changes to Config.hs

  • Committer: Package Import Robot
  • Author(s): Denis Laxalde
  • Date: 2013-07-06 15:37:50 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130706153750-wxxplc788jedqvv5
Tags: 0.15.0.0-1
* New upstream release.
* Make it clear in copyright that the license is GPL-3 (as stated by the
  author in <https://github.com/albertoruiz/hmatrix/issues/45>) although
  there is no proper license file yet.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import System.Exit
21
21
import System.Environment
22
22
import System.Directory(createDirectoryIfMissing)
 
23
import System.FilePath((</>))
23
24
import Data.List(isPrefixOf, intercalate)
24
25
import Distribution.Simple.LocalBuildInfo
25
26
import Distribution.Simple.Configure
38
39
       , "blas gslcblas gfortran"        -- Arch Linux with normal blas and lapack
39
40
       ]
40
41
 
 
42
-- location of test program
 
43
testProgLoc bInfo = buildDir bInfo </> "dummy.c"
 
44
testOutLoc bInfo = buildDir bInfo </> "dummy"
 
45
 
 
46
-- write test program
 
47
writeTestProg bInfo contents = writeFile (testProgLoc bInfo) contents
 
48
 
 
49
-- compile, discarding error messages
 
50
compile cmd = do
 
51
    let processRecord = (shell $ join cmd) { std_out = CreatePipe
 
52
                                           , std_err = CreatePipe }
 
53
    ( _, _, _, h) <- createProcess processRecord
 
54
    waitForProcess h
 
55
 
 
56
-- command to compile the test program
 
57
compileCmd bInfo buildInfo = [ "gcc "
 
58
                             , (join $ ccOptions buildInfo)  
 
59
                             , (join $ cppOptions buildInfo) 
 
60
                             , (join $ map ("-I"++) $ includeDirs buildInfo) 
 
61
                             , testProgLoc bInfo
 
62
                             , "-o"
 
63
                             , testOutLoc bInfo 
 
64
                             , (join $ map ("-L"++) $ extraLibDirs buildInfo) 
 
65
                             ]
 
66
 
41
67
-- compile a simple program with symbols from GSL and LAPACK with the given libs
42
 
testprog bInfo buildInfo libs fmks =
43
 
    "echo \"#include <gsl/gsl_sf_gamma.h>\nint main(){dgemm_(); zgesvd_(); gsl_sf_gamma(5);}\""
44
 
                     ++" > " ++ (buildDir bInfo) ++ "/dummy.c; gcc "
45
 
                     ++ (join $ ccOptions buildInfo) ++ " "
46
 
                     ++ (join $ cppOptions buildInfo) ++ " "
47
 
                     ++ (join $ map ("-I"++) $ includeDirs buildInfo) ++ " " 
48
 
                     ++ (buildDir bInfo) ++ "/dummy.c -o "
49
 
                     ++ (buildDir bInfo) ++ "/dummy "
50
 
                     ++ (join $ map ("-L"++) $ extraLibDirs buildInfo) ++ " "
51
 
                     ++ (prepend "-l" $ libs) ++ " "
52
 
                     ++ (prepend "-framework " fmks) ++ " > /dev/null 2> /dev/null"
 
68
testprog bInfo buildInfo libs fmks = do
 
69
    writeTestProg bInfo "#include <gsl/gsl_sf_gamma.h>\nint main(){dgemm_(); zgesvd_(); gsl_sf_gamma(5);}"
 
70
    compile $ compileCmd bInfo 
 
71
                         buildInfo 
 
72
                            ++ [ (prepend "-l" $ libs)
 
73
                               , (prepend "-framework " fmks) ] 
53
74
 
54
75
join = intercalate " "
55
76
prepend x = unwords . map (x++) . words
56
77
 
57
 
check bInfo buildInfo libs fmks = (ExitSuccess ==) `fmap` system (testprog bInfo buildInfo libs fmks)
 
78
check bInfo buildInfo libs fmks = (ExitSuccess ==) `fmap` testprog bInfo buildInfo libs fmks
58
79
 
59
80
-- simple test for GSL
60
 
gsl bInfo buildInfo = "echo \"#include <gsl/gsl_sf_gamma.h>\nint main(){gsl_sf_gamma(5);}\""
61
 
           ++" > " ++ (buildDir bInfo) ++ "/dummy.c; gcc "
62
 
           ++ (join $ ccOptions buildInfo) ++ " "
63
 
           ++ (join $ cppOptions buildInfo) ++ " "
64
 
           ++ (join $ map ("-I"++) $ includeDirs buildInfo) ++ " " 
65
 
           ++ (buildDir bInfo) ++ "/dummy.c -o "
66
 
           ++ (buildDir bInfo) ++ "/dummy "
67
 
           ++ (join $ map ("-L"++) $ extraLibDirs buildInfo) ++ " -lgsl -lgslcblas"
68
 
           ++ " > /dev/null 2> /dev/null"
 
81
gsl bInfo buildInfo = do
 
82
    writeTestProg bInfo "#include <gsl/gsl_sf_gamma.h>\nint main(){gsl_sf_gamma(5);}"
 
83
    compile $ compileCmd bInfo buildInfo ++ ["-lgsl", "-lgslcblas"]
69
84
 
70
85
-- test for gsl >= 1.12
71
 
gsl112 bInfo buildInfo =
72
 
    "echo \"#include <gsl/gsl_sf_exp.h>\nint main(){gsl_sf_exprel_n_CF_e(1,1,0);}\""
73
 
           ++" > " ++ (buildDir bInfo) ++ "/dummy.c; gcc " 
74
 
           ++ (buildDir bInfo) ++ "/dummy.c "
75
 
           ++ (join $ ccOptions buildInfo) ++ " "
76
 
           ++ (join $ cppOptions buildInfo) ++ " "
77
 
           ++ (join $ map ("-I"++) $ includeDirs buildInfo)
78
 
           ++" -o " ++ (buildDir bInfo) ++ "/dummy "
79
 
           ++ (join $ map ("-L"++) $ extraLibDirs buildInfo) ++ " -lgsl -lgslcblas"
80
 
           ++ " > /dev/null 2> /dev/null"
 
86
gsl112 bInfo buildInfo = do
 
87
    writeTestProg bInfo "#include <gsl/gsl_sf_exp.h>\nint main(){gsl_sf_exprel_n_CF_e(1,1,0);}"
 
88
    compile $ compileCmd bInfo buildInfo ++ ["-lgsl", "-lgslcblas"]
81
89
 
82
90
-- test for odeiv2
83
 
gslodeiv2 bInfo buildInfo =
84
 
    "echo \"#include <gsl/gsl_odeiv2.h>\nint main(){return 0;}\""
85
 
           ++" > " ++ (buildDir bInfo) ++ "/dummy.c; gcc " 
86
 
           ++ (buildDir bInfo) ++ "/dummy.c "
87
 
           ++ (join $ ccOptions buildInfo) ++ " "
88
 
           ++ (join $ cppOptions buildInfo) ++ " "
89
 
           ++ (join $ map ("-I"++) $ includeDirs buildInfo)
90
 
           ++" -o " ++ (buildDir bInfo) ++ "/dummy "
91
 
           ++ (join $ map ("-L"++) $ extraLibDirs buildInfo) ++ " -lgsl -lgslcblas"
92
 
           ++ " > /dev/null 2> /dev/null"
93
 
 
94
 
 
95
 
checkCommand c = (ExitSuccess ==) `fmap` system c
 
91
gslodeiv2 bInfo buildInfo = do
 
92
    writeTestProg bInfo "#include <gsl/gsl_odeiv2.h>\nint main(){return 0;}"
 
93
    compile $ compileCmd bInfo buildInfo ++ ["-lgsl", "-lgslcblas"]
 
94
 
 
95
checkCommand c = (ExitSuccess ==) `fmap` c
96
96
 
97
97
-- test different configurations until the first one works
98
98
try _ _ _ _ [] = return Nothing