     (with-current-buffer buf
       (goto-char (point-max))
       (insert  "> gxc " (if gerbil-compile-optimize "-O " "") fname "\n"))
+    (setq gerbil-build-directory nil)
     (let ((proc (if gerbil-compile-optimize
                     (start-process "gxc" buf "gxc" "-O" fname)
                   (start-process "gxc" buf "gxc" fname))))

  (gerbil-reload-file buffer-file-name))

(defvar gerbil-compile-optimize t)

(defun gerbil-compile-current-buffer ()
  (interactive)

    (with-current-buffer buf
      (goto-char (point-max))
      (insert "> build " build "\n"))
    (setq gerbil-build-directory build-dir)
    (let ((proc (start-process "build" buf "sh" "-c"
                               (concat "cd " build-dir " && ./" build-script))))
      (set-process-sentinel proc 'gerbil-compile-sentinel)
