-------------------------------------------------------------------------------- -- $Id: HaskellConfig.hs,v 1.3 2003/12/18 18:29:03 graham Exp $ -- -- Copyright (c) 2004, G. KLYNE. All rights reserved. -- See end of this file for licence information. -------------------------------------------------------------------------------- -- | -- Module : HaskellConfig -- Copyright : (c) 2003, Graham Klyne -- License : GPL V2 -- -- Maintainer : Graham Klyne -- Stability : provisional -- Portability : H98 -- -- This module contains functions that retrieve information about the -- Haskell installation and configuration parameters for the system -- under which the current program is running. -- -- The intent is that this module can be easily replaced to capture the -- idiosyncrasies of different systems and Haskell installations. -- -------------------------------------------------------------------------------- module Distribution.HaskellConfig ( HaskellConfig(..) , getHaskellConfig , ProgramConfig(..) , getProgramConfig ) where import Distribution.Version ( Version(..) ) import Time ( Month(..) ) import Directory ( getCurrentDirectory ) import System ( getProgName, getArgs, getEnv ) import Monad ( liftM ) ------------------------------------------------------------ -- System and Haskell configuration information datatype ------------------------------------------------------------ data HaskellConfig = HaskellConfig { machineType :: [String] -- Machine architecture name , intBigEndian :: Bool -- Big-endian? (else little-endian) , systemType :: [String] -- Identify system type , haskellName :: String -- Haskell compiler name , haskellVers :: Version -- Haskell compiler version , intSize :: Int -- Number of bits in an Int , configDir :: FilePath -- Base directory for config files -- , configKey :: String -- Configuration key string } -- Machine CPU type identifiers -- Additional list elements may be added to refine the machine information machineI86 = ["I86"] machineSparc = ["Sparc"] machinePPC = ["PPC"] machineARM = ["ARM"] -- System type identifiers: -- Start with generic classification and add refining information -- finer refinements may be added over time, as needed. For most -- purposes, the first component should be sufficient to determine -- system-dependent behaviours. -- systemRedHat = ["Posix","Linux","RedHat"] systemSuse = ["Posix","Linux","Suse"] systemMaxOSX = ["Posix","Linux","Suse"] systemWin2000 = ["Win32","Win2K"] systemWinXP = ["Win32","WinXP"] systemWinNT = ["Win32","WinNT"] -- Haskell compiler names -- haskellGHC = "GHC" haskellHugs = "Hugs" haskellNHC = "NHC" haskellHBC = "HBC" haskellHBI = "HBI" ------------------------------------------------------------ -- getHaskellConfig ------------------------------------------------------------ getHaskellConfig :: (HaskellConfig -> a) -> IO a getHaskellConfig sel = liftM sel haskellConfig -- Static implementation; could use system calls to be more flexible. -- (Does memoization work inside the I/O monad? Does it matter?) haskellConfig :: IO HaskellConfig haskellConfig = return HaskellConfig { machineType = machineI86 , intBigEndian = False , systemType = systemWinXP , haskellName = "Hugs" , haskellVers = DateVersion 2002 November 0 , intSize = 32 , configDir = "C:\\DEV\\Hugs98" } ------------------------------------------------------------ -- Running program configuration data ------------------------------------------------------------ {- programArgs included here for experimentation, and is not needed -} data ProgramConfig = ProgramConfig { programFile :: FilePath -- Program file name , programArgs :: [String] -- Program arguments , programDir :: FilePath -- Base directory for config files } -- Parameterized by base program name, as Hugs doesn't seem to provide a -- way to get at the main program module name. The actual program name -- should be used where available. -- getProgramConfig :: String -> (ProgramConfig -> a) -> IO a getProgramConfig pn sel = liftM sel (programConfig pn) -- This needs working on. The idea is to return information that allows a -- program to access associated data and configuration information. -- programConfig :: String -> IO ProgramConfig programConfig pn = do { -- pn <- getProgName ; ar <- getArgs ; cd <- getCurrentDirectory ; return ProgramConfig { programFile = cd++"\\"++pn , programArgs = ar , programDir = cd } } -------------------------------------------------------------------------------- -- -- Copyright (c) 2004, G. KLYNE. All rights reserved. -- -- This is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- -- This software is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with Swish; if not, write to: -- The Free Software Foundation, Inc., -- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- -------------------------------------------------------------------------------- -- $Source: /file/cvsdev/HaskellRDF/HaskellConfig.hs,v $ -- $Author: graham $ -- $Revision: 1.3 $ -- $Log: HaskellConfig.hs,v $