;;; -*- Mode: lisp -*-

#||
(print #-gcl *load-truename* #+gcl sys:*load-pathname*)

(print (merge-pathnames
	(make-pathname
	 :name (concatenate 'string "binary-"
			    #+clisp "clisp"
			    #+cmu "cmucl"
			    #+scl "scl"
			    #+sbcl "sbcl"
			    #+allegro "acl"
			    #+openmcl "openmcl"
                #+abcl "abcl"
			    #-(or clisp cmu scl sbcl gcl allegro openmcl abcl) "unknownlisp")
	 :directory '(#-gcl :relative "blas"))
	(make-pathname :directory (pathname-directory #-gcl *load-truename*
						      #+gcl sys:*load-pathname*))))
||#

#-gcl
(progn
  (defun lapack-source-pathname (subdir)
    (merge-pathnames (make-pathname :directory (list :relative subdir))
		     (make-pathname :directory (pathname-directory *load-truename*))))
(defun lapack-binary-pathname (subdir)
  (merge-pathnames
   (make-pathname
    :name (concatenate 'string "binary-"
		       #+clisp "clisp"
		       #+cmu "cmucl"
		       #+scl "scl"
		       #+sbcl "sbcl"
		       #+allegro "acl"
		       #+openmcl "openmcl"
               #+abcl "abcl"
		       #-(or clisp cmu scl sbcl gcl allegro openmcl abcl) "unknownlisp")
    :directory (list :relative subdir))
   (make-pathname :directory (pathname-directory *load-truename*))))
)

#+gcl
(progn
  (defun lapack-source-pathname (subdir)
    (merge-pathnames (make-pathname :directory (list subdir))
		     (make-pathname :directory (pathname-directory sys:*load-pathname*))))
(defun lapack-binary-pathname (subdir)
  (merge-pathnames (make-pathname :directory (list subdir))
		   (make-pathname :directory (pathname-directory sys:*load-pathname*))))
)

(mk:defsystem lapack-package
  :source-pathname (lapack-source-pathname ".")
  :source-extension "lisp"
  :components
  ((:file "lapack-package")))

(mk:defsystem blas
  :source-pathname (merge-pathnames (make-pathname :directory '(#-gcl :relative "blas"))
				    (make-pathname :directory (pathname-directory #-gcl *load-truename*
										  #+gcl sys:*load-pathname*)))
  :binary-pathname (lapack-binary-pathname "blas")
  :source-extension "lisp"
  :depends-on ("lapack-package")
  :components
  (
   (:file "daxpy")
   (:file "dcopy")
   (:file "ddot")
   (:file "dnrm2")
   (:file "dscal")
   (:file "idamax")

   (:file "dasum")
   (:file "dcabs1")
   (:file "dgbmv"
	  :depends-on ("lsame" "xerbla"))
   (:file "dgemm"
	  :depends-on ("lsame" "xerbla"))
   (:file "dgemv"
	  :depends-on ("lsame" "xerbla"))
   (:file "dger"
	  :depends-on ("xerbla"))
   (:file "drot")
   (:file "drotg")
   (:file "dsbmv"
	  :depends-on ("lsame" "xerbla"))
   (:file "dspmv"
	  :depends-on ("lsame" "xerbla"))
   (:file "dspr"
	  :depends-on ("lsame" "xerbla"))
   (:file "dspr2"
	  :depends-on ("lsame" "xerbla"))
   (:file "dswap")
   (:file "dsymm"
	  :depends-on ("lsame" "xerbla"))
   (:file "dsymv"
	  :depends-on ("lsame" "xerbla"))
   (:file "dsyr"
	  :depends-on ("lsame" "xerbla"))
   (:file "dsyr2"
	  :depends-on ("lsame" "xerbla"))
   (:file "dsyr2k"
	  :depends-on ("lsame" "xerbla"))
   (:file "dsyrk"
	  :depends-on ("lsame" "xerbla"))
   (:file "dtbmv"
	  :depends-on ("lsame" "xerbla"))
   (:file "dtbsv"
	  :depends-on ("lsame" "xerbla"))
   (:file "dtpmv"
	  :depends-on ("lsame" "xerbla"))
   (:file "dtpsv"
	  :depends-on ("lsame" "xerbla"))
   (:file "dtrmm"
	  :depends-on ("lsame" "xerbla"))
   (:file "dtrmv"
	  :depends-on ("lsame" "xerbla"))
   (:file "dtrsm"
	  :depends-on ("lsame" "xerbla"))
   (:file "dtrsv"
	  :depends-on ("lsame" "xerbla"))
   (:file "dzasum"
	  :depends-on ("dcabs1"))
   (:file "dznrm2")
   (:file "icamax")
   (:file "isamax")
   (:file "izamax"
	  :depends-on ("dcabs1"))
   (:file "lsame")
   (:file "xerbla")

   ;; Complex versions.
   (:file "zaxpy"
	  :depends-on ("dcabs1"))
   (:file "zcopy")
   (:file "zdotc")
   (:file "zdotu")
   (:file "zdscal")
   (:file "zgbmv")
   (:file "zgemm")
   (:file "zgemv")
   (:file "zgerc")
   (:file "zgeru")
   (:file "zhbmv")
   (:file "zhemm")
   (:file "zhemv")
   (:file "zher")
   (:file "zher2")
   (:file "zher2k")
   (:file "zherk")
   (:file "zhpmv")
   (:file "zhpr")
   (:file "zhpr2")
   (:file "zrotg")
   (:file "zscal")
   (:file "zswap")
   (:file "zsymm")
   (:file "zsyr2k")
   (:file "zsyrk")
   (:file "ztbmv")
   (:file "ztbsv")
   (:file "ztpmv")
   (:file "ztpsv")
   (:file "ztrmm")
   (:file "ztrmv")
   (:file "ztrsm")
   (:file "ztrsv")
   ))

(mk:defsystem lapack
  :source-pathname (directory-namestring #-gcl *load-truename*
					 #+gcl sys:*load-pathname*)
;;  :binary-pathname (make-pathname :directory (pathname-directory *load-truename*))
  :binary-pathname (lapack-binary-pathname "lapack")
  :source-extension "lisp"
  :depends-on ("lapack-package" "blas")
  :components
  (
   (:module lapack
	    :binary-pathname ""
	    :components
	    ((:file "dgeev"
		    :depends-on ("dlartg" "dlapy2" "dgebak" "dtrevc" "dhseqr"
					  "dorghr" "dlacpy" "dgehrd" "dgebal"
					  "dlascl" "dlange" "dlabad" "dlamch"
					  "ilaenv"))
	     (:file "dgebak")
 	     (:file "dgebal")
 	     (:file "dgehrd"
		    :depends-on ("dlahrd" "dlarfb" "dgehd2" "ilaenv"))
 	     (:file "dhseqr"
		    :depends-on ("dlarfx" "dlarfg" "dlapy2" "dlacpy" "dlanhs"
					  "dlabad" "dlamch" "dlahqr" "ilaenv"
					  "dlaset"))
 	     (:file "dlabad")
 	     (:file "dlacpy")
 	     (:file "dlamch")
 	     (:file "dlange"
		    :depends-on ("dlassq"))
 	     (:file "dlapy2")
 	     (:file "dlartg"
		    :depends-on ("dlamch"))
 	     (:file "dlascl"
		    :depends-on ("dlamch"))
 	     (:file "dorghr"
		    :depends-on ("dorgqr" "ilaenv"))
	     (:file "dtrevc"
		    :depends-on ("dlabad" "dlamch" "dlaln2"))
 	     (:file "ilaenv"
		    :depends-on ("ieeeck"))
	     (:file "dlahrd"
		    :depends-on ("dlarfg"))
	     (:file "dlarfb")
	     (:file "dgehd2"
		    :depends-on ("dlarfg" "dlarf"))
	     (:file "dlaset")
	     (:file "dlahqr"
		    :depends-on ("dlanhs" "dlarfg" "dlanv2" "dlabad" "dlamch"))
	     (:file "dlanhs"
		    :depends-on ("dlassq"))
	     (:file "dlarfg"
		    :depends-on ("dlapy2" "dlamch"))
	     (:file "dlarfx")
	     (:file "dlassq")
	     (:file "dorgqr"
		    :depends-on ("dorg2r" "dlarft" "dlarfb" "ilaenv"))
	     (:file "dlaln2"
		    :depends-on ("dladiv"
				 "dlamch"))
	     (:file "ieeeck")
	     (:file "dlarf")
	     (:file "dlanv2"
		    :depends-on ("dlapy2" "dlamch"))
	     (:file "dorg2r"
		    :depends-on ("dlarf"))
	     (:file "dlarft")
	     (:file "dladiv")

	     ;; DGEEVX
	     (:file "dgeevx"
		    :depends-on ("dlartg" "dlapy2" "dgebak" "dtrsna" "dtrevc"
					  "dhseqr" "dorghr" "dlacpy" "dgehrd"
					  "dgebal" "dlascl" "dlange" "dlabad"
					  "dlamch" "ilaenv"))
	     (:file "dtrsna"
		    :depends-on ("dtrexc" "dlacon" "dlaqtr"
					  "dlacpy" "dlapy2" "dlamch"))
	     (:file "dtrexc"
		    :depends-on ("dlaexc"))
	     (:file "dlacon")
	     (:file "dlaqtr"
		    :depends-on ("dladiv" "dlaln2" "dlange" "dlamch"))
	     (:file "dlaexc"
		    :depends-on ("dlasy2" "dlanv2" "dlarfg" "dlamch" "dlange"
					  "dlacpy" "dlartg"))
	     (:file "dlasy2"
		    :depends-on ("dlamch"))

	     ;; DGESV
	     (:file "dgesv"
		    :depends-on ("dgetrf" "dgetrs"))
	     (:file "dgetrf"
		    :depends-on ("dgetf2" "dlaswp" "ilaenv"))
	     (:file "dgetrs"
		    :depends-on ("dlaswp"))
	     (:file "dgetf2")
	     (:file "dlaswp")

	     ;; DGESDD
	     (:file "dgesdd"
		    :depends-on ("dorglq" "dgelqf" "dorgbr" "dormbr" "dorgqr"
					  "dlacpy" "dbdsdc" "dgebrd" "dlaset"
					  "dgeqrf" "dlascl" "dlange" "dlamch"
					  "ilaenv"))
	     (:file "dbdsdc"
		    :depends-on ("dlasr" "dlasda" "dlasd0" "dlamch" "dlascl"
					 "dlanst" "dlaset" "dlasdq"
					 "dlartg" "ilaenv"))
	     (:file "dgebrd"
		    :depends-on ("dlabrd" "dgebd2" "ilaenv"))
	     (:file "dgelqf"
		    :depends-on ("dgelq2" "dlarfb" "dlarft" "ilaenv"))
	     (:file "dorgbr"
		    :depends-on ("dorglq" "dorgqr" "ilaenv"))
	     (:file "dorglq"
		    :depends-on ("dorgl2" "dlarfb" "dlarft" "ilaenv"))
	     (:file "dorgl2"
		    :depends-on ("dlarf"))
	     (:file "dormbr"
		    :depends-on ("dormqr" "dormlq" "ilaenv"))
	     (:file "dlasdq"
		    :depends-on ("dlasr" "dbdsqr" "dlartg"))
	     (:file "dlanst"
		    :depends-on ("dlassq"))
	     (:file "dlasd0"
		    :depends-on ("dlasdt" "dlasd1" "dlasdq"))
	     (:file "dlasda"
		    :depends-on ("dlasd6" "dlaset" "dlasdq"))
	     (:file "dlasr")
	     (:file "dlabrd"
		    :depends-on ("dlarfg"))
	     (:file "dgebd2"
		    :depends-on ("dlarf" "dlarfg"))
	     (:file "dgelq2"
		    :depends-on ("dlarf" "dlarfg"))
	     (:file "dormqr"
		    :depends-on ("dorm2r" "dlarfb" "dlarft" "ilaenv"))
	     (:file "dormlq"
		    :depends-on ("dorml2" "dlarfb" "dlarft" "ilaenv"))
	     (:file "dgeqrf"
		    :depends-on ("dgeqr2" "dlarfb" "dlarft" "ilaenv"))
	     (:file "dbdsqr"
		    :depends-on ("dlasq1" "dlasv2" "dlas2" "dlasr" "dlartg"
					  "dlamch"))
	     (:file "dlasq1"
		    :depends-on ("dlas2" "dlasrt" "dlasq2" "dlascl"))
	     (:file "dlasv2"
		    :depends-on ("dlamch"))
	     (:file "dlas2")
	     (:file "dlasdt")
	     (:file "dlasd1"
		    :depends-on ("dlasd2" "dlasd3" "dlamrg" "dlascl"))
	     (:file "dlasrt")
	     (:file "dlasq2"
		    :depends-on ("dlasq3" "ilaenv" "dlasrt" "dlamch"))
	     (:file "dlasd2"
		    :depends-on ("dlamrg" "dlacpy" "dlaset" "dlapy2" "dlamch"
					  "dlamrg"))
	     (:file "dlasd3"
		    :depends-on ("dlasd4" "dlacpy" "dlascl" "dlamch"))
	     (:file "dlamrg")
	     (:file "dlasd6"
		    :depends-on ("dlasd7" "dlasd8"))
	     (:file "dorml2")
	     (:file "dgeqr2"
		    :depends-on ("dlarf" "dlarfg"))
	     (:file "dorm2r"
		    :depends-on ("dlarf"))
	     (:file "dlasd4"
		    :depends-on ("dlasd5" "dlaed6"))
	     (:file "dlasd7"
		    :depends-on ("dlapy2" "dlamch" "dlamrg"))
	     (:file "dlasd8"
		    :depends-on ("dlasd4" "dlaset" "dlascl" "dlamch"))
	     (:file "dlasq3"
		    :depends-on ("dlasq4" "dlasq5" "dlasq6" "dlamch"))
	     (:file "dlasq4")
	     (:file "dlasq5")
	     (:file "dlasq6"
		    :depends-on ("dlamch"))
	     (:file "dlasd5")
	     (:file "dlaed6"
		    :depends-on ("dlamch"))

	     ;; DGESVD
	     (:file "dgesvd"
		    :depends-on ("dorglq" "dgelqf" "dormbr" "dorgqr" "dlacpy"
					  "dbdsqr" "dorgbr" "dgebrd" "dlaset"
					  "dgeqrf" "dlascl" "dlange" "dlamch"
					  "ilaenv"))

	     ;; For condition numbers of the singular vectors
	     (:file "ddisna")
	     
	     ;;(:file "zgeev")
	     (:file "zlange"
		    :depends-on ("zlassq"))
	     (:file "zlassq")
	     ))))

(mk:defsystem lapack-interface
  :source-pathname (directory-namestring #-gcl *load-truename*
					 #+gcl sys:*load-pathname*)
  :source-extension "lisp"
  :depends-on ("lapack")
  :components
  (
   (:file "eigensys")))
