diff --git a/Examples/MacOSX/MainWrapper.hs b/Examples/MacOSX/MainWrapper.hs
new file mode 100644
--- /dev/null
+++ b/Examples/MacOSX/MainWrapper.hs
@@ -0,0 +1,4 @@
+{-# LANGUAGE ForeignFunctionInterface #-}
+module MainWrapper where
+import Main (main)
+foreign export ccall "haskell_main" main :: IO ()
diff --git a/Examples/MacOSX/Makefile b/Examples/MacOSX/Makefile
--- a/Examples/MacOSX/Makefile
+++ b/Examples/MacOSX/Makefile
@@ -1,10 +1,12 @@
-test: wrapper.o SDLWrapper.hs
-	ghc -no-hs-main --make wrapper.o SDLWrapper.hs -o test
-SDLWrapper_stub.h: SDLWrapper.hs
-	ghc -no-hs-main --make SDLWrapper.hs -c
-wrapper.o: SDLWrapper_stub.h
-	ghc -no-hs-main `sdl-config --cflags` -Wall wrapper.c -c
+# build with sdl wrapper for mac osx (see mainc.c or hssdl/Examples/MacOSX)
+PROGNAME=main
+$(PROGNAME): mainc.o MainWrapper.hs Main.hs
+	ghc -no-hs-main --make mainc.o MainWrapper.hs -o $@
+mainc.o: mainc.c MainWrapper_stub.h
+	ghc -no-hs-main `sdl-config --cflags` -Wall $*.c -c
+MainWrapper_stub.h: MainWrapper.hs
+	ghc -no-hs-main --make $< -c
 clean:
-	rm -f *.hi *.o *_stub.c *_stub.h test
+	rm -f *.hi *.o *_stub.c *_stub.h $(PROGNAME)
 .PHONY: clean
-
+#
diff --git a/Examples/MacOSX/SDLWrapper.hs b/Examples/MacOSX/SDLWrapper.hs
deleted file mode 100644
--- a/Examples/MacOSX/SDLWrapper.hs
+++ /dev/null
@@ -1,4 +0,0 @@
-{-# LANGUAGE ForeignFunctionInterface #-}
-module SDLWrapper where
-import Main
-foreign export ccall "haskell_main" main :: IO ()
diff --git a/Examples/MacOSX/mainc.c b/Examples/MacOSX/mainc.c
new file mode 100644
--- /dev/null
+++ b/Examples/MacOSX/mainc.c
@@ -0,0 +1,44 @@
+/*
+A C wrapper to get proper SDL initialisation on mac. From MACOSX in the
+SDL haskell package:
+
+  SDL uses Objective-C and Cocoa to open a UI window; this means that
+  Cocoa must be initialized, and in particular, an NSAutoReleasePool be in
+  place.  This initialization is done in libSDLmain.  For
+  C/C++/Objective-C programs, libSDLmain #defines the developer's main to
+  be SDL_main and piggy backs SDL_main onto it's own Cocoa main, using the
+  C preprocessor and abusing the linker.  Of course, this technique will
+  never work for Haskell: there is no clean entry point to a Haskell
+  runtime in this fashion.
+  ...
+  MainWrapper.hs imports Main.hs and foreign-exports main as haskell_main.
+  mainc.c includes SDL.h and contains a main function to make the
+  preprocessor magic of SDL happen; it also initializes the GHC runtime
+  system and calls haskell_main. Some makefile rules link our objects with
+  the GHC RTS and SDL.
+
+See also
+http://www.haskell.org/ghc/docs/latest/html/users_guide/ffi-ghc.html#using-own-main
+
+*/
+
+#include <SDL.h>
+#include <HsFFI.h>
+#ifdef __GLASGOW_HASKELL__
+#include "MainWrapper_stub.h"
+#endif
+
+#ifdef __GLASGOW_HASKELL__
+extern void __stginit_MainWrapper (void);
+#endif
+
+int main(int argc, char *argv[])
+{
+  hs_init(&argc, &argv);
+#ifdef __GLASGOW_HASKELL__
+  hs_add_root(__stginit_MainWrapper);
+#endif
+  haskell_main();
+  hs_exit();
+  return 0;
+}
diff --git a/Examples/MacOSX/wrapper.c b/Examples/MacOSX/wrapper.c
deleted file mode 100644
--- a/Examples/MacOSX/wrapper.c
+++ /dev/null
@@ -1,25 +0,0 @@
-//for explanations see http://www.haskell.org/ghc/docs/latest/html/users_guide/ffi-ghc.html#using-own-main
-
-#include <SDL.h>
-#include <HsFFI.h>
-
-#ifdef __GLASGOW_HASKELL__
-#include "SDLWrapper_stub.h"
-#endif
-
-#ifdef __GLASGOW_HASKELL__
-extern void __stginit_SDLWrapper ( void );
-#endif
-
-int main(int argc, char *argv[])
-{
-  hs_init(&argc, &argv);
-#ifdef __GLASGOW_HASKELL__
-  hs_add_root(__stginit_SDLWrapper);
-#endif
-
-  haskell_main();
-
-  hs_exit();
-  return 0;
-}
diff --git a/Graphics/UI/SDL/Events.hsc b/Graphics/UI/SDL/Events.hsc
--- a/Graphics/UI/SDL/Events.hsc
+++ b/Graphics/UI/SDL/Events.hsc
@@ -44,8 +44,9 @@
 
 import Foreign (Int16, Word8, Word16, Word32, Ptr,
                Storable(poke, sizeOf, alignment, peekByteOff, pokeByteOff, peek),
-               unsafePerformIO, toBool, new, alloca)
+               toBool, new, alloca)
 import Foreign.C (peekCString, CString, CInt)
+import System.IO.Unsafe (unsafePerformIO)
 import Data.Bits (Bits((.&.), shiftL))
 import Control.Concurrent (threadDelay)
 import Prelude hiding (Enum(..))
diff --git a/Graphics/UI/SDL/Joystick.hsc b/Graphics/UI/SDL/Joystick.hsc
--- a/Graphics/UI/SDL/Joystick.hsc
+++ b/Graphics/UI/SDL/Joystick.hsc
@@ -33,9 +33,10 @@
     , close
     ) where
 
-import Foreign (Int16, Word8, Ptr, FunPtr, Storable(peek), unsafePerformIO,
+import Foreign (Int16, Word8, Ptr, FunPtr, Storable(peek),
                 finalizeForeignPtr, toBool, maybePeek, alloca, withForeignPtr, newForeignPtr)
 import Foreign.C (peekCString, CString)
+import System.IO.Unsafe (unsafePerformIO)
 
 import Graphics.UI.SDL.General (unwrapMaybe)
 import Graphics.UI.SDL.Utilities (fromBitmask)
diff --git a/Graphics/UI/SDL/Types.hsc b/Graphics/UI/SDL/Types.hsc
--- a/Graphics/UI/SDL/Types.hsc
+++ b/Graphics/UI/SDL/Types.hsc
@@ -43,7 +43,8 @@
 
 import Foreign.C (CInt)
 import Foreign (Word8, Word16, Word32, Ptr, Storable(peekByteOff),
-               unsafePerformIO, newForeignPtr_, ForeignPtr, withForeignPtr)
+                newForeignPtr_, ForeignPtr, withForeignPtr)
+import System.IO.Unsafe (unsafePerformIO)
 
 import Graphics.UI.SDL.Utilities (Enum(..), fromBitmask)
 import Graphics.UI.SDL.Color (Pixel(..))
diff --git a/Graphics/UI/SDL/Video.hsc b/Graphics/UI/SDL/Video.hsc
--- a/Graphics/UI/SDL/Video.hsc
+++ b/Graphics/UI/SDL/Video.hsc
@@ -83,7 +83,7 @@
 
 import Foreign (Ptr, FunPtr, Storable(peek), castPtr, plusPtr, nullPtr, newForeignPtr_,
                finalizeForeignPtr, alloca, withForeignPtr, newForeignPtr)
