Remove old and crusty tooltalk pkg
[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     ("ecb" . "xemacs-packages")
113     ("ecrypto" . "xemacs-packages")
114     ("ede" . "xemacs-packages")
115     ("edebug" . "xemacs-packages")
116     ("ediff" . "xemacs-packages")
117     ("edit-utils" . "xemacs-packages")
118     ("edt" . "xemacs-packages")
119     ("efs" . "xemacs-packages")
120     ("eieio" . "xemacs-packages")
121     ("elib" . "xemacs-packages")
122     ("emerge" . "xemacs-packages")
123     ("erc" . "xemacs-packages")
124     ("eshell" . "xemacs-packages")
125     ("eterm" . "xemacs-packages")
126     ("eudc" . "xemacs-packages")
127     ("escreen" . "xemacs-packages")
128     ("footnote" . "xemacs-packages")
129     ("forms" . "xemacs-packages")
130     ("fortran-modes" . "xemacs-packages")
131     ("frame-icon" . "xemacs-packages")
132     ("fsf-compat" . "xemacs-packages")
133     ("games" . "xemacs-packages")
134     ("general-docs" . "xemacs-packages")
135     ("gnats" . "xemacs-packages")
136     ("gnus" . "xemacs-packages")
137     ("guided-tour" . "xemacs-packages")
138     ("haskell-mode" . "xemacs-packages")
139     ("hm--html-menus" . "xemacs-packages")
140     ("hyperbole" . "xemacs-packages")
141     ("ibuffer" . "xemacs-packages")
142     ("idlwave" . "xemacs-packages")
143     ("igrep" . "xemacs-packages")
144     ("ilisp" . "xemacs-packages")
145     ("ispell" . "xemacs-packages")
146     ("jde" . "xemacs-packages")
147     ("mail-lib" . "xemacs-packages")
148     ("mailcrypt" . "xemacs-packages")
149     ("mew" . "xemacs-packages")
150     ("mh-e" . "xemacs-packages")
151     ("mine" . "xemacs-packages")
152     ("misc-games" . "xemacs-packages")
153     ("mmm-mode" . "xemacs-packages")
154     ("net-utils" . "xemacs-packages")
155     ("ocaml" . "xemacs-packages")
156     ("oo-browser" . "xemacs-packages")
157     ("os-utils" . "xemacs-packages")
158     ("pc" . "xemacs-packages")
159     ("pcl-cvs" . "xemacs-packages")
160     ("pcomplete" . "xemacs-packages")
161     ("perl-modes" . "xemacs-packages")
162     ("pgg" . "xemacs-packages")
163     ("prog-modes" . "xemacs-packages")
164     ("ps-print" . "xemacs-packages")
165     ("psgml" . "xemacs-packages")
166     ("psgml-dtds" . "xemacs-packages")
167     ("python-modes" . "xemacs-packages")
168     ("re-builder" . "xemacs-packages")
169     ("reftex" . "xemacs-packages")
170     ("riece" . "xemacs-packages")
171     ("rmail" . "xemacs-packages")
172     ("ruby-modes" . "xemacs-packages")
173     ("sasl" . "xemacs-packages")
174     ("scheme" . "xemacs-packages")
175     ("semantic" . "xemacs-packages")
176     ("sgml" . "xemacs-packages")
177     ("sh-script" . "xemacs-packages")
178     ("sieve" . "xemacs-packages")
179     ("slider" . "xemacs-packages")
180     ("sml-mode" . "xemacs-packages")
181     ("sounds-au" . "xemacs-packages")
182     ("sounds-wav" . "xemacs-packages")
183     ("speedbar" . "xemacs-packages")
184     ("strokes" . "xemacs-packages")
185     ("supercite" . "xemacs-packages")
186     ("texinfo" . "xemacs-packages")
187     ("text-modes" . "xemacs-packages")
188     ("textools" . "xemacs-packages")
189     ("time" . "xemacs-packages")
190     ("tm" . "xemacs-packages")
191     ("tpu" . "xemacs-packages")
192     ("tramp" . "xemacs-packages")
193     ("vc" . "xemacs-packages")
194     ("vc-cc" . "xemacs-packages")
195     ("vhdl" . "xemacs-packages")
196     ("view-process" . "xemacs-packages")
197     ("viper" . "xemacs-packages")
198     ("vm" . "xemacs-packages")
199     ("w3" . "xemacs-packages")
200     ("x-symbol" . "xemacs-packages")
201     ("xemacs-base" . "xemacs-packages")
202     ("xemacs-devel" . "xemacs-packages")
203     ("xetla" . "xemacs-packages")
204     ("xlib" . "xemacs-packages")
205     ("xslide" . "xemacs-packages")
206     ("xslt-process" . "xemacs-packages")
207     ("xwem" . "xemacs-packages")
208     ("zenirc" . "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 "jde")
239                (equal package "lookup")
240                (equal package "mule-ucs")
241                (equal package "tramp")
242                (equal package "vm")
243                (equal package "w3")
244                (equal package "x-symbol")
245                (equal package "xlib")
246                (equal package "xwem"))
247            (list (expand-file-name "lisp" (file-name-as-directory dir))))
248           ((equal package "mew")
249            (list (expand-file-name "mew" (file-name-as-directory dir))))
250           ((equal package "zenirc")
251            (list (expand-file-name "src" (file-name-as-directory dir))))
252           ((equal package "semantic")
253            (list dir
254                  (expand-file-name "bovine" (file-name-as-directory dir))
255                  (expand-file-name "wisent" (file-name-as-directory dir))))
256           (t (list dir)))))
257
258 (defvar depends nil)
259 (defvar command-line-args-left)
260
261 (while (and command-line-args-left
262             (not (equal "--" (car command-line-args-left))))
263   (push (car command-line-args-left) depends)
264   (pop command-line-args-left))
265
266 (when command-line-args-left
267   (pop command-line-args-left))
268
269 ;; Setup load-path, data-directory-list and load necessary auto-autoloads
270 (while depends
271   (let ((dirs (package-name-to-directories (car depends))))
272     (when (null dirs)
273       (error "%s is not in `package-directory-map'.  See: package-compile.el"
274              (car depends)))
275     (let* ((dir (car dirs))
276            (etc-dir (expand-file-name "etc" dir)))
277       (while dirs
278         (push (car dirs) load-path)
279         (setq dirs (cdr dirs)))
280       ;; This assumes package has layout *-packages/package/etc/package
281       ;; This is the case for the only package it matters at the time or writing
282       ;; which is ps-print
283       (if (file-directory-p (expand-file-name (car depends) etc-dir))
284           (push (file-name-as-directory etc-dir) data-directory-list))
285       (load (expand-file-name "auto-autoloads" dir))
286       (pop depends))))
287
288 ;; Lastly, add the current directory
289 (push default-directory load-path)
290
291 ;; Let it be known we are running under special circomstances
292 (defvar bootstrap-in-progress t)
293
294 ;;; Step 3, perform the requested bytecompilation
295
296 ;; (message "datadirs = %s" data-directory-list)
297
298 ;; (prin1 "Load path = ")
299 ;; (prin1 load-path)
300 ;; (terpri)
301
302 ;; Let the caller specify command
303 ;(batch-byte-compile)
304
305 ;; See comment at top of file.
306 ;; #### Let's see whether we actually need this.
307 ;;(setq load-ignore-elc-files t)
308
309 (provide 'package-compile)
310
311 ;;; package-compile.el ends here