From 8d398ecf6eefdee316f7108a0c6f1d3e51a42b62 Mon Sep 17 00:00:00 2001 From: Herbert Valerio Riedel Date: Thu, 3 May 2018 08:59:23 +0200 Subject: [PATCH] Convert to build-type:Simple package --- Setup.hs | 64 +------------------------------ http-streams.cabal | 8 +--- lib/Network/Http/Inconvenience.hs | 15 ++++---- 3 files changed, 10 insertions(+), 77 deletions(-) diff --git a/Setup.hs b/Setup.hs index d7cb73e..9a994af 100644 --- a/Setup.hs +++ b/Setup.hs @@ -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 diff --git a/http-streams.cabal b/http-streams.cabal index b72a27e..6372131 100644 --- a/http-streams.cabal +++ b/http-streams.cabal @@ -1,4 +1,4 @@ -cabal-version: >= 1.24 +cabal-version: 1.12 name: http-streams version: 0.8.6.1 synopsis: An HTTP client using io-streams @@ -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 diff --git a/lib/Network/Http/Inconvenience.hs b/lib/Network/Http/Inconvenience.hs index 2a70d7f..348599d 100644 --- a/lib/Network/Http/Inconvenience.hs +++ b/lib/Network/Http/Inconvenience.hs @@ -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) @@ -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 ------------------------------------------------------------------------------ @@ -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