| 1 | -- -*-haskell-*- |
| 2 | -- =========================================================================== |
| 3 | -- C -> Haskell Compiler: configuration |
| 4 | -- |
| 5 | -- Author : Manuel M T Chakravarty |
| 6 | -- Created: 27 September 99 |
| 7 | -- |
| 8 | -- Version $Revision: 1.3 $ from $Date: 2005/02/07 00:04:28 $ |
| 9 | -- |
| 10 | -- Copyright (c) [1999..2003] Manuel M T Chakravarty |
| 11 | -- |
| 12 | -- This file is free software; you can redistribute it and/or modify |
| 13 | -- it under the terms of the GNU General Public License as published by |
| 14 | -- the Free Software Foundation; either version 2 of the License, or |
| 15 | -- (at your option) any later version. |
| 16 | -- |
| 17 | -- This file is distributed in the hope that it will be useful, |
| 18 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | -- GNU General Public License for more details. |
| 21 | -- |
| 22 | --- DESCRIPTION --------------------------------------------------------------- |
| 23 | -- |
| 24 | -- Configuration options; largely set by `configure'. |
| 25 | -- |
| 26 | --- TODO ---------------------------------------------------------------------- |
| 27 | -- |
| 28 | module C2HSConfig ( |
| 29 | -- |
| 30 | -- programs and paths |
| 31 | -- |
| 32 | cpp, cppopts, cppoptsdef, hpaths, dlsuffix, tmpdir, |
| 33 | -- |
| 34 | -- system-dependent definitions, as the New FFI isn't fully supported on all |
| 35 | -- systems yet |
| 36 | -- |
| 37 | Ptr, FunPtr, Storable(sizeOf, alignment), |
| 38 | -- |
| 39 | -- parameters of the targeted C compiler |
| 40 | -- |
| 41 | bitfieldDirection, bitfieldPadding, bitfieldIntSigned, bitfieldAlignment |
| 42 | ) where |
| 43 | |
| 44 | import Data.Ix (Ix) |
| 45 | import Data.Array (Array, array) |
| 46 | |
| 47 | import Foreign (Ptr, FunPtr) |
| 48 | import Foreign (Storable(sizeOf, alignment), toBool) |
| 49 | import Foreign.C (CInt(..)) |
| 50 | import System.Info (os) |
| 51 | |
| 52 | -- program settings |
| 53 | -- ---------------- |
| 54 | |
| 55 | -- C preprocessor executable (EXPORTED) |
| 56 | -- |
| 57 | cpp :: FilePath |
| 58 | cpp = case os of |
| 59 | "darwin" -> "gcc" |
| 60 | _ -> "cpp" |
| 61 | |
| 62 | -- C preprocessor options (EXPORTED) |
| 63 | -- |
| 64 | -- * `-x c' forces CPP to regard the input as C code; this option seems to be |
| 65 | -- understood at least on Linux, FreeBSD, and Solaris and seems to make a |
| 66 | -- difference over the default language setting on FreeBSD |
| 67 | -- |
| 68 | -- * `-P' would suppress `#line' directives |
| 69 | -- |
| 70 | cppopts :: [String] |
| 71 | cppopts = case (os,cpp) of |
| 72 | ("openbsd","cpp") -> ["-xc", "-w"] |
| 73 | (_,"cpp") -> ["-x", "c", "-w"] |
| 74 | (_,"gcc") -> ["-E", "-x", "c", "-w"] |
| 75 | _ -> [] |
| 76 | |
| 77 | -- C preprocessor option for including only definitions (EXPORTED) |
| 78 | cppoptsdef :: String |
| 79 | cppoptsdef = "-imacros" |
| 80 | |
| 81 | -- standard system search paths for header files (EXPORTED) |
| 82 | -- |
| 83 | hpaths :: [FilePath] |
| 84 | hpaths = [".", "/usr/include", "/usr/local/include"] |
| 85 | |
| 86 | -- OS-dependent suffix for dynamic libraries |
| 87 | -- |
| 88 | dlsuffix :: String |
| 89 | dlsuffix = error "C2HSConfig.dlsuffix" -- used to be: "@DLSUFFIX@" |
| 90 | |
| 91 | -- possibly system-dependent location for temporary files |
| 92 | -- |
| 93 | tmpdir :: String |
| 94 | tmpdir = error "C2HSConfig.tmpdir" -- used to be: "@TMPDIR@" |
| 95 | -- tmpdir is unused and it causes problems on widows since it ends up with |
| 96 | -- the value "C:\TMP" which is not a valid string. It'd need to be "C:\\TMP" |
| 97 | -- so just remove the thing for now. |
| 98 | |
| 99 | -- parameters of the targeted C compiler |
| 100 | -- ------------------------------------- |
| 101 | |
| 102 | -- indicates in which direction the C compiler fills bitfields (EXPORTED) |
| 103 | -- |
| 104 | -- * the value is 1 or -1, depending on whether the direction is growing |
| 105 | -- towards the MSB |
| 106 | -- |
| 107 | bitfieldDirection :: Int |
| 108 | bitfieldDirection = fromIntegral bitfield_direction |
| 109 | |
| 110 | foreign import ccall bitfield_direction :: CInt |
| 111 | |
| 112 | -- indicates whether a bitfield that does not fit into a partially filled |
| 113 | -- storage unit in its entirety introduce padding or split over two storage |
| 114 | -- units (EXPORTED) |
| 115 | -- |
| 116 | -- * `True' means that such a bitfield introduces padding (instead of being |
| 117 | -- split) |
| 118 | -- |
| 119 | bitfieldPadding :: Bool |
| 120 | bitfieldPadding = toBool bitfield_padding |
| 121 | |
| 122 | foreign import ccall bitfield_padding :: CInt |
| 123 | |
| 124 | -- indicates whether a bitfield of type `int' is signed in the targeted C |
| 125 | -- compiler (EXPORTED) |
| 126 | -- |
| 127 | bitfieldIntSigned :: Bool |
| 128 | bitfieldIntSigned = toBool bitfield_int_signed |
| 129 | |
| 130 | foreign import ccall bitfield_int_signed :: CInt |
| 131 | |
| 132 | -- the alignment constraint for a bitfield (EXPORTED) |
| 133 | -- |
| 134 | -- * this makes the assumption that the alignment of a bitfield is independent |
| 135 | -- of the bitfield's size |
| 136 | -- |
| 137 | bitfieldAlignment :: Int |
| 138 | bitfieldAlignment = fromIntegral bitfield_alignment |
| 139 | |
| 140 | foreign import ccall bitfield_alignment :: CInt |