+(export 'write-dependency-file)
+(defgeneric write-dependency-file (module reason output-dir)
+ (:documentation
+ "Write a dependency-tracking make(1) fragment.
+
+ Specifically, we've processed a MODULE for a particular REASON (a
+ symbol), and the user has requested that output be written to OUTPUT-DIR
+ (a pathname): determine a suitable output pathname and write a make(1)
+ fragment explaining that the output file we've made depends on all of the
+ files we had to read to load the module."))
+
+(defmethod write-dependency-file ((module module) reason output-dir)
+ (let* ((common-case
+ ;; Bletch. We want to derive the filetype from the one we're
+ ;; given, but we need to determine the environment's preferred
+ ;; filetype case to do that. Make a pathname and inspect it to
+ ;; find out how to do this.
+
+ (if (upper-case-p
+ (char (pathname-type (make-pathname
+ :type "TEST"
+ :case :common))
+ 0))
+ #'string-upcase
+ #'string-downcase))
+
+ (outpath (output-type-pathname reason))
+ (deppath (make-pathname :type (concatenate 'string
+ (pathname-type outpath)
+ (funcall common-case
+ "-DEP"))
+ :defaults outpath))
+ (outfile (module-output-file module reason output-dir))
+ (depfile (module-output-file module deppath output-dir)))
+
+ (with-open-file (dep depfile
+ :direction :output
+ :if-exists :supersede
+ :if-does-not-exist :create)
+ (format dep "### -*-makefile-*-~%~
+ ~A:~{ \\~% ~A~}~%"
+ outfile
+ (cons (module-name module)
+ (module-files module))))))
+