diff --git a/LICENSE b/LICENSE
new file mode 100644
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,30 @@
+Copyright Henning Thielemann 2014
+
+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.
+
+    * Neither the name of Henning Thielemann nor the names of other
+      contributors may be used to endorse or promote products derived
+      from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"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
+OWNER OR CONTRIBUTORS 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/Setup.hs b/Setup.hs
new file mode 100644
--- /dev/null
+++ b/Setup.hs
@@ -0,0 +1,3 @@
+#!/usr/bin/env runhaskell
+import Distribution.Simple
+main = defaultMain
diff --git a/llvm-pkg-config.cabal b/llvm-pkg-config.cabal
new file mode 100644
--- /dev/null
+++ b/llvm-pkg-config.cabal
@@ -0,0 +1,62 @@
+Name:                llvm-pkg-config
+Version:             0.0
+Synopsis:            Generate Pkg-Config configuration file for LLVM
+Description:
+  Building the @llvm-base@ package is fragile due to its configuration process.
+  It would be much simpler, if LLVM would support pkg-config
+  since this is nicely integrated in Cabal.
+  However, LLVM developers do not seem to care much about it:
+  <http://llvm.org/bugs/show_bug.cgi?id=9405>.
+  If we are lucky we get pkg-config support in Debian Linux.
+  Until this comes true, you can use this program.
+  It calls @llvm-config@ and writes its output to a PC file.
+  .
+  > llvm-pkg-config
+  .
+  calls default @llvm-config@ and writes the generated file to standard output.
+  .
+  > sudo llvm-pkg-config --install
+  .
+  installs the PC file at a default location.
+  This should be the standard task to perform.
+  .
+  > llvm-pkg-config --llvm-config=/custom/path/to/llvm-config
+  .
+  if you have multiple versions of LLVM installed
+  you may choose an @llvm-config@ other than the default one.
+License:             BSD3
+License-file:        LICENSE
+Author:              Henning Thielemann
+Maintainer:          llvm@henning-thielemann.de
+Stability:           Stable
+Tested-With:         GHC==7.4.1, GHC==7.8.1
+Category:            Code Generation
+Build-type:          Simple
+Cabal-version:       >=1.6
+Data-Files:
+  make-pkg-config.sh
+
+Source-Repository this
+  Tag:         0.0
+  Type:        darcs
+  Location:    http://code.haskell.org/~thielema/llvm-pkg-config/
+
+Source-Repository head
+  Type:        darcs
+  Location:    http://code.haskell.org/~thielema/llvm-pkg-config/
+
+
+Executable llvm-pkg-config
+  Main-is: Main.hs
+  Other-Modules:
+    Options
+    Utility
+  Hs-Source-Dirs: src
+  GHC-Options: -Wall -threaded
+  Build-depends:
+    Cabal >=1.14 && <1.20,
+    process >=1.0 && <1.3,
+    explicit-exception >=0.1.7 && <0.2,
+    transformers >=0.2.2 && <0.4,
+    utility-ht >=0.0.8 && <0.1,
+    base >=4.2 && <5
diff --git a/make-pkg-config.sh b/make-pkg-config.sh
new file mode 100644
--- /dev/null
+++ b/make-pkg-config.sh
@@ -0,0 +1,23 @@
+version=$(llvm-config --version)
+
+echo Name: LLVM
+echo Description: Low-level Virtual Machine compiler framework
+# We keep the initial numeric part of a version number.
+# I.e. a suffix like 'svn' or 'rc' will be removed.
+# This way Cabal can match on version ranges.
+echo Version: $(echo ${version} | sed 's/\([0-9.]\+\).*/\1/')
+echo URL: http://www.llvm.org/
+echo Requires:
+echo Conflicts:
+echo Libs: -L$(llvm-config --libdir) -lLLVM-${version}
+echo Cflags: -I$(llvm-config --includedir)
+
+# This emits -fPIC flag which lets ghci fail with
+#   unknown symbol `DW.ref.__gxx_personality_v0'
+# echo Cflags: $(llvm-config --cflags)
+
+# echo Libs.private: $(llvm-config --ldflags)
+# echo Libs: $(llvm-config --libs)
+# echo Libs: -L$(llvm-config --libdir)
+# echo Libs: $(for dir in $(llvm-config --libdirs); do echo -L$dir; done)
+# echo Libs.private: -lm
diff --git a/src/Main.hs b/src/Main.hs
new file mode 100644
--- /dev/null
+++ b/src/Main.hs
@@ -0,0 +1,51 @@
+module Main (main) where
+
+import qualified Options
+import Utility (exitFailureMsg, )
+
+import qualified System.Process as Proc
+import Distribution.Simple.Utils (setFileOrdinary, )
+
+import qualified Data.List.HT as ListHT
+import qualified Data.Char as Char
+import Text.Printf (printf, )
+
+import qualified Control.Monad.Exception.Synchronous as Exc
+import qualified Control.Monad.Trans.Class as MT
+
+
+callLLVMConfig :: Options.T -> String -> IO String
+callLLVMConfig flags arg =
+   fmap (ListHT.dropWhileRev Char.isSpace) $
+   Proc.readProcess (Options.llvmConfigPath flags) [arg] ""
+
+createPkgConfig :: Options.T -> IO String
+createPkgConfig flags = do
+   fullVersion <- callLLVMConfig flags "--version"
+   let version = takeWhile (\c -> Char.isDigit c || c=='.') fullVersion
+   libdir <- callLLVMConfig flags "--libdir"
+   includedir <- callLLVMConfig flags "--includedir"
+   return $ unlines $
+      "Name: LLVM" :
+      "Description: Low-level Virtual Machine compiler framework" :
+      printf "Version: %s" version :
+      "URL: http://www.llvm.org/" :
+      "Requires:" :
+      "Conflicts:" :
+      printf "Libs: -L%s -lLLVM-%s" libdir version :
+      printf "Cflags: -I%s" includedir :
+      []
+
+run :: Options.T -> IO ()
+run flags = do
+   content <- createPkgConfig flags
+   if Options.install flags
+     then
+        let path = Options.installPath flags
+        in  writeFile path content >> setFileOrdinary path
+     else putStr content
+
+main :: IO ()
+main =
+   Exc.resolveT exitFailureMsg $
+      MT.lift . run =<< Options.get
diff --git a/src/Options.hs b/src/Options.hs
new file mode 100644
--- /dev/null
+++ b/src/Options.hs
@@ -0,0 +1,68 @@
+module Options where
+
+import qualified System.Environment as Env
+import System.Console.GetOpt
+          (ArgOrder(RequireOrder), OptDescr(Option), ArgDescr(NoArg, ReqArg),
+           getOpt, usageInfo, )
+import System.Exit (exitSuccess, )
+
+import qualified Control.Monad.Exception.Synchronous as Exc
+import qualified Control.Monad.Trans.Class as MT
+import Control.Monad (when, )
+
+import Text.Printf (printf, )
+
+
+data T =
+   Cons {
+      help :: Bool,
+      llvmConfigPath :: FilePath,
+      installPath :: FilePath,
+      install :: Bool
+   }
+
+deflt :: T
+deflt =
+   Cons {
+      help = False,
+      llvmConfigPath = "llvm-config",
+      installPath = "/usr/local/lib/pkgconfig/llvm.pc",
+      install = False
+   }
+
+
+options :: [OptDescr (T -> Exc.Exceptional String T)]
+options =
+   Option ['h'] ["help"]
+      (NoArg (\flags -> return $ flags{help = True}))
+      "show options" :
+   Option [] ["llvm-config"]
+      (ReqArg (\str flags -> return $ flags{llvmConfigPath = str}) "PATH")
+      (printf "path of llvm-config executable (default %s)" $
+       llvmConfigPath deflt) :
+   Option [] ["install"]
+      (NoArg (\flags -> return $ flags{install = True}))
+      (printf "install config file at standard location (default %s)" $
+       installPath deflt) :
+   []
+
+
+get :: Exc.ExceptionalT String IO T
+get = do
+   argv <- MT.lift Env.getArgs
+   let (opts, args, errors) =
+          getOpt RequireOrder options argv
+   when (not (null errors)) $ Exc.throwT $ concat $ errors
+   when (not (null args)) $ Exc.throwT $
+      "I have no usage for the arguments " ++ show args
+   flags <-
+      Exc.ExceptionalT $ return $
+         foldl (>>=) (return deflt) opts
+   when (help flags)
+      (MT.lift $
+       Env.getProgName >>= \programName ->
+       putStrLn
+          (usageInfo ("Usage: " ++ programName ++
+                      " [OPTIONS]") options) >>
+       exitSuccess)
+   return flags
diff --git a/src/Utility.hs b/src/Utility.hs
new file mode 100644
--- /dev/null
+++ b/src/Utility.hs
@@ -0,0 +1,10 @@
+module Utility where
+
+import qualified System.Exit as Exit
+import qualified System.IO as IO
+
+
+exitFailureMsg :: String -> IO ()
+exitFailureMsg msg = do
+   IO.hPutStrLn IO.stderr msg
+   Exit.exitFailure
