1 ;; make-deps.el --- compute make dependencies for Elisp sources
3 ;; Copyright © Austin Clements
5 ;; This file is part of Notmuch.
7 ;; Notmuch is free software: you can redistribute it and/or modify it
8 ;; under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; Notmuch is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with Notmuch. If not, see <https://www.gnu.org/licenses/>.
20 ;; Authors: Austin Clements <aclements@csail.mit.edu>
24 (defun batch-make-deps ()
25 "Invoke `make-deps' for each file on the command line."
27 (setq debug-on-error t)
28 (dolist (file command-line-args-left)
29 (let ((default-directory command-line-default-directory))
30 (find-file-literally file))
31 (make-deps command-line-default-directory))
34 (defun make-deps (&optional dir)
35 "Print make dependencies for the current buffer.
37 This prints make dependencies to `standard-output' based on the
38 top-level `require' expressions in the current buffer. Paths in
39 rules will be given relative to DIR, or `default-directory'."
41 (setq dir (or dir default-directory))
43 (goto-char (point-min))
46 (let ((form (read (current-buffer))))
47 ;; Is it a (require 'x) form?
48 (when (and (listp form) (= (length form) 2)
49 (eq (car form) 'require)
50 (listp (cadr form)) (= (length (cadr form)) 2)
51 (eq (car (cadr form)) 'quote)
52 (symbolp (cadr (cadr form))))
53 ;; Find the required library
54 (let* ((name (cadr (cadr form)))
55 (fname (locate-library (symbol-name name))))
56 ;; Is this file and the library in the same directory?
57 ;; If not, assume it's a system library and don't
58 ;; bother depending on it.
60 (string= (file-name-directory (buffer-file-name))
61 (file-name-directory fname)))
62 ;; Print the dependency
63 (princ (format "%s.elc: %s.elc\n"
64 (file-name-sans-extension
65 (file-relative-name (buffer-file-name) dir))
66 (file-name-sans-extension
67 (file-relative-name fname dir)))))))))
70 ;;; make-deps.el ends here