From c06d483ef60f7aeaf2d8bd8177a7af8ce097ecdb Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Wed, 17 Oct 2012 10:09:20 -0700 Subject: [PATCH] provide a flag to disable the FFI function getSystemEncoding Ignore-this: 4c6b01ddae1d86034b7d9522c188ad75 The library for querying locale isn't as easily available on Windows as it is on Linux. This flag provides a way for people who don't need the getSystemEncoding function to ease the build process. darcs-hash:20121017170920-76d51-7caa5ee9897c49a46d7beeb4aca5dcedf60e3c32 --- System/IO/Encoding.hs | 11 +++++++++-- encoding.cabal | 20 ++++++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/System/IO/Encoding.hs b/System/IO/Encoding.hs index e0c42b0..0e93eb7 100644 --- a/System/IO/Encoding.hs +++ b/System/IO/Encoding.hs @@ -131,12 +131,19 @@ interact f = do line <- hGetLine stdin hPutStrLn stdout (f line) +#ifdef SYSTEM_ENCODING foreign import ccall "system_encoding.h get_system_encoding" get_system_encoding :: IO CString +#endif --- | Returns the encoding used on the current system. +-- | Returns the encoding used on the current system. Currently only supported +-- on Linux-alikes. getSystemEncoding :: IO DynEncoding getSystemEncoding = do +#ifdef SYSTEM_ENCODING enc <- get_system_encoding str <- peekCString enc - return $ encodingFromString str \ No newline at end of file + return $ encodingFromString str +#else + error "getSystemEncoding is not supported on this platform" +#endif diff --git a/encoding.cabal b/encoding.cabal index d4af523..24b0b8a 100644 --- a/encoding.cabal +++ b/encoding.cabal @@ -18,11 +18,15 @@ Extra-Source-Files: Data/CharMap/Builder.hs Data/Array/Static/Builder.hs Data/Map/Static/Builder.hs + system_encoding.h + system_encoding.c Flag splitBase description: Choose the new smaller, split-up base package. Flag newGHC description: Use ghc version > 6.10 +Flag systemEncoding + description: Provide the getSystemEncoding action to query the locale. Library Build-Depends: binary, extensible-exceptions, HaXml >= 1.22 && < 1.24 @@ -35,6 +39,8 @@ Library else Build-Depends: base < 3 + Extensions: CPP + Exposed-Modules: Data.Encoding Data.Encoding.ByteSource @@ -102,9 +108,11 @@ Library Data.Map.Static Data.Static Data.CharMap - Includes: - system_encoding.h - Install-Includes: - system_encoding.h - C-Sources: - system_encoding.c \ No newline at end of file + if flag(systemEncoding) + Includes: + system_encoding.h + Install-Includes: + system_encoding.h + C-Sources: + system_encoding.c + CPP-Options: -DSYSTEM_ENCODING