diff --git a/.gitignore b/.gitignore
index d3ca28b8a4f2c9e6954db9855f56f364a4cc0a4f..6b8d26e0f4740ba2fd59635182e7e16f82dbadad 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
 /dist/
-/haddock-library/dist
+/haddock-api/dist/
+/haddock-library/dist/
 /html-test/out/
 /latex-test/out/
 
diff --git a/.travis.yml b/.travis.yml
index 338d394d3f167f5cf2a090fca74dcfaf2b1588bc..9872092017b5972b0be968bb0c3e143b45bd764f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -15,6 +15,7 @@ before_install:
  - doctest -isrc -i$(echo vendor/attoparsec-*) -optP-include -optPdist/build/autogen/cabal_macros.h src/Documentation/Haddock/Parser.hs
  - cabal install
  - cd ..
+ - (cd haddock-api/ && cabal configure --enable-tests --ghc-options=-Werror && cabal build && cabal test && cabal install)
 
 script:
  - cabal configure --enable-tests --ghc-options=-Werror && cabal build && cabal test
diff --git a/LICENSE b/LICENSE
index 1636bfcd30709373c2842cb05bb945667241290c..460decfca1699ec8280bd32e785375943a7bb224 100644
--- a/LICENSE
+++ b/LICENSE
@@ -5,11 +5,11 @@ modification, are permitted provided that the following conditions are met:
 
 - Redistributions of source code must retain the above copyright notice,
 this list of conditions and the following disclaimer.
- 
+
 - Redistributions in binary form must reproduce the above copyright notice,
 this list of conditions and the following disclaimer in the documentation
 and/or other materials provided with the distribution.
- 
+
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY
 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
