forked from aesiniath/http-streams
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Setup.hs
64 lines (51 loc) · 1.75 KB
/
Setup.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
--
-- 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