forked from aesiniath/http-streams
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
3 changed files
with
10 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters