From 03cab9651b0c3d4de1f1830c9ff5cebfd7fbb3aa Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Mon, 27 Apr 2009 17:29:05 +0000 Subject: first version of configure(.hs) --- Setup.lhs | 6 +++- configure | 3 ++ configure.hs | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ hmatrix.cabal | 38 ++++++------------------- 4 files changed, 107 insertions(+), 30 deletions(-) create mode 100644 configure create mode 100644 configure.hs diff --git a/Setup.lhs b/Setup.lhs index 6b32049..9b055c9 100644 --- a/Setup.lhs +++ b/Setup.lhs @@ -1,4 +1,8 @@ #! /usr/bin/env runhaskell > import Distribution.Simple -> main = defaultMain +> import System(system) + +> main = defaultMainWithHooks autoconfUserHooks {runTests = t} + +> 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 @@ +#! /bin/sh + +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 @@ +#! /usr/bin/env runhaskell +{- configure.hs for hmatrix + ------------------------ + + GSL and LAPACK may require auxiliary libraries which depend on OS, + distribution, and implementation. This script tries to to find out + the correct link command for your system. + Suggestions and contributions are welcome. + + By default we try to link -lgsl -llapack. This works in ubuntu/debian, + both with and without ATLAS. + If this fails we try different sets of additional libraries which are + known to work in some systems. + + The desired libraries can also be explicitly given by the user using cabal + flags (e.g., -fmkl, -faccelerate) or --configure-option=link:lib1,lib2,lib3,... + +-} + +import System +import Data.List(isPrefixOf) +import Distribution.Simple.LocalBuildInfo +import Distribution.Simple.Configure +import Distribution.PackageDescription + +-- possible additional dependencies for the desired libs (by default gsl lapack) + +opts = [ "" -- Ubuntu/Debian + , "blas" + , "blas cblas" + , "cblas" + , "gslcblas" + , "blas gslcblas" + , "f77blas cblas atlas gcc_s" -- Arch Linux (older version of atlas-lapack) + , "blas gslcblas gfortran" -- Arch Linux with normal blas and lapack + ] + +-- compile a simple program with symbols from GSL and LAPACK with the given libs +testprog libs fmks = "echo \"int main(){zgesvd_(); gsl_sf_gamma();}\" > /tmp/dummy.c; gcc /tmp/dummy.c " + ++ f1 libs ++ " " ++ f2 fmks ++ " > /dev/null 2> /dev/null" + +f1 = unwords . map ("-l"++) . words +f2 = unwords . map ("-framework "++) . words + +check libs fmks = (ExitSuccess ==) `fmap` system (testprog libs fmks) + +-- test different configurations until the first one works +try _ _ [] = return Nothing +try b f (opt:rest) = do + ok <- check (b ++ " " ++ opt) f + if ok then return (Just opt) + else try b f rest + +-- read --configure-option=link:lib1,lib2,lib3,etc +linkop = "link:" +getUserLink = concatMap (g . drop (length linkop)) . filter (isPrefixOf linkop) + where g = map cs + cs ',' = ' ' + cs x = x + +main = do + putStr "Checking foreign libraries..." + + args <- getArgs + Just bInfo <- maybeGetPersistBuildConfig "dist" + + let Just lib = library . localPkgDescr $ bInfo + base = unwords . extraLibs . libBuildInfo $ lib + fwks = unwords . frameworks . libBuildInfo $ lib + auxpref = getUserLink args + + -- We extract the desired libs from hmatrix.cabal (using a cabal flags) + -- and from a posible --configure-option=link:lib1,lib2,lib3 + -- by default the desired libs are gsl lapack. + + let pref = if null (words (base ++ " " ++ auxpref)) then "gsl lapack" else auxpref + fullOpts = map ((pref++" ")++) opts + + r <- try base fwks fullOpts + case r of + Nothing -> do + putStrLn " FAIL" + putStrLn " *** Sorry, I can't link gsl and lapack." + putStrLn " *** Please make sure that the appropriate -dev packages are installed." + putStrLn " *** You can also specify the required libraries using" + putStrLn " *** cabal install hmatrix --configure-option=link:lib1,lib2,lib3,etc." + writeFile "hmatrix.buildinfo" ("buildable: False\n") + Just ops -> do + putStrLn " OK" + 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 @@ Name: hmatrix -Version: 0.5.1.1 +Version: 0.5.1.2 License: GPL License-file: LICENSE Author: Alberto Ruiz @@ -14,9 +14,11 @@ Category: Math tested-with: GHC ==6.10.2 cabal-version: >=1.2 -build-type: Simple +build-type: Custom extra-source-files: lib/Numeric/LinearAlgebra/Tests/quickCheckCompat.h +extra-source-files: configure configure.hs README INSTALL +extra-tmp-files: hmatrix.buildinfo flag splitBase description: Choose the new smaller, split-up base package. @@ -30,9 +32,8 @@ flag accelerate default: False flag unsafe - description: Compile the library with bound checking disabled. - default: False - + description: Compile the library with bound checking disabled. + default: False library if flag(splitBase) @@ -117,30 +118,9 @@ library extra-libraries: gsl mkl_lapack mkl_intel_lp64 mkl_sequential mkl_core else extra-libraries: gsl mkl_lapack mkl_intel mkl_sequential mkl_core - else - if flag(accelerate) + + if flag(accelerate) frameworks: Accelerate extra-libraries: gsl - else - - extra-libraries: gsl lapack - - -- Include additional libraries if they are - -- required by your system to link -lgsl -llapack - - -- (In ubuntu/debian cblas is included in blas, - -- which is automatically linked by lapack, so - -- nothing more is required.) - - -- Examples: - - -------- if blas/cblas are not automatically linked by lapack: - -- blas cblas - - -------- Nonoptimized cblas included in gsl: - -- gslcblas - -------- Arch Linux with atlas-lapack: - -- f77blas cblas atlas gcc_s - -------- Arch Linux with normal blas and lapack: - -- blas gslcblas gfortran +-- the extra-libraries required for gsl and lapack are automatically detected by configure(.hs) -- cgit v1.2.3