1 ;;; update-elc-2.el --- Recompile remaining .el files, post-dumping
3 ;; Copyright (C) 1997 by Free Software Foundation, Inc.
4 ;; Copyright (C) 2000 Ben Wing.
6 ;; Author: Ben Wing <ben@xemacs.org>, based on cleantree.el by
7 ;; Steven L Baur <steve@xemacs.org>
8 ;; Maintainer: XEmacs Development Team
11 ;; This file is part of XEmacs.
13 ;; XEmacs is free software; you can redistribute it and/or modify it
14 ;; under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; XEmacs is distributed in the hope that it will be useful, but
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 ;; General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with XEmacs; see the file COPYING. If not, write to the Free
25 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 ;;; Synched up with: Not in FSF
32 ;; This file should be used after XEmacs has been dumped, to recompile
33 ;; all remaining out-of-date .els and clean up orphaned .elcs. It should
36 ;; xemacs -batch -vanilla -l update-elc-2.el -f batch-update-elc-2 ${dirname}
38 ;; where ${dirname} is the directory tree to recompile, usually `lisp'.
40 ;; Note that this is very different from update-elc.el, which is called
41 ;; BEFORE dumping, handles only the files needed to dump, and is called
42 ;; from temacs instead of xemacs.
44 ;; The original cleantree.el had the comment: This code is derived
45 ;; from Gnus based on a suggestion by David Moore <dmoore@ucsd.edu>
49 (defvar update-elc-ignored-dirs
50 `("." ".." "CVS" "SCCS" "RCS" ,@(unless (featurep 'mule) '("mule"))))
52 (defvar update-elc-ignored-files
53 ;; note: entries here are regexps
66 "^very-early-lisp\\.el$"))
68 ;; SEEN accumulates the list of already-handled dirs.
69 (defun do-update-elc-2 (dir compile-stage-p seen)
70 (setq dir (file-name-as-directory dir))
71 ;; Only scan this sub-tree if we haven't been here yet.
72 (unless (member (file-truename dir) seen)
73 (push (file-truename dir) seen)
77 ;; Stage 2: Recompile necessary .els
78 (let ((files (directory-files dir t "\\.el$"))
80 (while (setq file (car files))
81 (setq files (cdr files))
82 (setq file-c (concat file "c"))
83 (when (and (file-exists-p file)
84 (or (not (file-exists-p file-c))
85 (file-newer-than-file-p file file-c))
89 (if (string-match regexp
90 (file-name-nondirectory file))
92 update-elc-ignored-files)
94 (byte-compile-file file))))
97 ;; Remove out-of-date elcs
98 (let ((files (directory-files dir t "\\.el$"))
100 (while (setq file (car files))
101 (setq files (cdr files))
102 (setq file-c (concat file "c"))
103 (when (and (file-exists-p file-c)
104 (file-newer-than-file-p file file-c))
105 (message "Removing out-of-date %s" file-c)
106 (delete-file file-c))))
107 ;; Remove elcs without corresponding el
108 (let ((files (directory-files dir t "\\.elc$"))
110 (while (setq file-c (car files))
111 (setq files (cdr files))
112 (setq file (replace-in-string file-c "c$" ""))
113 (when (and (file-exists-p file-c)
114 (not (file-exists-p file)))
115 (message "Removing %s; no corresponding .el" file-c)
116 (delete-file file-c))))
118 ;; We descend recursively
119 (let ((dirs (directory-files dir t nil t))
121 (while (setq dir (pop dirs))
122 (when (and (not (member (file-name-nondirectory dir)
123 update-elc-ignored-dirs))
124 (file-directory-p dir))
125 (do-update-elc-2 dir compile-stage-p seen))))
130 (defun batch-update-elc-2 ()
131 (defvar command-line-args-left)
132 (unless noninteractive
133 (error "`batch-update-elc-2' is to be used only with -batch"))
134 (let ((dir (car command-line-args-left)))
135 ;; We remove all the bad .elcs before any byte-compilation, because
136 ;; there may be dependencies between one .el and another (even across
137 ;; directories), and we don't want to load an out-of-date .elc while
138 ;; byte-compiling a file.
139 (message "Removing old or spurious .elcs in directory tree `%s'..." dir)
140 (do-update-elc-2 dir nil nil)
141 (message "Removing old or spurious .elcs in directory tree `%s'...done"
143 (message "Recompiling updated .els in directory tree `%s'..." dir)
144 (do-update-elc-2 dir t nil)
145 (message "Recompiling updated .els in directory tree `%s'...done" dir))
146 (setq command-line-args-left nil))
148 ;;; update-elc-2.el ends here