diff --git a/Setup.hs b/Setup.hs
--- a/Setup.hs
+++ b/Setup.hs
@@ -1,4 +1,85 @@
+{-|
+Module      : Main
+Description : Setup script for hgeos build
+Copyright   : (C) Richard Cook, 2016
+Licence     : MIT
+Maintainer  : rcook@rcook.org
+Stability   : experimental
+Portability : portable
+-}
+
+{-# LANGUAGE CPP #-}
+
+module Main (main) where
+
+#ifdef mingw32_HOST_OS
+
+import Data.List
+import Distribution.PackageDescription
 import Distribution.Simple
+import Distribution.Simple.LocalBuildInfo
+import Distribution.Simple.Setup
+import System.Directory
+import System.FilePath
 
+testPrefix :: String
+testPrefix = "test:"
+
+dllName :: String
+dllName = "geos_c.dll"
+
 main :: IO ()
+main = defaultMainWithHooks hgeosHooks
+
+hgeosHooks :: UserHooks
+hgeosHooks = simpleUserHooks
+    { confHook = hgeosConfHook
+    , postBuild = hgeosPostBuild
+    }
+
+hgeosConfHook :: (GenericPackageDescription, HookedBuildInfo) -> ConfigFlags -> IO LocalBuildInfo
+hgeosConfHook (description, buildInfo) flags = do
+    localBuildInfo <- confHook simpleUserHooks (description, buildInfo) flags
+    let packageDescription = localPkgDescr localBuildInfo
+        Just packageLibrary = library packageDescription
+        libraryBuildInfo = libBuildInfo packageLibrary
+
+    dir <- getCurrentDirectory
+    let externalDir = dir </> "external"
+        geosPackageDir = externalDir </> "geos"
+        geosIncludeDir = geosPackageDir </> "include"
+        geosLibDir = geosPackageDir </> "lib"
+
+    return localBuildInfo {
+        localPkgDescr = packageDescription {
+            library = Just $ packageLibrary {
+                libBuildInfo = libraryBuildInfo {
+                    includeDirs = geosIncludeDir : includeDirs libraryBuildInfo,
+                    extraLibDirs = geosLibDir : extraLibDirs libraryBuildInfo
+                }
+            }
+        }
+    }
+
+hgeosPostBuild :: Args -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
+hgeosPostBuild args buildFlags _ _ = do
+    case find (testPrefix `isPrefixOf`) args of
+         Nothing -> return ()
+         Just testArg -> do
+                dir <- getCurrentDirectory
+                let testName = drop (length testPrefix) testArg
+                    distDir = dir </> (fromFlag $ buildDistPref buildFlags)
+                    buildDir = distDir </> "build"
+                    testDLLPath = buildDir </> testName </> dllName
+                    geosDLLPath = dir </> "external" </> "geos" </> "bin" </> dllName
+                copyFile geosDLLPath testDLLPath
+                return ()
+
+#else
+
+import Distribution.Simple
+
+main :: IO ()
 main = defaultMain
+
+#endif
diff --git a/hgeos.cabal b/hgeos.cabal
--- a/hgeos.cabal
+++ b/hgeos.cabal
@@ -1,5 +1,5 @@
 name:                 hgeos
-version:              0.1.5.0
+version:              0.1.5.1
 synopsis:             Simple Haskell bindings to GEOS C API
 description:
   Simple Haskell bindings to the <https://trac.osgeo.org/geos/ GEOS>
@@ -13,7 +13,7 @@
 maintainer:           Richard Cook <rcook@rcook.org>
 copyright:            (C) 2016 Richard Cook
 category:             Data, Geography, Geometry, Text
-build-type:           Simple
+build-type:           Custom
 cabal-version:        >= 1.10
 data-files:           data/namibia.wkt
 
@@ -28,14 +28,10 @@
                     , transformers
   extra-libraries:    geos_c
   c-sources:          src/lib/Data/Geolocation/GEOS/helpers.c
-                    , src/lib/Data/Geolocation/GEOS/helpers.h
   cc-options:         -std=c99 -pthread
   exposed-modules:    Data.Geolocation.GEOS
                     , Data.Geolocation.GEOS.Imports
                     , Data.Geolocation.GEOS.Trans
-  if os(windows)
-    include-dirs:     C:/OSGeo4W64/include
-    extra-lib-dirs:   C:/OSGeo4W64/lib
 
 test-suite hgeos-app
   type:               exitcode-stdio-1.0
diff --git a/src/lib/Data/Geolocation/GEOS.hs b/src/lib/Data/Geolocation/GEOS.hs
--- a/src/lib/Data/Geolocation/GEOS.hs
+++ b/src/lib/Data/Geolocation/GEOS.hs
@@ -5,7 +5,7 @@
 Licence     : MIT
 Maintainer  : rcook@rcook.org
 Stability   : experimental
-Portability : POSIX
+Portability : portable
 
 A high-level API for interoperating with GEOS C API which includes automatic
 management of lifetimes of objects such as readers, writers and geometries.
diff --git a/src/lib/Data/Geolocation/GEOS/Imports.hs b/src/lib/Data/Geolocation/GEOS/Imports.hs
--- a/src/lib/Data/Geolocation/GEOS/Imports.hs
+++ b/src/lib/Data/Geolocation/GEOS/Imports.hs
@@ -5,7 +5,7 @@
 Licence     : MIT
 Maintainer  : rcook@rcook.org
 Stability   : experimental
-Portability : POSIX
+Portability : portable
 
 These are low-level FFI bindings for the GEOS C API derived from
 <http://geos.osgeo.org/doxygen/geos__c_8h_source.html geos_c.h>. These enable
diff --git a/src/lib/Data/Geolocation/GEOS/Trans.hs b/src/lib/Data/Geolocation/GEOS/Trans.hs
--- a/src/lib/Data/Geolocation/GEOS/Trans.hs
+++ b/src/lib/Data/Geolocation/GEOS/Trans.hs
@@ -5,7 +5,7 @@
 Licence     : MIT
 Maintainer  : rcook@rcook.org
 Stability   : experimental
-Portability : POSIX
+Portability : portable
 
 These are @MaybeT@ monad transformer wrapper functions for the high-level API
 to simplify error handling in client code.
diff --git a/src/lib/Data/Geolocation/GEOS/helpers.h b/src/lib/Data/Geolocation/GEOS/helpers.h
deleted file mode 100644
--- a/src/lib/Data/Geolocation/GEOS/helpers.h
+++ /dev/null
@@ -1,7 +0,0 @@
-#pragma once
-
-#include "geos_c.h"
-
-GEOSContextHandle_t initializeGEOSWithHandlers();
-const char* getNoticeMessage();
-const char* getErrorMessage();