diff --git a/haddock-api/LICENSE b/haddock-api/LICENSE
new file mode 100644
index 0000000000000000000000000000000000000000..460decfca1699ec8280bd32e785375943a7bb224
--- /dev/null
+++ b/haddock-api/LICENSE
@@ -0,0 +1,23 @@
+Copyright 2002-2010, Simon Marlow.  All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+
+- Redistributions in binary form must reproduce the above copyright notice,
+this list of conditions and the following disclaimer in the documentation
+and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/haddock-api/Setup.lhs b/haddock-api/Setup.lhs
new file mode 100755
index 0000000000000000000000000000000000000000..5bde0de962274e26328ecffabb4e9f6430a10cc9
--- /dev/null
+++ b/haddock-api/Setup.lhs
@@ -0,0 +1,3 @@
+#!/usr/bin/env runhaskell
+> import Distribution.Simple
+> main = defaultMain
diff --git a/haddock-api/haddock-api.cabal b/haddock-api/haddock-api.cabal
new file mode 100644
index 0000000000000000000000000000000000000000..c40edb1416bafb2c7612dcb600fada58f9da42d0
--- /dev/null
+++ b/haddock-api/haddock-api.cabal
@@ -0,0 +1,94 @@
+name:                 haddock-api
+version:              2.14.4
+synopsis:             A documentation-generation tool for Haskell libraries
+description:          Haddock is a documentation-generation tool for Haskell
+                      libraries
+license:              BSD3
+license-file:         LICENSE
+author:               Simon Marlow, David Waern
+maintainer:           Simon Hengel <sol@typeful.net>, Mateusz Kowalczyk <fuuzetsu@fuuzetsu.co.uk>
+homepage:             http://www.haskell.org/haddock/
+bug-reports:          https://github.com/haskell/haddock/issues
+copyright:            (c) Simon Marlow, David Waern
+category:             Documentation
+build-type:           Simple
+cabal-version:        >= 1.10
+stability:            experimental
+
+data-dir:
+  resources
+data-files:
+  html/frames.html
+  html/haddock-util.js
+  html/Classic.theme/haskell_icon.gif
+  html/Classic.theme/minus.gif
+  html/Classic.theme/plus.gif
+  html/Classic.theme/xhaddock.css
+  html/Ocean.std-theme/hslogo-16.png
+  html/Ocean.std-theme/minus.gif
+  html/Ocean.std-theme/ocean.css
+  html/Ocean.std-theme/plus.gif
+  html/Ocean.std-theme/synopsis.png
+  latex/haddock.sty
+
+library
+  default-language:
+      Haskell2010
+
+  build-depends:
+      base >= 4.3 && < 4.8
+    , bytestring
+    , filepath
+    , directory
+    , containers
+    , deepseq
+    , array
+    , xhtml >= 3000.2 && < 3000.3
+    , Cabal >= 1.10
+    , ghc == 7.8.3
+
+    , ghc-paths
+    , haddock-library
+
+  hs-source-dirs:
+      src
+
+  ghc-options: -funbox-strict-fields -Wall -fwarn-tabs -O2
+
+  exposed-modules:
+    Documentation.Haddock
+
+  other-modules:
+    Haddock
+    Haddock.Interface
+    Haddock.Interface.Rename
+    Haddock.Interface.Create
+    Haddock.Interface.AttachInstances
+    Haddock.Interface.LexParseRn
+    Haddock.Interface.ParseModuleHeader
+    Haddock.Parser
+    Haddock.Utils
+    Haddock.Backends.Xhtml
+    Haddock.Backends.Xhtml.Decl
+    Haddock.Backends.Xhtml.DocMarkup
+    Haddock.Backends.Xhtml.Layout
+    Haddock.Backends.Xhtml.Names
+    Haddock.Backends.Xhtml.Themes
+    Haddock.Backends.Xhtml.Types
+    Haddock.Backends.Xhtml.Utils
+    Haddock.Backends.LaTeX
+    Haddock.Backends.HaddockDB
+    Haddock.Backends.Hoogle
+    Haddock.ModuleTree
+    Haddock.Types
+    Haddock.Doc
+    Haddock.Version
+    Haddock.InterfaceFile
+    Haddock.Options
+    Haddock.GhcUtils
+    Haddock.Convert
+    Paths_haddock_api
+
+source-repository head
+  type:     git
+  location: https://github.com/haskell/haddock.git
diff --git a/resources/html/Classic.theme/haskell_icon.gif b/haddock-api/resources/html/Classic.theme/haskell_icon.gif
similarity index 100%
rename from resources/html/Classic.theme/haskell_icon.gif
rename to haddock-api/resources/html/Classic.theme/haskell_icon.gif
diff --git a/resources/html/Classic.theme/minus.gif b/haddock-api/resources/html/Classic.theme/minus.gif
similarity index 100%
rename from resources/html/Classic.theme/minus.gif
rename to haddock-api/resources/html/Classic.theme/minus.gif
diff --git a/resources/html/Classic.theme/plus.gif b/haddock-api/resources/html/Classic.theme/plus.gif
similarity index 100%
rename from resources/html/Classic.theme/plus.gif
rename to haddock-api/resources/html/Classic.theme/plus.gif
diff --git a/resources/html/Classic.theme/xhaddock.css b/haddock-api/resources/html/Classic.theme/xhaddock.css
similarity index 100%
rename from resources/html/Classic.theme/xhaddock.css
rename to haddock-api/resources/html/Classic.theme/xhaddock.css
diff --git a/resources/html/Ocean.std-theme/hslogo-16.png b/haddock-api/resources/html/Ocean.std-theme/hslogo-16.png
similarity index 100%
rename from resources/html/Ocean.std-theme/hslogo-16.png
rename to haddock-api/resources/html/Ocean.std-theme/hslogo-16.png
diff --git a/resources/html/Ocean.std-theme/minus.gif b/haddock-api/resources/html/Ocean.std-theme/minus.gif
similarity index 100%
rename from resources/html/Ocean.std-theme/minus.gif
rename to haddock-api/resources/html/Ocean.std-theme/minus.gif
diff --git a/resources/html/Ocean.std-theme/ocean.css b/haddock-api/resources/html/Ocean.std-theme/ocean.css
similarity index 100%
rename from resources/html/Ocean.std-theme/ocean.css
rename to haddock-api/resources/html/Ocean.std-theme/ocean.css
diff --git a/resources/html/Ocean.std-theme/plus.gif b/haddock-api/resources/html/Ocean.std-theme/plus.gif
similarity index 100%
rename from resources/html/Ocean.std-theme/plus.gif
rename to haddock-api/resources/html/Ocean.std-theme/plus.gif
diff --git a/resources/html/Ocean.std-theme/synopsis.png b/haddock-api/resources/html/Ocean.std-theme/synopsis.png
similarity index 100%
rename from resources/html/Ocean.std-theme/synopsis.png
rename to haddock-api/resources/html/Ocean.std-theme/synopsis.png
diff --git a/resources/html/frames.html b/haddock-api/resources/html/frames.html
similarity index 100%
rename from resources/html/frames.html
rename to haddock-api/resources/html/frames.html
diff --git a/resources/html/haddock-util.js b/haddock-api/resources/html/haddock-util.js
similarity index 100%
rename from resources/html/haddock-util.js
rename to haddock-api/resources/html/haddock-util.js
diff --git a/resources/latex/haddock.sty b/haddock-api/resources/latex/haddock.sty
similarity index 100%
rename from resources/latex/haddock.sty
rename to haddock-api/resources/latex/haddock.sty
diff --git a/haddock-api/src b/haddock-api/src
new file mode 120000
index 0000000000000000000000000000000000000000..e057607ed009d665f88b468cb77342491ad71d82
--- /dev/null
+++ b/haddock-api/src
@@ -0,0 +1 @@
+../src/
\ No newline at end of file
diff --git a/haddock.cabal b/haddock.cabal
index 7e3fa0e219e55eba06c9586c9f3eecb69f1eb4d8..57f6d15ce35b5efbdd388fd9db291c52706b9d48 100644
--- a/haddock.cabal
+++ b/haddock.cabal
@@ -35,45 +35,21 @@ extra-source-files:
   latex-test/ref/Simple/*.tex
   latex-test/ref/Simple/*.sty
 
-data-dir:   resources
-data-files: html/frames.html
-            html/haddock-util.js
-            html/Classic.theme/haskell_icon.gif
-            html/Classic.theme/minus.gif
-            html/Classic.theme/plus.gif
-            html/Classic.theme/xhaddock.css
-            html/Ocean.std-theme/hslogo-16.png
-            html/Ocean.std-theme/minus.gif
-            html/Ocean.std-theme/ocean.css
-            html/Ocean.std-theme/plus.gif
-            html/Ocean.std-theme/synopsis.png
-            latex/haddock.sty
-
 flag in-ghc-tree
   description: Are we in a GHC tree?
   default: False
   manual: True
 
--- Using this disables -O2, and hence allows to use --disable-optimization,
--- which is about twice as fast.  This should probably be the default, but we
--- need some benchmarks first..
-flag dev
-  default: False
-  manual: True
-
 executable haddock
   default-language:     Haskell2010
   main-is:              Main.hs
   hs-source-dirs:       driver
-  if flag(dev)
-    ghc-options:          -funbox-strict-fields -Wall -fwarn-tabs
-  else
-    ghc-options:          -funbox-strict-fields -Wall -fwarn-tabs -O2
+  ghc-options:          -funbox-strict-fields -Wall -fwarn-tabs -O2
 
   build-depends:
     base >= 4.3 && < 4.8
   if flag(in-ghc-tree)
-    hs-source-dirs: src, haddock-library/vendor/attoparsec-0.12.1.1, haddock-library/src
+    hs-source-dirs: haddock-api/src, haddock-library/vendor/attoparsec-0.12.1.1, haddock-library/src
     cpp-options: -DIN_GHC_TREE
     build-depends:
       filepath,
@@ -134,93 +110,7 @@ executable haddock
       Haddock.GhcUtils
       Haddock.Convert
   else
-    build-depends:  haddock, haddock-library
-
-library
-  default-language:     Haskell2010
-
-  build-depends:
-    base >= 4.3 && < 4.8,
-    bytestring,
-    filepath,
-    directory,
-    containers,
-    deepseq,
-    array,
-    xhtml >= 3000.2 && < 3000.3,
-    Cabal >= 1.10,
-    ghc == 7.8.3
-
-  if flag(in-ghc-tree)
-    cpp-options: -DIN_GHC_TREE
-    hs-source-dirs:       src, haddock-library/vendor/attoparsec-0.12.1.1, haddock-library/src
-
-    exposed-modules:
-      Documentation.Haddock.Parser
-      Documentation.Haddock.Types
-      Documentation.Haddock.Doc
-
-    other-modules:
-      Data.Attoparsec
-      Data.Attoparsec.ByteString
-      Data.Attoparsec.ByteString.Buffer
-      Data.Attoparsec.ByteString.Char8
-      Data.Attoparsec.ByteString.FastSet
-      Data.Attoparsec.ByteString.Internal
-      Data.Attoparsec.Combinator
-      Data.Attoparsec.Internal
-      Data.Attoparsec.Internal.Fhthagn
-      Data.Attoparsec.Internal.Types
-      Data.Attoparsec.Number
-      Documentation.Haddock.Utf8
-      Documentation.Haddock.Parser.Util
-
-  else
-    build-depends: ghc-paths, haddock-library
-    hs-source-dirs:       src
-
-
-  if flag(dev)
-    ghc-options:          -funbox-strict-fields -Wall -fwarn-tabs
-  else
-    ghc-options:          -funbox-strict-fields -Wall -fwarn-tabs -O2
-
-  exposed-modules:
-    Documentation.Haddock
-
-  other-modules:
-    Haddock
-    Haddock.Interface
-    Haddock.Interface.Rename
-    Haddock.Interface.Create
-    Haddock.Interface.AttachInstances
-    Haddock.Interface.LexParseRn
-    Haddock.Interface.ParseModuleHeader
-    Haddock.Parser
-    Haddock.Utils
-    Haddock.Backends.Xhtml
-    Haddock.Backends.Xhtml.Decl
-    Haddock.Backends.Xhtml.DocMarkup
-    Haddock.Backends.Xhtml.Layout
-    Haddock.Backends.Xhtml.Names
-    Haddock.Backends.Xhtml.Themes
-    Haddock.Backends.Xhtml.Types
-    Haddock.Backends.Xhtml.Utils
-    Haddock.Backends.LaTeX
-    Haddock.Backends.HaddockDB
-    Haddock.Backends.Hoogle
-    Haddock.ModuleTree
-    Haddock.Types
-    Haddock.Doc
-    Haddock.Version
-    Haddock.InterfaceFile
-    Haddock.Options
-    Haddock.GhcUtils
-    Haddock.Convert
-    Paths_haddock
-
-  if flag(in-ghc-tree)
-    buildable: False
+    build-depends:  haddock-api, haddock-library
 
 test-suite html-test
   type:             exitcode-stdio-1.0
diff --git a/src/Haddock.hs b/src/Haddock.hs
index 3d049b18ed92b434d592b80c7e8c058bfcb970be..ad78c50dc4814b5e1e5573c74d2be2f12eb359f0 100644
--- a/src/Haddock.hs
+++ b/src/Haddock.hs
@@ -19,7 +19,6 @@
 -----------------------------------------------------------------------------
 module Haddock (haddock, readPackagesAndProcessModules, withGhc') where
 
-
 import Haddock.Backends.Xhtml
 import Haddock.Backends.Xhtml.Themes (getThemes)
 import Haddock.Backends.LaTeX
@@ -54,7 +53,7 @@ import Data.Int
 import System.FilePath
 #else
 import qualified GHC.Paths as GhcPaths
-import Paths_haddock
+import Paths_haddock_api (getDataDir)
 #endif
 
 import GHC hiding (verbosity)
diff --git a/src/Haddock/Version.hs b/src/Haddock/Version.hs
index f4729c7d3d33ff51a89a0ce81cbd80f68ba7066d..2ef3a25716510cd259b252055bdd7fcd78b1774e 100644
--- a/src/Haddock/Version.hs
+++ b/src/Haddock/Version.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE CPP #-}
 -----------------------------------------------------------------------------
 -- |
 -- Module      :  Haddock.Version
@@ -12,11 +13,17 @@ module Haddock.Version (
   projectName, projectVersion, projectUrl
 ) where
 
+#ifdef IN_GHC_TREE
 import Paths_haddock ( version )
+#else
+import Paths_haddock_api ( version )
+#endif
 import Data.Version  ( showVersion )
 
-projectName, projectUrl :: String
+projectName :: String
 projectName = "Haddock"
+
+projectUrl :: String
 projectUrl  = "http://www.haskell.org/haddock/"
 
 projectVersion :: String