Merge remote-tracking branch 'origin/master' into for-steve
[sxemacs] / lisp / compile-core.el
1 ;;; compile-core.el --- Bytecompile out-of-date dumped files
2 ;;
3 ;; Copyright (C) 2006 Sebastian Freundt
4 ;;
5 ;; Author: Sebastian Freundt <hroptatyr@sxemacs.org>
6 ;; Maintainer: SXEmacs Development Team
7 ;; Keywords: internal
8 ;;
9 ;; This file is part of SXEmacs.
10 ;;
11 ;; SXEmacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
15
16 ;; SXEmacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
23 ;;
24 ;;; Synched up with: Not in FSF.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (load "loadup-el.el")
31 (load "auto-autoloads.el")
32 (load "custom-defines.el")
33 (load "bytecomp.el")
34 (load "byte-optimize.el")
35 (when (featurep '(and mule (not mule-autoloads)))
36   (load-file "mule/auto-autoloads.el")
37   (load-file "mule/custom-defines.el"))
38 (when (and (fboundp #'ffi-defun)
39            (not (featurep 'ffi-autoloads)))
40   (load-file "ffi/auto-autoloads.el")
41   (load-file "ffi/custom-defines.el"))
42
43 (princ "Compiling core lisp files...")
44
45 (defvar destdir
46   default-directory)
47 (defvar sourcedir
48   (file-name-directory (locate-file "compile-core.el" load-path)))
49 (defvar lispdir-regexp
50   (compile-regexp "lisp/"))
51
52 (defun byte-compile-dest-file (filename)
53   "Convert an Emacs Lisp source file name to a compiled file name."
54   (let ((outfile (if (string-match lispdir-regexp filename)
55                      (file-name-sans-extension
56                       (substring filename (match-end 0)))
57                    filename)))
58     (expand-file-name (concat outfile ".elc") destdir)))
59
60 (defun parse-command-line (cmdl)
61   (let ((newcmdl (dllist))
62         (cmdlpl (make-skiplist))
63         (mm (compile-regexp "^--"))
64         (ign (compile-regexp "^-[^-]")))
65     (while (car cmdl)
66       (let* ((file (car cmdl))
67              (current (expand-file-name file sourcedir))
68              (current (if (file-exists-p current)
69                           current
70                         (expand-file-name file destdir))))
71         (cond ((string-match mm file)
72                (let ((key (intern file))
73                      (val (car (cdr-safe cmdl))))
74                  (put-skiplist cmdlpl key val)
75                  (setq cmdl (cdr-safe cmdl))))
76               ((string-match ign file)
77                (setq cmdl (cdr-safe cmdl)))
78               ((string-match emacs-lisp-file-regexp current)
79                (dllist-append newcmdl current))
80               (t nil)))
81       (setq cmdl (cdr-safe cmdl)))
82     (put newcmdl :tweaks cmdlpl)
83     newcmdl))
84
85 (setq files (parse-command-line (cdr-safe command-line-args)))
86 (setq params (get files :tweaks))
87
88 (setq files-to-compile (dllist))
89 (if (get-skiplist params '--force)
90     (setq files-to-compile files)
91   (mapc-internal
92    #'(lambda (file)
93        (when (file-newer-than-file-p file (byte-compile-dest-file file))
94          (dllist-append files-to-compile file)))
95    files))
96
97 (setq problem-files (dllist))
98 (mapc-internal
99  #'(lambda (file)
100      (condition-case nil
101          (byte-compile-file file)
102        (error
103         (progn
104           (dllist-append problem-files file)
105           (message "Dinn work: %s" file)))))
106  files-to-compile)
107
108 ;; (mapc-internal
109 ;;  #'(lambda (file)
110 ;;      (condition-case nil
111 ;;          (byte-compile-file file)
112 ;;        (error
113 ;;         (progn
114 ;;           (dllist-append problem-files file)
115 ;;           (message "Dinn work: %s" file)))))
116 ;;  problem-files)
117
118 ;;; compile-core.el ends here