diff --git a/ChangeLog b/ChangeLog
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2017-04-05  Vladimir Shabanov  <vshabanoff@gmail.com>
+
+	* HsOpenSSL.cabal (Version): Bump version to 0.11.4.6
+
+	* Setup.hs: builds with ghc 8.2,
+	by Erik de Castro Lopo @erikd (#22)
+
 2017-04-04  Vladimir Shabanov  <vshabanoff@gmail.com>
 
 	* HsOpenSSL.cabal (Version): Bump version to 0.11.4.5
diff --git a/HsOpenSSL.cabal b/HsOpenSSL.cabal
--- a/HsOpenSSL.cabal
+++ b/HsOpenSSL.cabal
@@ -12,7 +12,7 @@
     <http://hackage.haskell.org/package/tls>, which is a pure Haskell
     implementation of SSL.
     .
-Version:       0.11.4.5
+Version:       0.11.4.6
 License:       PublicDomain
 License-File:  COPYING
 Author:        Adam Langley, Mikhail Vorozhtsov, PHO, Taru Karttunen
@@ -66,7 +66,7 @@
         base       >= 4.4 && < 5,
         bytestring >= 0.9   && < 0.11,
         network    >= 2.1   && < 2.7,
-        time       >= 1.5   && < 1.7
+        time       >= 1.5   && < 1.9
 
     if flag(fast-bignum) && impl(ghc >= 7.10.1)
         -- only new integer-gmp 1.0.0 is supported
diff --git a/Setup.hs b/Setup.hs
--- a/Setup.hs
+++ b/Setup.hs
@@ -1,11 +1,16 @@
-#!/usr/bin/env runghc
-
+{-# LANGUAGE CPP #-}
 {-# LANGUAGE TupleSections #-}
 
 import Distribution.Simple
 import Distribution.Simple.Setup (ConfigFlags(..), toFlag)
 import Distribution.Simple.LocalBuildInfo (localPkgDescr)
+
+#if __GLASGOW_HASKELL__ >= 802
+import Distribution.PackageDescription (FlagName(..), mkFlagName)
+#else
 import Distribution.PackageDescription (FlagName(..))
+#endif
+
 import Distribution.Verbosity (silent)
 import System.Info (os)
 import qualified Control.Exception as E (tryJust, throw)
@@ -36,13 +41,13 @@
         Right lbi -> return lbi -- library was found
         Left e
             | configConfigurationsFlags cfg
-              `intersect` [(FlagName f, True) | f <- flags] /= [] ->
+              `intersect` [(mkFlagName f, True) | f <- flags] /= [] ->
                 E.throw e
                 -- flag was set but library still wasn't found
             | otherwise -> do
                 r <- forM flags $ \ f ->
                     fmap (f,) $ tryConfig descr $
-                    setFlag f cfg { configVerbosity = toFlag silent }
+                    setFlag (mkFlagName f) cfg { configVerbosity = toFlag silent }
                     -- TODO: configure is a long operation
                     -- while checkForeignDeps is fast.
                     -- Perhaps there is a way to configure once
@@ -57,21 +62,23 @@
                     fs ->
                         fail $ multipleFound fs
 
-notFound =
-    "Can't find OpenSSL library,\n\
-    \install it via 'brew install openssl' or 'port install openssl'\n\
-    \or use --extra-include-dirs= and --extra-lib-dirs=\n\
-    \to specify location of installed OpenSSL library."
+notFound = unlines
+    [ "Can't find OpenSSL library,"
+    , "install it via 'brew install openssl' or 'port install openssl'"
+    , "or use --extra-include-dirs= and --extra-lib-dirs="
+    , "to specify location of installed OpenSSL library."
+    ]
 
-multipleFound fs =
-    "Multiple OpenSSL libraries were found,\n\
-    \use " ++ intercalate " or " ["'-f " ++ f ++ "'" | (f,_) <- fs] ++ "\n\
-    \to specify location of installed OpenSSL library."
+multipleFound fs = unlines
+    [ "Multiple OpenSSL libraries were found,"
+    , "use " ++ intercalate " or " ["'-f " ++ f ++ "'" | (f,_) <- fs]
+    , "to specify location of installed OpenSSL library."
+    ]
 
 setFlag f c = c { configConfigurationsFlags = go (configConfigurationsFlags c) }
     where go [] = []
-          go (x@(FlagName n, _):xs)
-              | n == f = (FlagName f, True) : xs
+          go (x@(n, _):xs)
+              | n == f = (f, True) : xs
               | otherwise = x : go xs
 
 tryConfig descr flags = do
@@ -90,3 +97,8 @@
 
     where ue e | isUserError e = Just e
                | otherwise = Nothing
+
+#if __GLASGOW_HASKELL__ < 802
+mkFlagName = FlagName
+#endif
+
