diff --git a/BotLib.hs b/BotLib.hs
new file mode 100644
--- /dev/null
+++ b/BotLib.hs
@@ -0,0 +1,87 @@
+module BotLib where
+
+
+import Data.ByteString.Char8 (pack, ByteString)
+import qualified Data.ByteString.Char8 as B -- crank it up, yeah!
+
+import Data.Char
+import Data.List
+
+
+baseName :: FilePath -> FilePath
+baseName s = base
+    where
+    rfile = takeWhile (not . (`elem` "/\\")) (reverse s)
+    base  = takeWhile (/='.') (reverse rfile)
+
+--
+-- tricksy non-copying implementation.
+--
+expand :: Int -> Int -> String -> ByteString -> ByteString
+expand l n basename xs
+    | n `seq` xs `seq` False               = undefined -- strict
+    | l == n                               = xs        -- not found
+    | pLUGIN  `B.isPrefixOf` (B.drop n xs) = B.concat $ pref : render  name  ++ [B.tail rest]
+    | mODULES `B.isPrefixOf` (B.drop n xs) = B.concat $ pref : modules basename name' ++ [B.tail rest']
+    | otherwise                            = expand l (n+1) basename xs
+
+    where pref         = B.take n xs    -- accumulating an offset
+
+          pLUGIN       = pack "PLUGIN "
+          (name, rest) = B.break (=='\n') (B.drop (n+B.length pLUGIN) xs)
+
+          mODULES      = pack "MODULES "
+          (name', rest') = B.break (=='\n') (B.drop (n+B.length mODULES) xs)
+
+--
+-- render the plugin boiler plate
+--
+render :: ByteString -> [ByteString]
+render name =
+    pack "newtype "  : name :
+    pack "Module = " : name : pack "Module () \n\
+    \\n\
+    \theModule :: MODULE                            \n\
+    \theModule = MODULE $ " : name : pack "Module ()       \n" : []
+
+--
+-- Collect all the plugin names, and generate the Modules.hs file
+--
+modules :: String -> ByteString -> [ByteString]
+modules basename s =
+    [pack "module ", pack basename, pack " (modulesInfo) where\n"
+    ,pack "import Lambdabot\n"
+    ,pack "\n"]
+    ++ (concatMap importify statics) ++
+    [pack "modulesInfo :: (LB (), [String])\n"
+    ,pack "modulesInfo = (loadStaticModules, plugins)\n"
+    ,pack "loadStaticModules :: LB ()\n"
+    ,pack "loadStaticModules = do\n"]
+    ++ (concatMap instalify statics) ++
+    [pack "plugins :: [String]\n"
+    ,pack "plugins = ["]
+    ++ ((concat . (intersperse [pack ","]) . map pluginify) plugins) ++
+    [pack "]\n"]
+
+    where ms  = filter nonWhitespace $ B.split ' ' s
+
+          statics = sort statics'
+          plugins = sort plugins'
+
+          (statics', rest) = break ((==)(pack ":")) ms
+          plugins' = drop 1 rest
+
+          importify x = [pack "import qualified Plugin.", x, B.singleton '\n']
+          instalify x = [pack "  ircInstallModule Plugin.",x
+                        ,pack ".theModule \""
+                        ,B.map toLower x
+                        , pack "\"\n"]
+          pluginify x = [pack "\""
+                        ,B.map toLower x
+                        ,pack "\""]
+
+
+          nonWhitespace t
+              | t == pack ""   = False
+              | t == pack "\n" = False
+              | otherwise      = True
diff --git a/BotPP.hs b/BotPP.hs
new file mode 100644
--- /dev/null
+++ b/BotPP.hs
@@ -0,0 +1,28 @@
+{-# OPTIONS -O -funbox-strict-fields #-}
+-- Copyright (c) 2006 Don Stewart - http://www.cse.unsw.edu.au/~dons
+-- GPL version 2 or later (see http://www.gnu.org/copyleft/gpl.html)
+
+--
+-- Implements a preprocessor for plugins, filling in commonly required
+-- syntax.
+--
+-- Currently only useful for plugins that only:
+--  import Plugin
+-- and have () for state.
+--
+-- Also used to generate the modules list in Modules.hs
+--
+
+import System.Environment
+
+import qualified Data.ByteString.Char8 as B -- crank it up, yeah!
+
+import BotLib
+
+main :: IO ()
+main = do
+    -- putStr "BotPP called with args: ";  print =<< getArgs
+    [orig,i,o] <- getArgs
+    let basename = baseName orig
+    -- putStr "basename = "; print basename
+    B.readFile i >>= \l -> B.writeFile o $ expand (B.length l) 0 basename l
diff --git a/LICENSE b/LICENSE
new file mode 100644
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2003 Andrew J. Bromage
+Portions Copyright (c) 2003 Shae Erisson, Sven M. Hallberg, Taylor Campbell
+Portions Copyright (c) 2003-2006 Members of the AUTHORS file
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject
+to the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 = defaultMainWithHooks defaultUserHooks
diff --git a/botpp.cabal b/botpp.cabal
new file mode 100644
--- /dev/null
+++ b/botpp.cabal
@@ -0,0 +1,21 @@
+Name:                botpp
+Version:             0.1
+License:             GPL
+License-file:        LICENSE
+Author:              Don Stewart
+Maintainer:          Cale Gibbard <cgibbard@gmail.com>
+Category:            Development, Web
+Synopsis:            Build tool for Lambdabot
+Description:         This is a build tool for the Lambdabot IRC bot, which processes
+                     simple directives to write a bunch of boilerplate Haskell code.
+Homepage:            http://haskell.org/haskellwiki/Lambdabot
+
+build-type:          Simple
+Cabal-Version:       >= 1.2
+
+Library
+        build-depends: base, bytestring
+        exposed-modules: BotLib
+
+Executable BotPP
+           main-is: BotPP.hs