-import Foreign.C (peekCString, CString, CInt)
+import Foreign.C (peekCString, CString, CInt())
 import Foreign.Marshal.Array (withArrayLen, peekArray0, peekArray, allocaArray)
 import Foreign.Marshal.Utils (with, toBool, maybeWith, maybePeek, fromBool)
 import Control.Exception (bracket)
@@ -130,7 +130,7 @@
 data Toggle = Disable | Enable | Query
     deriving (Eq, Ord, Show)
 
-toToggle :: (Num a) => a -> Toggle
+toToggle :: (Eq a, Num a) => a -> Toggle
 toToggle (#{const SDL_DISABLE}) = Disable
 toToggle (#{const SDL_ENABLE}) = Enable
 toToggle (#{const SDL_QUERY}) = Query
diff --git a/MACOSX b/MACOSX
--- a/MACOSX
+++ b/MACOSX
@@ -54,10 +54,9 @@
 
 All our troubles stem from SDL's startup procedure on Mac OS X.  The fundamental problem is that SDL uses Objective-C and Cocoa to open a UI window; this means that Cocoa must be initialized, and in particular, an NSAutoReleasePool be in place.  This initialization is done in libSDLmain.  For C/C++/Objective-C programs, libSDLmain #defines the developer's main to be SDL_main and piggy backs SDL_main onto it's own Cocoa main, using the C preprocessor and abusing the linker.  Of course, this technique will never work for Haskell: there is no clean entry point to a Haskell runtime in this fashion.
 
-But we can fake it. In Examples/MacOSX, there is an example program using SDL in Main.hs. It doesn't need to be modified to make it work on OS X. Instead we put two helper files in the same directory and compile them along with it: SDLWrapper.hs imports Main and foreign-exports Main.main as haskell_main to be able to call it from C. wrapper.c includes SDL.h and contains a main function to make the preprocessor magic of SDL happen. The C main function initializes the GHC RTS and calls haskell_main from SDLWrapper.hs which is Main.main in disguise.
-The Makefile then uses ghc --make to link our objects with the GHC RTS and SDL.
+But we can fake it. In Examples/MacOSX, there is an example program using SDL in Main.hs. It doesn't need to be modified to make it work on OS X. Instead we put two helper files in the same directory and compile them along with it: MainWrapper.hs imports Main.hs and foreign-exports main as haskell_main. mainc.c includes SDL.h and contains a main function to make the preprocessor magic of SDL happen; it also initializes the GHC runtime system and calls haskell_main. Some makefile rules link our objects with the GHC RTS and SDL.
 
-For your own projects just copy the two helper files and make your build system produce the final result like the example Makefile does.
+For your own projects, copy the two helper files mainc.c and MainWrapper.hs and copy/mimic the build rules from the example Makefile, optionally changing PROGNAME.
 
 GHCi and hsSDL on Mac OS X
 --------------------------
diff --git a/SDL.cabal b/SDL.cabal
--- a/SDL.cabal
+++ b/SDL.cabal
@@ -1,6 +1,6 @@
 Cabal-Version:      >= 1.6
 Name:               SDL
-Version:            0.6.2
+Version:            0.6.3
 Maintainer:         Lemmih (lemmih@gmail.com)
 Author:             Lemmih (lemmih@gmail.com)
 Copyright:          2004-2010, Lemmih
@@ -20,8 +20,8 @@
 Data-files:         README, MACOSX, WIN32,
                     Examples/MacOSX/Main.hs,
                     Examples/MacOSX/Makefile,
-                    Examples/MacOSX/SDLWrapper.hs,
-                    Examples/MacOSX/wrapper.c
+                    Examples/MacOSX/MainWrapper.hs,
+                    Examples/MacOSX/mainc.c
 Extra-Source-files: configure, configure.ac, SDL.buildinfo.in, config.mk.in, includes/HsSDLConfig.h.in
 
 Library
diff --git a/Setup.lhs b/Setup.lhs
--- a/Setup.lhs
+++ b/Setup.lhs
@@ -2,4 +2,4 @@
 > module Main where
 > import Distribution.Simple
 > main :: IO ()
-> main = defaultMainWithHooks defaultUserHooks
+> main = defaultMainWithHooks autoconfUserHooks
