;;; -*- Mode: Lisp -*-

(cl:in-package :cl-user)

#+mcclim(eval-when (:compile-toplevel :load-toplevel :execute)
          (cerror "Continue corrupting the lisp image."
                  "~@<You are trying to load the McCLIM dependency groveler into a lisp ~
                      image that has McCLIM already loaded. Besides possibly skewing results, ~
                      this will corrupt your Lisp image.~:@>"))

;; load groveler, for the component type, etc.
(eval-when (:load-toplevel :execute)
  (asdf:find-system :mcclim) ; ensure that its system definition is loaded.
  (asdf:oos 'asdf:load-op :asdf-dependency-grovel)) 

(defpackage :mcclim-dependencies.system
  (:use :asdf :cl :asdf-dependency-grovel :mcclim.system))

(in-package :mcclim-dependencies.system)

(defclass mcclim-instrumented-cl-source-file (mcclim-cl-source-file instrumented-cl-source-file)
     ())

;;; serial system definitions
(defmacro groveling-defsystem ((module &key depends-on (serial t)) &body components)
  `(progn
     #+asdf
     (asdf:defsystem ,module
       ,@(and depends-on
              `(:depends-on ,depends-on))
       :serial ,serial
       :default-component-class mcclim-instrumented-cl-source-file
       :components
       (,@(loop for c in components
                for p = (when (stringp c)
                          (merge-pathnames
                           (parse-namestring c)
                           (make-pathname :type "lisp"
                                          :defaults *clim-directory*)))
                if (stringp c)
		  collect `(:file ,(pathname-name p) :pathname ,p)
                else
                  collect c)))))

(groveling-defsystem (:clim-lisp/serial)
  "patch"
  #.(fix)
  "package")

(groveling-defsystem (:clim-basic/serial
                 :depends-on (:clim-lisp/serial :spatial-trees :flexichain))
   "decls"
   "protocol-classes"
   #.(mp)
   "utils"
   "defresource"
   "setf-star"
   
   "design"
   "X11-colors"
   "coordinates"
   "transforms"
   "regions"

   "sheets"
   "pixmap"
   
   "events"

   "ports"
   "grafts"
   "medium"
   "output"

   "input"
   "repaint"
   "graphics"
   "views"
   "stream-output"
   "recording"
   "encapsulate"
   "stream-input"
   "text-selection"
   "bezier"
)

(groveling-defsystem (:goatee-core/serial :depends-on (:clim-basic/serial))
  "Goatee/conditions"
  "Goatee/dbl-list"
  "Goatee/flexivector"
  "Goatee/buffer"
  "Goatee/editable-buffer"
  "Goatee/editable-area"
  "Goatee/clim-area"
  "Goatee/kill-ring"
  "Goatee/goatee-command"
  "Goatee/editing-stream"
  "Goatee/presentation-history"
  )

(groveling-defsystem (:clim-core/serial :depends-on
                                        (:clim-basic/serial :goatee-core/serial
                                                            :clim-postscript/grovel))
  "text-formatting"
  "input-editing"
  "presentations"
  "presentation-defs"
  "pointer-tracking"
  "commands"
  "incremental-redisplay"
  "frames"
  "panes"
  "gadgets"
  "menu"
  "table-formatting"
  "graph-formatting"
  "bordered-output"
  "dialog-views"
  "dialog"
  "builtin-commands"
  "describe"
  "menu-choose"
  )

(groveling-defsystem (:esa-mcclim/serial
                      :depends-on (:clim-core/serial))
  "ESA/packages"
  "ESA/utils"
  "ESA/esa"
  "ESA/esa-buffer"
  "ESA/esa-io"
  "ESA/esa-command-parser"
  "ESA/colors")



(groveling-defsystem (:drei-mcclim/serial
                      :depends-on (:flexichain :esa-mcclim/serial :clim-core/serial))
  "Drei/cl-automaton/automaton-package"
  "Drei/cl-automaton/eqv-hash"
  "Drei/cl-automaton/state-and-transition"
  "Drei/cl-automaton/automaton"
  "Drei/cl-automaton/regexp"
  
  "Drei/Persistent/binseq-package"
  "Drei/Persistent/binseq"
  "Drei/Persistent/obinseq"
  "Drei/Persistent/binseq2"

  "Drei/packages"
  "Drei/buffer"
  "Drei/Persistent/persistent-buffer"
  "Drei/kill-ring"
  "Drei/base"
  "Drei/syntax"
  "Drei/motion"
  "Drei/editing"
  "Drei/abbrev"
  "Drei/undo"
  "Drei/delegating-buffer"
  "Drei/Persistent/persistent-undo"
  "Drei/drei"
  "Drei/core"
  "Drei/buffer-streams"
  "Drei/rectangle"
  "Drei/drei-clim"
  "Drei/core-commands"
  "Drei/drei-redisplay"
  "Drei/basic-commands"
  "Drei/misc-commands"
  "Drei/unicode-commands"
  "Drei/search-commands"
  "Drei/fundamental-syntax"
  "Drei/lisp-syntax"
  "Drei/input-editor"
  "Drei/lisp-syntax-swine"
  "Drei/lisp-syntax-commands")

(groveling-defsystem (:clim-postscript/grovel
                      :depends-on (:clim-basic/serial)
                      :serial nil)
  "Backends/PostScript/package"
  "Backends/PostScript/encoding"
  "Backends/PostScript/paper"
  "Backends/PostScript/class"
  "Backends/PostScript/font"
  "Backends/PostScript/graphics"
  "Backends/PostScript/sheet"
  "Backends/PostScript/afm"
  "Backends/PostScript/standard-metrics")

(groveling-defsystem (:clim/serial
                      :depends-on (:clim-core/serial :goatee-core/serial
                                                     :drei-mcclim/serial))
  "input-editing-goatee"
  "input-editing-drei"
  "text-editor-gadget"
  "Extensions/rgb-image")



;;;; the dependency system

(asdf:defsystem :mcclim-dependencies
  :components
  ((component-file "mcclim"
                   :output-file #.(merge-pathnames #p"clim-components.lisp-expr"
                                                   *clim-directory*)
                   :load-system :clim/serial
                   :merge-systems (:clim-lisp/serial :clim-basic/serial :clim-core/serial :clim/serial
                                                     :goatee-core/serial :esa-mcclim/serial
                                                     :drei-mcclim/serial :clim-postscript/grovel)
                   :additional-dependencies (("\"package\"" "\"patch\"" "#.(fix)"))
                   :component-name-translation
                   ((#.(format nil "~S" (fix))
                     "#.(fix)"
                     "#.(fix) :pathname #.(make-pathname :directory '(:relative \"Lisp-Dep\") :name (fix \"\") :type \"lisp\")")
                    (#.(format nil "~S" (mp))
                     "#.(mp)"
                     "#.(mp) :pathname #.(make-pathname :directory '(:relative \"Lisp-Dep\") :name (mp \"\") :type \"lisp\")"))
                   :cull-redundant t
                   :verbose nil)))