diff --git a/Setup.hs b/Setup.hs
--- a/Setup.hs
+++ b/Setup.hs
@@ -1,3 +1,33 @@
+{-# LANGUAGE CPP #-}
+{-# OPTIONS_GHC -Wall #-}
+module Main (main) where
+
+#ifndef MIN_VERSION_cabal_doctest
+#define MIN_VERSION_cabal_doctest(x,y,z) 0
+#endif
+
+#if MIN_VERSION_cabal_doctest(1,0,0)
+
+import Distribution.Extra.Doctest ( defaultMainAutoconfWithDoctests )
+main :: IO ()
+main = defaultMainAutoconfWithDoctests "doctests"
+
+#else
+
+#ifdef MIN_VERSION_Cabal
+-- If the macro is defined, we have new cabal-install,
+-- but for some reason we don't have cabal-doctest in package-db
+--
+-- Probably we are running cabal sdist, when otherwise using new-build
+-- workflow
+#warning You are configuring this package without cabal-doctest installed. \
+         The doctests test-suite will not work as a result. \
+         To fix this, install cabal-doctest before configuring.
+#endif
+
 import Distribution.Simple
 
-main = defaultMainWithHooks autoconfUserHooks
+main :: IO ()
+main = defaultMain
+
+#endif
diff --git a/cbits/strftime.c b/cbits/strftime.c
--- a/cbits/strftime.c
+++ b/cbits/strftime.c
@@ -476,7 +476,7 @@
 				else
 #endif /* defined TM_ZONE */
 				if (t->tm_isdst >= 0)
-					pt = _add(tzname[t->tm_isdst != 0],
+					pt = _add(_tzname[t->tm_isdst != 0],
 						pt, ptlim);
 				/*
 				 * C99 says that %Z must be replaced by the
@@ -514,7 +514,7 @@
 				 * appropriate variables are not available.
 				 */
 				if (t->tm_isdst == 0)
-					diff = -timezone;
+					diff = -_timezone;
 				else
 #ifdef ALTZONE
 					diff = -altzone;
diff --git a/cbits/strptime.c b/cbits/strptime.c
--- a/cbits/strptime.c
+++ b/cbits/strptime.c
@@ -548,9 +548,9 @@
 				if (0 == strcmp(zonestr, "GMT") ||
 				    0 == strcmp(zonestr, "UTC")) {
 				    *GMTp = 1;
-				} else if (0 == strcmp(zonestr, tzname[0])) {
+				} else if (0 == strcmp(zonestr, _tzname[0])) {
 				    tm->tm_isdst = 0;
-				} else if (0 == strcmp(zonestr, tzname[1])) {
+				} else if (0 == strcmp(zonestr, _tzname[1])) {
 				    tm->tm_isdst = 1;
 				} else {
 				    return (NULL);
diff --git a/test/doctests.hs b/test/doctests.hs
--- a/test/doctests.hs
+++ b/test/doctests.hs
@@ -1,11 +1,12 @@
 module Main where
 
-import Test.DocTest
+import Build_doctests (flags, pkgs, module_sources)
+import Data.Foldable (traverse_)
+import Test.DocTest (doctest)
 
 main :: IO ()
-main = doctest [
-    "-XOverloadedStrings"
-  , "-idist/build"
-  , "dist/build/cbits/conv.o"
-  , "Data/UnixTime.hs"
-  ]
+main = do
+    traverse_ putStrLn args
+    doctest args
+  where
+    args = ["-XOverloadedStrings"] ++ flags ++ pkgs ++ module_sources
diff --git a/unix-time.cabal b/unix-time.cabal
--- a/unix-time.cabal
+++ b/unix-time.cabal
@@ -1,5 +1,5 @@
 Name:                   unix-time
-Version:                0.4.2
+Version:                0.4.3
 Author:                 Kazu Yamamoto <kazu@iij.ad.jp>
 Maintainer:             Kazu Yamamoto <kazu@iij.ad.jp>
 License:                BSD3
@@ -8,7 +8,7 @@
 Description:            Fast parser\/formatter\/utilities for Unix time
 Category:               Data
 Cabal-Version:          >= 1.10
-Build-Type:             Configure
+Build-Type:             Custom
 Extra-Source-Files:     cbits/config.h.in
                         cbits/conv.c
                         cbits/strftime.c
@@ -19,6 +19,9 @@
                         configure.ac
 Extra-Tmp-Files:        config.log config.status autom4te.cache cbits/config.h
 
+Custom-Setup
+  Setup-Depends:        base, Cabal, cabal-doctest >=1.0.6 && <1.1
+
 Library
   Default-Language:     Haskell2010
   GHC-Options:          -Wall
@@ -40,7 +43,7 @@
                       , cbits/win_patch.c
   include-dirs:         cbits
 
-Test-Suite doctest
+Test-Suite doctests
   Type:                 exitcode-stdio-1.0
   Default-Language:     Haskell2010
   HS-Source-Dirs:       test
@@ -48,6 +51,7 @@
   Main-Is:              doctests.hs
   Build-Depends:        base
                       , doctest >= 0.9.3
+                      , unix-time
 
 Test-Suite spec
   Type:                 exitcode-stdio-1.0
