vc -- Build fix.
[packages] / package-compile.el
1 ;;; package-compile.el --- Bytecompiler wrapper for building packages from source
2
3 ;; Copyright (C) 1998 by Free Software Foundation, Inc.
4 ;; Copyright (C) 2002 Ben Wing.
5
6 ;; Author: SL Baur <steve@xemacs.org>
7 ;; Keywords: internal, lisp
8
9 ;; This file is part of XEmacs.
10
11 ;; XEmacs is free software; you can redistribute it and/or modify it
12 ;; under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; XEmacs is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs; see the file COPYING.  If not, write to the Free
23 ;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 ;; 02111-1301, USA.
25
26 ;;; Synched up with: Not in FSF
27
28 ;;; Commentary:
29
30 ;; This is meant to be called -batch and handles setting up the loadpath
31 ;; and minimizing what autoloads are imported.
32
33 ;; This package cannot be used with an XEmacs binary that was built with
34 ;; backwards compatible lisp directories.
35
36 ;;; Code:
37
38 (setq stack-trace-on-error t)
39 ;; #### We ought to set load-ignore-elc-files here.  However, that causes
40 ;; a crash when loading auto-autoload files, for obscure reasons that I
41 ;; haven't yet tracked down.  So we set it down below, after all the
42 ;; auto-autoloads have been loaded.
43 ;;
44 ;; Using load-ignore-elc-files is the ONLY way to ensure that compilation
45 ;; of the package tree proceeds properly regardless of the state of .elc
46 ;; files wrt .el files. (Of course, another solution would be to simply
47 ;; erase all .elc files; but this is less drastic.) Using
48 ;; load-ignore-out-of-date-elc-files is a start, but not enough -- it's
49 ;; possible, for example, for a .elc file that gets loaded to be out of
50 ;; date even if its date is later than its .el file.  This happens, for
51 ;; example, with a file containing top-level calls to macros located in
52 ;; another file -- if the macros are changed in the other file, the .elc
53 ;; file will be out of date because it will contain the old macros.
54 ;; Loading the .el file (ala `load-ignore-elc-files') works, since the new
55 ;; macros will be retrieved on-the-fly when the macro is first called.
56 (setq load-ignore-out-of-date-elc-files t)
57 (setq load-always-display-messages t)
58 ;; Don't enable this by default, as it clutters up the output so much.
59 ;; Turn it on if you're doubtful that the right files are being loaded.
60 ;; (setq load-show-full-path-in-messages t)
61
62 (when (interactive-p)
63   (error "package-compile may only be used with -batch"))
64
65 ;;; Step 1, set the load-path and load the core autoloads.
66
67 (let ((depth (cond
68               ;; #### All hail Mr. Preprocessor!
69               ;; OK, OK, his code is under development; FIXME when it's done.
70               ((boundp 'paths-load-path-depth) ; XEmacs 21.1
71                paths-load-path-depth)
72               ((boundp 'paths-core-load-path-depth) ; XEmacs > 21.2.41
73                paths-core-load-path-depth)
74               (t (error "Somebody has been messing with paths-find-*!")))))
75   (setq load-path (paths-find-recursive-load-path
76                    (cons lisp-directory
77                          ;; Only pay attention to mule-lisp-directory if
78                          ;; it's non-nil.
79                          (and mule-lisp-directory (list mule-lisp-directory)))
80                    depth)))
81
82 (load (expand-file-name "auto-autoloads" (car load-path)))
83
84
85 ;;; Step 2, collect the dependencies into load-path and load the autoloads.
86 (let ((load-ignore-elc-files nil)
87       (load-ignore-out-of-date-elc-files t))
88   ;; Make sure we get the compiled version of the byte compiler, otherwise
89   ;; compilation will be UNGODLY slow.
90   (require 'bytecomp)
91   (require 'byte-optimize))
92
93 (defconst package-directory-map
94   '(
95     ;; xemacs-packages
96     ("ada" . "xemacs-packages")
97     ("apel" . "xemacs-packages")
98     ("auctex" . "xemacs-packages")
99     ("bbdb" . "xemacs-packages")
100     ("c-support" . "xemacs-packages")
101     ("calc" . "xemacs-packages")
102     ("calendar" . "xemacs-packages")
103     ("cc-mode" . "xemacs-packages")
104     ("cedet-common" . "xemacs-packages")
105     ("cogre" . "xemacs-packages")
106     ("cookie" . "xemacs-packages")
107     ("crisp" . "xemacs-packages")
108     ("debug" . "xemacs-packages")
109     ("docbookide" . "xemacs-packages")
110     ("dictionary" . "xemacs-packages")
111     ("dired" . "xemacs-packages")
112     ("easypg" . "xemacs-packages")
113     ("ecb" . "xemacs-packages")
114     ("ecrypto" . "xemacs-packages")
115     ("ede" . "xemacs-packages")
116     ("edebug" . "xemacs-packages")
117     ("ediff" . "xemacs-packages")
118     ("edit-utils" . "xemacs-packages")
119     ("edt" . "xemacs-packages")
120     ("efs" . "xemacs-packages")
121     ("eieio" . "xemacs-packages")
122     ("elib" . "xemacs-packages")
123     ("emerge" . "xemacs-packages")
124     ("erc" . "xemacs-packages")
125     ("eshell" . "xemacs-packages")
126     ("ess" . "xemacs-packages")
127     ("eterm" . "xemacs-packages")
128     ("eudc" . "xemacs-packages")
129     ("escreen" . "xemacs-packages")
130     ("footnote" . "xemacs-packages")
131     ("forms" . "xemacs-packages")
132     ("fortran-modes" . "xemacs-packages")
133     ("frame-icon" . "xemacs-packages")
134     ("fsf-compat" . "xemacs-packages")
135     ("games" . "xemacs-packages")
136     ("general-docs" . "xemacs-packages")
137     ("gnats" . "xemacs-packages")
138     ("gnus" . "xemacs-packages")
139     ("guided-tour" . "xemacs-packages")
140     ("haskell-mode" . "xemacs-packages")
141     ("hm--html-menus" . "xemacs-packages")
142     ("hyperbole" . "xemacs-packages")
143     ("ibuffer" . "xemacs-packages")
144     ("idlwave" . "xemacs-packages")
145     ("igrep" . "xemacs-packages")
146     ("ilisp" . "xemacs-packages")
147     ("ispell" . "xemacs-packages")
148     ("jde" . "xemacs-packages")
149     ("mail-lib" . "xemacs-packages")
150     ("mailcrypt" . "xemacs-packages")
151     ("mew" . "xemacs-packages")
152     ("mh-e" . "xemacs-packages")
153     ("mine" . "xemacs-packages")
154     ("misc-games" . "xemacs-packages")
155     ("mmm-mode" . "xemacs-packages")
156     ("net-utils" . "xemacs-packages")
157     ("ocaml" . "xemacs-packages")
158     ("oo-browser" . "xemacs-packages")
159     ("os-utils" . "xemacs-packages")
160     ("patcher" . "xemacs-packages")
161     ("pc" . "xemacs-packages")
162     ("pcl-cvs" . "xemacs-packages")
163     ("pcomplete" . "xemacs-packages")
164     ("perl-modes" . "xemacs-packages")
165     ("pgg" . "xemacs-packages")
166     ("prog-modes" . "xemacs-packages")
167     ("ps-print" . "xemacs-packages")
168     ("psgml" . "xemacs-packages")
169     ("psgml-dtds" . "xemacs-packages")
170     ("python-modes" . "xemacs-packages")
171     ("re-builder" . "xemacs-packages")
172     ("reftex" . "xemacs-packages")
173     ("riece" . "xemacs-packages")
174     ("rmail" . "xemacs-packages")
175     ("ruby-modes" . "xemacs-packages")
176     ("sasl" . "xemacs-packages")
177     ("scheme" . "xemacs-packages")
178     ("semantic" . "xemacs-packages")
179     ("sgml" . "xemacs-packages")
180     ("sh-script" . "xemacs-packages")
181     ("sieve" . "xemacs-packages")
182     ("slider" . "xemacs-packages")
183     ("sml-mode" . "xemacs-packages")
184     ("sounds-au" . "xemacs-packages")
185     ("sounds-wav" . "xemacs-packages")
186     ("speedbar" . "xemacs-packages")
187     ("strokes" . "xemacs-packages")
188     ("supercite" . "xemacs-packages")
189     ("texinfo" . "xemacs-packages")
190     ("text-modes" . "xemacs-packages")
191     ("textools" . "xemacs-packages")
192     ("time" . "xemacs-packages")
193     ("tm" . "xemacs-packages")
194     ("tpu" . "xemacs-packages")
195     ("tramp" . "xemacs-packages")
196     ("vc" . "xemacs-packages")
197     ("vhdl" . "xemacs-packages")
198     ("view-process" . "xemacs-packages")
199     ("viper" . "xemacs-packages")
200     ("vm" . "xemacs-packages")
201     ("w3" . "xemacs-packages")
202     ("x-symbol" . "xemacs-packages")
203     ("xemacs-base" . "xemacs-packages")
204     ("xemacs-devel" . "xemacs-packages")
205     ("xlib" . "xemacs-packages")
206     ("xslide" . "xemacs-packages")
207     ("xslt-process" . "xemacs-packages")
208     ("xwem" . "xemacs-packages")
209     ;; mule-packages
210     ("edict" . "mule-packages")
211     ("egg-its" . "mule-packages")
212     ("latin-euro-standards" . "mule-packages")
213     ("latin-unity" . "mule-packages")
214     ("leim" . "mule-packages")
215     ("locale" . "mule-packages")
216     ("lookup" . "mule-packages")
217     ("mule-base" . "mule-packages")
218     ("mule-ucs" . "mule-packages")
219     ("skk" . "mule-packages")
220     ))
221
222 (defvar package-source-root nil)
223 (let ((defdir default-directory))
224   (while (not (file-exists-p (expand-file-name "XEmacs.rules" defdir)))
225     (setq defdir (expand-file-name (concat defdir "/.."))))
226   (setq package-source-root defdir))
227
228 (defun package-name-to-directories (package)
229   "Map `package' to a source directory."
230   (let* ((area (or (cdr (assoc package package-directory-map))
231                    (error (concat "%s is not in `package-directory-map'.  "
232                                   "See: package-compile.el")
233                           package)))
234          (dir (expand-file-name
235               package (expand-file-name area package-source-root))))
236     (cond ((or (equal package "bbdb") 
237                (equal package "gnus")
238                (equal package "ess")
239                (equal package "jde")
240                (equal package "lookup")
241                (equal package "mule-ucs")
242                (equal package "patcher")
243                (equal package "riece")
244                (equal package "tramp")
245                (equal package "vm")
246                (equal package "w3")
247                (equal package "x-symbol")
248                (equal package "xlib")
249                (equal package "xwem"))
250            (list (expand-file-name "lisp" (file-name-as-directory dir))))
251           ((equal package "mew")
252            (list (expand-file-name "mew" (file-name-as-directory dir))))
253           ((equal package "semantic")
254            (list dir
255                  (expand-file-name "bovine" (file-name-as-directory dir))
256                  (expand-file-name "wisent" (file-name-as-directory dir))))
257           (t (list dir)))))
258
259 (defvar depends nil)
260 (defvar command-line-args-left)
261
262 (while (and command-line-args-left
263             (not (equal "--" (car command-line-args-left))))
264   (push (car command-line-args-left) depends)
265   (pop command-line-args-left))
266
267 (when command-line-args-left
268   (pop command-line-args-left))
269
270 ;; Setup load-path, data-directory-list and load necessary auto-autoloads
271 (while depends
272   (let ((dirs (package-name-to-directories (car depends))))
273     (when (null dirs)
274       (error "%s is not in `package-directory-map'.  See: package-compile.el"
275              (car depends)))
276     (let* ((dir (car dirs))
277            (etc-dir (expand-file-name "etc" dir)))
278       (while dirs
279         (push (car dirs) load-path)
280         (setq dirs (cdr dirs)))
281       ;; This assumes package has layout *-packages/package/etc/package
282       ;; This is the case for the only package it matters at the time or writing
283       ;; which is ps-print
284       (if (file-directory-p (expand-file-name (car depends) etc-dir))
285           (push (file-name-as-directory etc-dir) data-directory-list))
286       (load (expand-file-name "auto-autoloads" dir))
287       (pop depends))))
288
289 ;; Lastly, add the current directory
290 (push default-directory load-path)
291
292 ;; Let it be known we are running under special circomstances
293 (defvar bootstrap-in-progress t)
294
295 ;;; Step 3, perform the requested bytecompilation
296
297 ;; (message "datadirs = %s" data-directory-list)
298
299 ;; (prin1 "Load path = ")
300 ;; (prin1 load-path)
301 ;; (terpri)
302
303 ;; Let the caller specify command
304 ;(batch-byte-compile)
305
306 ;; See comment at top of file.
307 ;; #### Let's see whether we actually need this.
308 ;;(setq load-ignore-elc-files t)
309
310 (provide 'package-compile)
311
312 ;;; package-compile.el ends here