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 <http://www.gnu.org/licenses/>.
20 ;; Authors: Austin Clements <aclements@csail.mit.edu>
22 (defun batch-make-deps ()
23 "Invoke `make-deps' for each file on the command line."
25 (setq debug-on-error t)
26 (dolist (file command-line-args-left)
27 (let ((default-directory command-line-default-directory))
28 (find-file-literally file))
29 (make-deps command-line-default-directory))
32 (defun make-deps (&optional dir)
33 "Print make dependencies for the current buffer.
35 This prints make dependencies to `standard-output' based on the
36 top-level `require' expressions in the current buffer. Paths in
37 rules will be given relative to DIR, or `default-directory'."
39 (setq dir (or dir default-directory))
41 (goto-char (point-min))
44 (let ((form (read (current-buffer))))
45 ;; Is it a (require 'x) form?
46 (when (and (listp form) (= (length form) 2)
47 (eq (car form) 'require)
48 (listp (cadr form)) (= (length (cadr form)) 2)
49 (eq (car (cadr form)) 'quote)
50 (symbolp (cadr (cadr form))))
51 ;; Find the required library
52 (let* ((name (cadr (cadr form)))
53 (fname (locate-library (symbol-name name))))
54 ;; Is this file and the library in the same directory?
55 ;; If not, assume it's a system library and don't
56 ;; bother depending on it.
58 (string= (file-name-directory (buffer-file-name))
59 (file-name-directory fname)))
60 ;; Print the dependency
61 (princ (format "%s.elc: %s.elc\n"
62 (file-name-sans-extension
63 (file-relative-name (buffer-file-name) dir))
64 (file-name-sans-extension
65 (file-relative-name fname dir)))))))))