make-deps.el (2534B)
1 ;;; make-deps.el --- compute make dependencies for Elisp sources -*- lexical-binding: t -*- 2 ;; 3 ;; Copyright © Austin Clements 4 ;; 5 ;; This file is part of Notmuch. 6 ;; 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. 11 ;; 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. 16 ;; 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/>. 19 ;; 20 ;; Authors: Austin Clements <aclements@csail.mit.edu> 21 22 ;;; Code: 23 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)) 31 (kill-emacs)) 32 33 (defun make-deps (&optional dir) 34 "Print make dependencies for the current buffer. 35 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'." 39 (unless dir 40 (setq dir default-directory)) 41 (save-excursion 42 (goto-char (point-min)) 43 (condition-case nil 44 (while t 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. 58 (when (and fname 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))))))))) 67 (end-of-file nil)))) 68 69 ;;; make-deps.el ends here