 ;;; SQLite connection
 
 (cl-eval-when (load compile)
+  (defvar emacsql-sqlite-data-root
+    (file-name-directory (or load-file-name buffer-file-name))
+    "Directory where EmacSQL is installed."))
+
+(cl-eval-when (load compile)
   (defvar emacsql-sqlite-executable
     (expand-file-name (format "bin/emacsql-sqlite-%s%s" (emacsql-system-tuple)
                               (if (memq system-type '(windows-nt cygwin ms-dos))
                                   ".exe"
                                 ""))
-                      emacsql-data-root)
+                      emacsql-sqlite-data-root)
     "Path to the EmacSQL backend (this is not the sqlite3 shell)."))
 
 (defvar emacsql-sqlite-reserved


(defun emacsql-sqlite-compile-switches ()
  "Return the compilation switches from the Makefile under sqlite/."
  (let ((makefile (expand-file-name "sqlite/Makefile" emacsql-data-root))
        (case-fold-search nil))
    (with-temp-buffer
      (insert-file-contents makefile)

  "Compile the SQLite back-end for EmacSQL, returning non-nil on success.
If called with non-nil ASYNC the return value is meaningless."
  (let* ((cc (executable-find "cc"))
         (src (expand-file-name "sqlite" emacsql-sqlite-data-root))
         (files (mapcar (lambda (f) (expand-file-name f src))
                        '("sqlite3.c" "emacsql.c")))
         (cflags (list (format "-I%s" src) (format "-O%d" (or o-level 2))))
