(mapcar #'require
        '(:asdf :sb-posix :clx :mcclim :mcclim-freetype :gsharp))

(push (lambda ()
        (setf mcclim-freetype::*freetype-font-path*
              (merge-pathnames
               (make-pathname :directory '(:relative "fonts"))
               (make-pathname
                :directory (pathname-directory sb-ext:*core-pathname*))))
        (setf sdl::*fonts-directory*
              (merge-pathnames
               (make-pathname :directory '(:relative "fonts"))
               (make-pathname
                :directory (pathname-directory sb-ext:*core-pathname*)))))
      sb-ext:*init-hooks*)

(sb-ext:disable-debugger)
(sb-ext:save-lisp-and-die 
 "/tmp/gsharp"
 :executable t
 :toplevel (lambda ()
             #+(or darwin win32)
             (unless (sb-posix:getenv "DISPLAY")
               (sb-posix:putenv "DISPLAY=:0.0"))
             (handler-case
                 (gsharp:gsharp)
               #+(or darwin win32)
               (sb-bsd-sockets:socket-error (c)
                 (declare (ignore c))
                 (sb-ext:run-program "/Applications/Utilities/X11.app/Contents/MacOS/X11" nil :wait nil)
                 (sleep 10)
                 (gsharp:gsharp)))
             (sb-ext:quit :unix-status 0)))
