1 ;;; make-deps.el --- compute make dependencies for Elisp sources -*- lexical-binding: t -*-
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."
26 (setq debug-on-error t)
27 (dolist (file command-line-args-left)
28 (let ((default-directory command-line-default-directory))
29 (find-file-literally file))
30 (make-deps command-line-default-directory))
33 (defun make-deps (&optional dir)
34 "Print make dependencies for the current buffer.
36 This prints make dependencies to `standard-output' based on the
37 top-level `require' expressions in the current buffer. Paths in
38 rules will be given relative to DIR, or `default-directory'."
40 (setq dir default-directory))
42 (goto-char (point-min))
45 (let ((form (read (current-buffer))))
46 ;; Is it a (require 'x) form?
47 (when (and (listp form) (= (length form) 2)
48 (eq (car form) 'require)
49 (listp (cadr form)) (= (length (cadr form)) 2)
50 (eq (car (cadr form)) 'quote)
51 (symbolp (cadr (cadr form))))
52 ;; Find the required library
53 (let* ((name (cadr (cadr form)))
54 (fname (locate-library (symbol-name name))))
55 ;; Is this file and the library in the same directory?
56 ;; If not, assume it's a system library and don't
57 ;; bother depending on it.
59 (string= (file-name-directory (buffer-file-name))
60 (file-name-directory fname)))
61 ;; Print the dependency
62 (princ (format "%s.elc: %s.elc\n"
63 (file-name-sans-extension
64 (file-relative-name (buffer-file-name) dir))
65 (file-name-sans-extension
66 (file-relative-name fname dir)))))))))
69 ;;; make-deps.el ends here