     (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)

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

            (let (limit (point))
              (goto-char (point-max))
              (when (re-search-backward gerbil-error-locat-rx limit t)
                (let* ((loc (gerbil-extract-locat (buffer-substring (point) (point-max))))
                       (fname (if gerbil-build-directory
                                  (concat gerbil-build-directory (car loc))
                                (car loc))))
                  (find-file fname)
                  (goto-line (cadr loc))
                  (forward-char (- (caddr loc) 1))
                  (mark-sexp)))))))
