From: <kr_...@us...> - 2005-06-16 18:09:01
|
Update of /cvsroot/htoolkit/HSQL/SQLite In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8511 Modified Files: Setup.lhs Log Message: Use pkg-config in the sqlite setup. Index: Setup.lhs =================================================================== RCS file: /cvsroot/htoolkit/HSQL/SQLite/Setup.lhs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Setup.lhs 9 Jun 2005 12:12:43 -0000 1.2 --- Setup.lhs 16 Jun 2005 18:08:52 -0000 1.3 *************** *** 1,62 **** ! #! runghc ! ! \begin{code} ! import Distribution.PackageDescription ! import Distribution.Setup ! import Distribution.Simple ! import Distribution.Simple.LocalBuildInfo ! import Distribution.Simple.Utils(rawSystemVerbose) ! import System.Info ! import System.Exit ! import System.Directory ! import Control.Monad(when) ! import Control.Exception(try) ! ! main = defaultMainWithHooks defaultUserHooks{preConf=preConf, postConf=postConf} ! where ! preConf :: [String] -> ConfigFlags -> IO HookedBuildInfo ! preConf args flags = do ! try (removeFile "SQLite.buildinfo") ! return emptyHookedBuildInfo ! postConf :: [String] -> ConfigFlags -> LocalBuildInfo -> IO ExitCode ! postConf args flags localbuildinfo = do ! testCompileRes <- testForSqlite localbuildinfo 0 ! case testCompileRes of ! ExitSuccess -> do ! message "sqlite library and headers are found" ! return testCompileRes ! ExitFailure n -> do ! message "sqlite library or headers aren't found" ! message "The package will not be build" ! let hbi = (Just emptyBuildInfo{buildable=False},[]) ! writeHookedBuildInfo "SQLite.buildinfo" hbi ! return testCompileRes ! \end{code} ! ! \begin{code} ! testForSqlite :: LocalBuildInfo -> Int -> IO ExitCode ! testForSqlite lbi verbose = do ! -- create program ! when (verbose > 0) $ do ! putStrLn "Test whether compile (test.hs):" ! putStrLn testProgram ! writeFile "test.hs" testProgram ! -- try to compile it ! let ghcPath = compilerPath (compiler lbi) ! let ghcArgs = ["test.hs", "-lsqlite", "--make", "-ffi", "-o", "test.bin"] ! res <- rawSystemVerbose verbose ghcPath ghcArgs ! try (removeFile "test.hs") ! try (removeFile "test.hi") ! try (removeFile "test.o") ! try (removeFile "test.bin") ! return res ! where ! testProgram = ! "import Foreign\n" ++ ! "import Foreign.C\n" ++ ! "foreign import ccall \"sqlite.h sqlite_open\" sqlite_open :: CString -> CInt -> Ptr CString -> IO (Ptr ())\n"++ ! "main = return ()" ! ! message :: String -> IO () ! message s = putStrLn $ "configure: " ++ s ! \end{code} --- 1,91 ---- ! #!/usr/bin/runghc ! ! \begin{code} ! import Distribution.PackageDescription ! import Distribution.Setup ! import Distribution.Simple ! import Distribution.Simple.LocalBuildInfo ! import Distribution.Simple.Utils(rawSystemVerbose) ! import System.Info ! import System.Exit ! import System.Directory ! import System.Process(runInteractiveProcess, waitForProcess) ! import System.IO(hClose, hGetContents, hPutStr, stderr) ! import Control.Monad(when) ! import Control.Exception(try) ! ! main = defaultMainWithHooks defaultUserHooks{preConf=preConf, postConf=postConf} ! where ! preConf :: [String] -> ConfigFlags -> IO HookedBuildInfo ! preConf args flags = do ! try (removeFile "SQLite.buildinfo") ! return emptyHookedBuildInfo ! postConf :: [String] -> ConfigFlags -> LocalBuildInfo -> IO ExitCode ! postConf args flags localbuildinfo = do ! mb_bi <- pkgConfigBuildInfo (configVerbose flags) "sqlite" ! let bi = case mb_bi of ! Just bi -> bi ! Nothing -> emptyBuildInfo{extraLibs=["sqlite"]} ! writeHookedBuildInfo "SQLite.buildinfo" (Just bi,[]) ! return ExitSuccess ! \end{code} ! ! The following code is derived from Distribution.Simple.Configure ! \begin{code} ! findProgram ! :: String -- ^ program name ! -> Maybe FilePath -- ^ optional explicit path ! -> IO (Maybe FilePath) ! findProgram name Nothing = do ! mb_path <- findExecutable name ! case mb_path of ! Nothing -> message ("No " ++ name ++ " found") ! Just path -> message ("Using " ++ name ++ ": " ++ path) ! return mb_path ! findProgram name (Just path) = do ! message ("Using " ++ name ++ ": " ++ path) ! return (Just path) ! ! rawSystemGrabOutput :: Int -> FilePath -> [String] -> IO String ! rawSystemGrabOutput verbose path args = do ! when (verbose > 0) $ ! putStrLn (path ++ concatMap (' ':) args) ! (inp,out,err,pid) <- runInteractiveProcess path args Nothing Nothing ! exitCode <- waitForProcess pid ! if exitCode /= ExitSuccess ! then do errMsg <- hGetContents err ! hPutStr stderr errMsg ! exitWith exitCode ! else return () ! hClose inp ! hClose err ! hGetContents out ! ! message :: String -> IO () ! message s = putStrLn $ "configure: " ++ s ! \end{code} ! ! Populate BuildInfo using pkg-config tool. ! \begin{code} ! pkgConfigBuildInfo :: Int -> String -> IO (Maybe BuildInfo) ! pkgConfigBuildInfo verbose pkgName = do ! mb_pkg_config_path <- findProgram "pkg-config" Nothing ! case mb_pkg_config_path of ! Just pkg_config_path -> do ! message ("configuring "++pkgName++" package using pkg-config") ! res <- rawSystemGrabOutput verbose pkg_config_path [pkgName, "--libs-only-l"] ! let libs = map (tail.tail) (words res) ! res <- rawSystemGrabOutput verbose pkg_config_path [pkgName, "--libs-only-L"] ! let lib_dirs = map (tail.tail) (words res) ! res <- rawSystemGrabOutput verbose pkg_config_path [pkgName, "--libs-only-other"] ! let ld_opts = words res ! res <- rawSystemGrabOutput verbose pkg_config_path [pkgName, "--cflags-only-I"] ! let inc_dirs = map (tail.tail) (words res) ! res <- rawSystemGrabOutput verbose pkg_config_path [pkgName, "--cflags-only-other"] ! let cc_opts = words res ! let bi = emptyBuildInfo{extraLibs=libs, extraLibDirs=lib_dirs, ldOptions=ld_opts, includeDirs=inc_dirs, ccOptions=cc_opts} ! return (Just bi) ! Nothing -> do ! message ("The package will be built using default settings for "++pkgName) ! return Nothing ! \end{code} |