Skip to content

Commit

Permalink
Use default Simple build type
Browse files Browse the repository at this point in the history
Merge branch 'simple' from Herbert Valerio Riedel removing need for
custom Setup.hs and replacing it with default built in compile time
defines.

Closes aesiniath#109.
  • Loading branch information
istathar committed May 7, 2018
2 parents 341335b + 9dbca1d commit ec9b58b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 77 deletions.
64 changes: 1 addition & 63 deletions Setup.hs
Original file line number Diff line number Diff line change
@@ -1,64 +1,2 @@
--
-- HTTP client for use with io-streams
--
-- Copyright © 2013 Operational Dynamics Consulting, Pty Ltd
--
-- The code in this file, and the program it is a part of, is
-- made available to you by its authors as open source software:
-- you can redistribute it and/or modify it under the terms of
-- the BSD licence.
--

import Data.Char (toUpper)
import Distribution.Text (display)
import Distribution.PackageDescription (PackageDescription(..))
import Distribution.Simple
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo)
import Distribution.Simple.Setup (ConfigFlags)
import Distribution.System (OS (..), buildOS)
import System.IO (IOMode (..), Handle, hPutStrLn, withFile)

main :: IO ()
main = defaultMainWithHooks $ simpleUserHooks {
postConf = configure
}

{-
Simple detection of which operating system we're building on;
there's no need to link the Cabal logic into our library, so
we'll keep using CPP in Network.Http.Inconvenience.
-}

configure :: Args -> ConfigFlags -> PackageDescription -> LocalBuildInfo -> IO ()
configure _ _ p _ = do

withFile "config.h" WriteMode (\h -> do
discoverOperatingSystem h
discoverLibraryVersion h p)

return ()

discoverOperatingSystem :: Handle -> IO ()
discoverOperatingSystem h = do
hPutStrLn h ("#define " ++ s)

where
o = buildOS

s = case o of
Linux -> "__LINUX__"
OSX -> "__MACOSX__"
Windows -> "__WINDOWS__"
_ -> "__" ++ up o ++ "__"

up x = map toUpper (show x)

discoverLibraryVersion :: Handle -> PackageDescription -> IO ()
discoverLibraryVersion h p = do
hPutStrLn h ("#define VERSION \"http-streams/" ++ s ++ "\"")

where
i = package p
v = pkgVersion i
s = display v

main = defaultMain
8 changes: 2 additions & 6 deletions http-streams.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 1.24
name: http-streams
version: 0.8.6.1
version: 0.8.6.2
synopsis: An HTTP client using io-streams
description:
/Overview/
Expand Down Expand Up @@ -38,11 +38,7 @@ extra-source-files: README.markdown CHANGELOG.markdown
tests/hello.txt
tests/hello.html

build-type: Custom

custom-setup
setup-depends: base >= 4.5,
Cabal >= 1.24
build-type: Simple

flag network-uri
description: Get Network.URI from the network-uri package
Expand Down
15 changes: 7 additions & 8 deletions lib/Network/Http/Inconvenience.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ module Network.Http.Inconvenience (
splitURI
) where

#include "config.h"

import Blaze.ByteString.Builder (Builder)
import qualified Blaze.ByteString.Builder as Builder (fromByteString,
fromWord8, toByteString)
Expand Down Expand Up @@ -77,11 +75,12 @@ import Network.Http.Connection
import Network.Http.RequestBuilder
import Network.Http.Types

#if defined __LINUX__ || defined __FREEBSD__
-- (see also http://downloads.haskell.org/~ghc/8.4.2/docs/html/users_guide/phases.html#standard-cpp-macros
-- for a list of predefined CPP macros provided by GHC and/or Cabal; see also the cabal user's guide)
#if defined(linux_HOST_OS) || defined(freebsd_HOST_OS)
import System.Directory (doesDirectoryExist)
#endif


type URL = ByteString

------------------------------------------------------------------------------
Expand Down Expand Up @@ -238,14 +237,14 @@ baselineContextSSL :: IO SSLContext
baselineContextSSL = withOpenSSL $ do
ctx <- SSL.context
SSL.contextSetDefaultCiphers ctx
#if defined __MACOSX__
#if defined(darwin_HOST_OS)
SSL.contextSetVerificationMode ctx SSL.VerifyNone
#elif defined __WINDOWS__
#elif defined(mingw32_HOST_OS)
SSL.contextSetVerificationMode ctx SSL.VerifyNone
#elif defined __FREEBSD__
#elif defined(freebsd_HOST_OS)
SSL.contextSetCAFile ctx "/usr/local/etc/ssl/cert.pem"
SSL.contextSetVerificationMode ctx $ SSL.VerifyPeer True True Nothing
#elif defined __OPENBSD__
#elif defined(openbsd_HOST_OS)
SSL.contextSetCAFile ctx "/etc/ssl/cert.pem"
SSL.contextSetVerificationMode ctx $ SSL.VerifyPeer True True Nothing
#else
Expand Down

0 comments on commit ec9b58b

Please sign in to comment.