pre-installer.ss
(module pre-installer mzscheme
	(require (lib "setup-extension.ss" "make")
		 (lib "compile.ss" "dynext")
		 (lib "link.ss" "dynext")
		 (lib "file.ss"))
	(require "sqlid-libpath.scm")
	(provide pre-installer)

(define (inserr env message)
  (display 
   (format "  ~a~%" message))
  (display 
   (format "  Setting environment variable ~a might help.~%  It will be used as PLT_EXTENSION_LIB_PATHS variable~%" 
	   env )))

(define saved-plt-extension-lib-paths #f)

(define (cond-set-extension_lib_path env)
  (let ((var (getenv env)))
    (if (eq? var #f)
	(begin
	  (display (format "  ~a has not been set, will *not* be used for PLT_EXTENSION_LIB_PATHS~%" env))
	  (if saved-plt-extension-lib-paths
	      (begin
		(display (format "  Resetting PLT_EXTENSION_LIB_PATHS=~a~%" saved-plt-extension-lib-paths))
		(putenv "PLT_EXTENSION_LIB_PATHS" saved-plt-extension-lib-paths))))
	(begin
	  (display (format "  Setting PLT_EXTENSION_LIB_PATHS=~a~%" var))
	  (putenv "PLT_EXTENSION_LIB_PATHS" var)))))

(define (pre-installer plthome package-dir)

  (display (format "  plthome  = ~a ~%" plthome))
  (display (format "  package-dir = ~a ~%" package-dir))

  (set-libpath)

  (set! saved-plt-extension-lib-paths (getenv "PLT_EXTENSION_LIB_PATHS"))

  (display (format "SQLITE3 DRIVER ~%"))
  (with-handlers ((exn:fail? (lambda (exn) (inserr "SQLITE3_EXTENSION_LIB_PATH" "SQLITE3 DRIVER NOT INSTALLED"))))
		 (cond-set-extension_lib_path "SQLITE3_EXTENSION_LIB_PATH")
		 (display (format "  PLT_EXTENSION_LIB_PATHS=~a~%" (getenv "PLT_EXTENSION_LIB_PATHS")))
		 (eval
		  (pre-install plthome
			      (build-path package-dir)
			      "c-sqld-sqlite.c"
			      (build-path package-dir)
			      ;; header subdirs
			      (list)
			      ;; unix libs
			      (list "sqlite3" "pthread")
			      ;; windows libs
			      (list)
			      ;; unix extra libs (assume always there)
			      (list)
			      ;; Windows extra libs (assume always there)
			      (list)
			      ;; Extra depends:
			      (list "c-sqld-sqlite.scm")
			      ;; Last-chance k:
			      (lambda (k) (k))
			      ;; 3m, too:
			      #t)))

  (display (format "POSTGRESQL DRIVER ~%"))
  (with-handlers ((exn:fail? (lambda (exn) (inserr "PSQL_EXTENSION_LIB_PATH" "POSTGRESQL DRIVER NOT INSTALLED"))))
		 (cond-set-extension_lib_path "PSQL_EXTENSION_LIB_PATH")
		 (display (format "  PLT_EXTENSION_LIB_PATHS=~a~%" (getenv "PLT_EXTENSION_LIB_PATHS")))
		 (pre-install plthome
			      (build-path package-dir)
			      "c-sqld-psql.c"
			      (build-path package-dir)
			      ;; header subdirs
			      (list)
			      ;; unix libs
			      (list "pq" "pthread")
			      ;; windows libs
			      (list)
			      ;; unix extra libs (assume always there)
			      (list)
			      ;; Windows extra libs (assume always there)
			      (list)
			      ;; Extra depends:
			      (list "c-sqld-psql.scm")
			      ;; Last-chance k:
			      (lambda (k) (k))
			      ;; 3m, too:
			      #t))

  (display (format "MYSQL DRIVER ~%"))
  (with-handlers ((exn:fail? (lambda (exn) (inserr "MYSQL_EXTENSION_LIB_PATH" "MYQSL DRIVER NOT INSTALLED"))))
		 (cond-set-extension_lib_path "MYSQL_EXTENSION_LIB_PATH")
		 (display (format "  PLT_EXTENSION_LIB_PATHS=~a~%" (getenv "PLT_EXTENSION_LIB_PATHS")))
		 (pre-install plthome
			      (build-path package-dir)
			      "c-sqld-mysql.c"
			      (build-path package-dir)
			      ;; header subdirs
			      (list)
			      ;; unix libs
			      (list "mysqlclient" "pthread")
			      ;; windows libs
			      (list)
			      ;; unix extra libs (assume always there)
			      (list)
			      ;; Windows extra libs (assume always there)
			      (list)
			      ;; Extra depends:
			      (list "c-sqld-mysql.scm")
			      ;; Last-chance k:
			      (lambda (k) (k))
			      ;; 3m, too:
			      #t))

  (display (format "ORACLE DRIVER ~%"))
  (with-handlers ((exn:fail? (lambda (exn) (inserr "ORACLE_EXTENSION_LIB_PATH" "ORACLE DRIVER NOT INSTALLED"))))
		 (cond-set-extension_lib_path "ORACLE_EXTENSION_LIB_PATH")
		 (display (format "  PLT_EXTENSION_LIB_PATHS=~a~%" (getenv "PLT_EXTENSION_LIB_PATHS")))
		 (pre-install plthome
			      (build-path package-dir)
			      "c-sqld-oracle.c"
			      (build-path package-dir)
			      ;; header subdirs
			      (list)
			      ;; unix libs
			      (list "sqlora8" "pthread")
			      ;; windows libs
			      (list)
			      ;; unix extra libs (assume always there)
			      (list)
			      ;; Windows extra libs (assume always there)
			      (list)
			      ;; Extra depends:
			      (list "c-sqld-oracle.scm")
			      ;; Last-chance k:
			      (lambda (k) (k))
			      ;; 3m, too:
			      #t))

  (display (format "DB2 DRIVER ~%"))
  (with-handlers ((exn:fail? (lambda (exn) (inserr "DB2_EXTENSION_LIB_PATH" "DB2 DRIVER NOT INSTALLED"))))
		 (cond-set-extension_lib_path "DB2_EXTENSION_LIB_PATH")
		 (display (format "  PLT_EXTENSION_LIB_PATHS=~a~%" (getenv "PLT_EXTENSION_LIB_PATHS")))
		 (pre-install plthome
			      (build-path package-dir)
			      "c-sqld-db2.c"
			      (build-path package-dir)
			      ;; header subdirs
			      (list)
			      ;; unix libs
			      (list "db2" "pthread")
			      ;; windows libs
			      (list)
			      ;; unix extra libs (assume always there)
			      (list)
			      ;; Windows extra libs (assume always there)
			      (list)
			      ;; Extra depends:
			      (list "c-sqld-db2.scm")
			      ;; Last-chance k:
			      (lambda (k) (k))
			      ;; 3m, too:
			      #t))

  )


)