[Haskell-cafe] ifdef based on which OS you're on

kudah kudahkukarek at gmail.com
Sat Feb 16 14:46:03 CET 2013


> __WIN32__

use mingw32_HOST_OS
> __MACOSX__

darwin_HOST_OS

On Sat, 16 Feb 2013 01:05:13 +1100 Andrew Cowie
<andrew at operationaldynamics.com> wrote:

> I've got a piece of code that looks like this:
> 
>         baselineContextSSL :: IO SSLContext
>         baselineContextSSL = do
>             ctx <- SSL.context
>             SSL.contextSetDefaultCiphers ctx
>         #if defined __MACOSX__
>             SSL.contextSetVerificationMode ctx SSL.VerifyNone
>         #elif defined __WIN32__
>             SSL.contextSetVerificationMode ctx SSL.VerifyNone
>         #else
>             SSL.contextSetCADirectory ctx "/etc/ssl/certs"
>             SSL.contextSetVerificationMode ctx $
>                 SSL.VerifyPeer True True Nothing
>         #endif
>             return ctx
> 
> all very nice (this being necessary because apparently the non-free
> operating systems don't store their certs in a reliably discoverable
> place; bummer).
> 
> That, however, is not the problem. After all, this sort of thing is
> what #ifdefs are for. The problem is needing to get an appropriate
> symbol based on what OS you're using defined.
> 
> I naively assumed there would be __LINUX__ and __MACOSX__ and
> __WIN32__ defined by GHC because, well, that's just the sort of
> wishful thinking that powers the universe.
> 
> So my question is: what's an appropriate Haskell mechanism for
> building code that is OS / arch  / distro specific? It's not like I
> have autoconf running generating me a config.h I could #include,
> right?
> 
> This feels simple and an appropriate use of CPP; even the symbol names
> look just about like what I would have expected; stackoverflow said
> so, must be true. Just need to get the right symbol defined at build
> time.
> 
> Any suggestions?
> 
> AfC
> Sydney
> 



More information about the Haskell-Cafe mailing list