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

Krzysztof Skrzętnicki gtener at gmail.com
Fri Feb 15 15:16:39 CET 2013

Well, for sure you can in define that in .cabal file:

    if !os(windows)
      CC-Options: "-DWINDOWS"

or something. See:

On Fri, Feb 15, 2013 at 3:05 PM, 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
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130215/1fd71699/attachment.htm>

More information about the Haskell-Cafe mailing list