7dfc4ea742d9f667bc4601182bf07b7264defead
[elisp/gnus.git-] / lisp / dgnushack.el
1 ;;; dgnushack.el --- a hack to set the load path for byte-compiling
2 ;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;;      Katsumi Yamaoka <yamaoka@jpl.org>
7 ;; Version: 4.19
8 ;; Keywords: news, path
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;;; Code:
30
31 ;; Set coding priority of Shift-JIS to the bottom.
32 (if (featurep 'xemacs)
33     (defalias 'set-coding-priority 'ignore)
34   (defalias 'coding-priority-list 'ignore)
35   (defalias 'set-coding-priority-list 'ignore))
36 (cond ((and (featurep 'xemacs) (featurep 'mule))
37        (if (memq 'shift-jis (coding-priority-list))
38            (set-coding-priority-list
39             (append (delq 'shift-jis (coding-priority-list)) '(shift-jis)))))
40       ((featurep 'mule)
41        (if (memq 'coding-category-sjis coding-category-list)
42            (set-coding-priority
43             (append (delq 'coding-category-sjis
44                           (copy-sequence coding-category-list))
45                     '(coding-category-sjis))))))
46
47 (defalias 'facep 'ignore)
48
49 (require 'cl)
50
51 (unless (and
52          ;; `dolist' might not be available because of ``-no-autoloads''.
53          (fboundp 'dolist)
54          ;; It may have been defined in egg.el.
55          (dolist (var nil t)))
56   (load "cl-macs" nil t))
57
58 (defvar srcdir (or (getenv "srcdir") "."))
59
60 (defvar dgnushack-w3-directory (let ((w3dir (getenv "W3DIR")))
61                                  (unless (zerop (length w3dir))
62                                    (file-name-as-directory w3dir))))
63
64 (let ((urldir (getenv "URLDIR")))
65   (unless (zerop (length urldir))
66     (setq urldir (file-name-as-directory urldir))
67     (push (file-name-as-directory urldir) load-path))
68   (when (and dgnushack-w3-directory
69              (not (string-equal urldir dgnushack-w3-directory)))
70     (push dgnushack-w3-directory load-path)))
71
72 ;; If we are building w3 in a different directory than the source
73 ;; directory, we must read *.el from source directory and write *.elc
74 ;; into the building directory.  For that, we define this function
75 ;; before loading bytecomp.  Bytecomp doesn't overwrite this function.
76 (defun byte-compile-dest-file (filename)
77   "Convert an Emacs Lisp source file name to a compiled file name.
78  In addition, remove directory name part from FILENAME."
79   (setq filename (byte-compiler-base-file-name filename))
80   (setq filename (file-name-sans-versions filename))
81   (setq filename (file-name-nondirectory filename))
82   (if (memq system-type '(win32 w32 mswindows windows-nt))
83       (setq filename (downcase filename)))
84   (cond ((eq system-type 'vax-vms)
85          (concat (substring filename 0 (string-match ";" filename)) "c"))
86         ((string-match emacs-lisp-file-regexp filename)
87          (concat (substring filename 0 (match-beginning 0)) ".elc"))
88         (t (concat filename ".elc"))))
89
90 (require 'bytecomp)
91 ;; To avoid having defsubsts and inlines happen.
92 ;(if (featurep 'xemacs)
93 ;    (require 'byte-optimize)
94 ;  (require 'byte-opt))
95 ;(defun byte-optimize-inline-handler (form)
96 ;  "byte-optimize-handler for the `inline' special-form."
97 ;  (cons 'progn (cdr form)))
98 ;(defalias 'byte-compile-file-form-defsubst 'byte-compile-file-form-defun)
99
100 (when (and (not (featurep 'xemacs))
101            (= emacs-major-version 21)
102            (= emacs-minor-version 3)
103            (condition-case code
104                (let ((byte-compile-error-on-warn t))
105                  (byte-optimize-form (quote (pop x)) t)
106                  nil)
107              (error (string-match "called for effect"
108                                   (error-message-string code)))))
109   (defadvice byte-optimize-form-code-walker (around silence-warn-for-pop
110                                                     (form for-effect)
111                                                     activate)
112     "Silence the warning \"...called for effect\" for the `pop' form.
113 It is effective only when the `pop' macro is defined by cl.el rather
114 than subr.el."
115     (let (tmp)
116       (if (and (eq (car-safe form) 'car)
117                for-effect
118                (setq tmp (get 'car 'side-effect-free))
119                (not byte-compile-delete-errors)
120                (not (eq tmp 'error-free))
121                (eq (car-safe (cadr form)) 'prog1)
122                (let ((var (cadr (cadr form)))
123                      (last (nth 2 (cadr form))))
124                  (and (symbolp var)
125                       (null (nthcdr 3 (cadr form)))
126                       (eq (car-safe last) 'setq)
127                       (eq (cadr last) var)
128                       (eq (car-safe (nth 2 last)) 'cdr)
129                       (eq (cadr (nth 2 last)) var))))
130           (progn
131             (put 'car 'side-effect-free 'error-free)
132             (unwind-protect
133                 ad-do-it
134               (put 'car 'side-effect-free tmp)))
135         ad-do-it))))
136
137 (when (and (not (featurep 'xemacs))
138            (byte-optimize-form '(and (> 0 1) foo) t))
139   (defadvice byte-optimize-form-code-walker
140     (around fix-bug-in-and/or-forms (form for-effect) activate)
141     "Optimize the rest of the and/or forms.
142 It has been fixed in XEmacs before releasing 21.4 and also has been
143 fixed in Emacs after 21.3."
144     (if (and for-effect (memq (car-safe form) '(and or)))
145         (let ((fn (car form))
146               (backwards (reverse (cdr form))))
147           (while (and backwards
148                       (null (setcar backwards
149                                     (byte-optimize-form (car backwards) t))))
150             (setq backwards (cdr backwards)))
151           (if (and (cdr form) (null backwards))
152               (byte-compile-log
153                "  all subforms of %s called for effect; deleted" form))
154           (when backwards
155             (setcdr backwards
156                     (mapcar 'byte-optimize-form (cdr backwards))))
157           (setq ad-return-value (cons fn (nreverse backwards))))
158       ad-do-it)))
159
160 ;; Add `early-package-load-path' to `load-path' for XEmacs.  Those paths
161 ;; won't appear in `load-path' when XEmacs starts with the `-no-autoloads'
162 ;; option because of a bug. :<
163 (when (and (featurep 'xemacs)
164            (string-match "--package-path=\\([^ ]+\\)"
165                          system-configuration-options))
166   (let ((paths
167          (apply 'nconc
168                 (mapcar
169                  (lambda (path)
170                    (when (file-directory-p
171                           (setq path (expand-file-name "lisp" path)))
172                      (directory-files path t)))
173                  (split-string (match-string 1 system-configuration-options)
174                                "::"))))
175         path adds)
176     (while paths
177       (setq path (car paths)
178             paths (cdr paths))
179       (when (and path
180                  (not (or (string-match "/\\.\\.?\\'" path)
181                           (member (file-name-as-directory path) load-path)
182                           (member path load-path)))
183                  (file-directory-p path))
184         (push (file-name-as-directory path) adds)))
185     (setq load-path (nconc (nreverse adds) load-path))))
186
187 (if (file-exists-p (expand-file-name "dgnuspath.el" srcdir))
188     (load (expand-file-name "dgnuspath.el" srcdir) nil nil t)
189   (message "  ** There's no dgnuspath.el file"))
190
191 (condition-case err
192     (load "~/.lpath.el" t nil t)
193   (error (message "Error in \"~/.lpath.el\" file: %s" err)))
194
195 ;; Don't load path-util until `char-after' and `char-before' have been
196 ;; optimized because it requires `poe' and then modify the functions.
197
198 ;; If the APEL modules are installed under the non-standard directory,
199 ;; for example "/var/home/john/lisp/apel-VERSION/", you should add that
200 ;; name using the configure option "--with-addpath=".
201 ;; And also the directory where the EMU modules are installed, for
202 ;; example "/usr/local/share/mule/19.34/site-lisp/", it should be
203 ;; included in the standard `load-path' or added by the configure
204 ;; option "--with-addpath=".
205 (let ((path (or (locate-library "path-util")
206                 (locate-library "apel/path-util")));; backward compat.
207       parent lpath)
208   (if path
209       (progn
210         (when (string-match "/$" (setq path (file-name-directory path)))
211           (setq path (substring path 0 (match-beginning 0))))
212         ;; path == "/var/home/john/lisp/apel-VERSION"
213         (when (string-match "/$" (setq parent (file-name-directory path)))
214           (setq parent (substring path 0 (match-beginning 0))))
215         ;; parent == "/var/home/john/lisp"
216         (if (setq lpath (or (member path load-path)
217                             (member (file-name-as-directory path) load-path)))
218             (unless (or (member parent load-path)
219                         (member (file-name-as-directory parent) load-path))
220               (push parent (cdr lpath)))
221           (push path load-path)
222           (unless (or (member parent load-path)
223                       (member (file-name-as-directory parent) load-path))
224             (push parent (cdr load-path))))
225         (require 'advice)
226         (require 'path-util))
227     (error "
228 APEL modules are not found in %s.
229 Try to re-configure with --with-addpath=APEL_PATH and run make again.
230 "
231            load-path)))
232
233 (unless (locate-library "mel")
234   (add-path "flim"))
235 (unless (module-installed-p 'mel)
236   ;; FLIM 1.14 may have installed in two "flim" subdirectories.
237   (push (expand-file-name "flim"
238                           (file-name-directory (get-latest-path "^apel$" t)))
239         load-path)
240   (unless (module-installed-p 'mel)
241     (error "
242 FLIM modules does not found in %s.
243 Try to re-configure with --with-addpath=FLIM_PATH and run make again.
244 "
245            load-path)))
246 (add-path "semi")
247
248 (when (and (featurep 'xemacs)
249            (let ((table (copy-syntax-table emacs-lisp-mode-syntax-table)))
250              (modify-syntax-entry ?= " " table)
251              (with-temp-buffer
252                (with-syntax-table table
253                  (insert "foo=bar")
254                  (goto-char (point-min))
255                  (forward-sexp 1)
256                  (eolp)))))
257   ;; The original `with-syntax-table' uses `copy-syntax-table' which
258   ;; doesn't seem to copy modified syntax entries in XEmacs 21.5.
259   (defmacro with-syntax-table (syntab &rest body)
260     "Evaluate BODY with the SYNTAB as the current syntax table."
261     `(let ((stab (syntax-table)))
262        (unwind-protect
263            (progn
264              ;;(set-syntax-table (copy-syntax-table ,syntab))
265              (set-syntax-table ,syntab)
266              ,@body)
267          (set-syntax-table stab)))))
268
269 (push srcdir load-path)
270 (load (expand-file-name "lpath.el" srcdir) nil t t)
271
272 (require 'custom)
273
274 ;; Bind functions defined by `defun-maybe'.
275 (put 'defun-maybe 'byte-hunk-handler 'byte-compile-file-form-defun-maybe)
276 (defun byte-compile-file-form-defun-maybe (form)
277   (if (and (not (fboundp (nth 1 form)))
278            (memq 'unresolved byte-compile-warnings))
279       (setq byte-compile-function-environment
280             (cons (cons (nth 1 form)
281                         (cons 'lambda (cdr (cdr form))))
282                   byte-compile-function-environment)))
283   form)
284
285 ;; Unknown variables and functions.
286 (unless (featurep 'xemacs)
287   (defalias 'Custom-make-dependencies 'ignore)
288   (defalias 'update-autoloads-from-directory 'ignore))
289
290 (defalias 'device-sound-enabled-p 'ignore)
291 (defalias 'play-sound-file 'ignore)
292 (defalias 'nndb-request-article 'ignore)
293 (defalias 'efs-re-read-dir 'ignore)
294 (defalias 'ange-ftp-re-read-dir 'ignore)
295 (defalias 'define-mail-user-agent 'ignore)
296
297 (eval-and-compile
298   (when (featurep 'xemacs)
299     (unless (fboundp 'defadvice)
300       (autoload 'defadvice "advice" nil nil 'macro))
301     (autoload 'Info-directory "info" nil t)
302     (autoload 'Info-menu "info" nil t)
303     (autoload 'annotations-at "annotations")
304     (autoload 'apropos "apropos" nil t)
305     (autoload 'apropos-command "apropos" nil t)
306     (autoload 'bbdb-complete-name "bbdb-com" nil t)
307     (autoload 'browse-url "browse-url" nil t)
308     (autoload 'customize-apropos "cus-edit" nil t)
309     (autoload 'customize-save-variable "cus-edit" nil t)
310     (autoload 'customize-variable "cus-edit" nil t)
311     (autoload 'delete-annotation "annotations")
312     (autoload 'dolist "cl-macs" nil nil 'macro)
313     (autoload 'enriched-decode "enriched")
314     (autoload 'executable-find "executable")
315     (autoload 'font-lock-fontify-buffer "font-lock" nil t)
316     (autoload 'info "info" nil t)
317     (autoload 'make-annotation "annotations")
318     (autoload 'make-display-table "disp-table")
319     (autoload 'pp "pp")
320     (autoload 'ps-despool "ps-print" nil t)
321     (autoload 'ps-spool-buffer "ps-print" nil t)
322     (autoload 'ps-spool-buffer-with-faces "ps-print" nil t)
323     (autoload 'read-passwd "passwd")
324     (autoload 'regexp-opt "regexp-opt")
325     (autoload 'reporter-submit-bug-report "reporter")
326     (if (emacs-version>= 21 5)
327         (autoload 'setenv "process" nil t)
328       (autoload 'setenv "env" nil t))
329     (autoload 'sgml-mode "psgml" nil t)
330     (autoload 'smtpmail-send-it "smtpmail")
331     (autoload 'sort-numeric-fields "sort" nil t)
332     (autoload 'sort-subr "sort")
333     (autoload 'trace-function-background "trace" nil t)
334     (autoload 'w3-do-setup "w3")
335     (autoload 'w3-prepare-buffer "w3-display")
336     (autoload 'w3-region "w3-display" nil t)
337     (defalias 'frame-char-height 'frame-height)
338     (defalias 'frame-char-width 'frame-width)
339     (defalias 'frame-parameter 'frame-property)
340     (defalias 'make-overlay 'ignore)
341     (defalias 'overlay-end 'ignore)
342     (defalias 'overlay-get 'ignore)
343     (defalias 'overlay-put 'ignore)
344     (defalias 'overlay-start 'ignore)
345     (defalias 'overlays-in 'ignore)
346     (defalias 'replace-dehighlight 'ignore)
347     (defalias 'replace-highlight 'ignore)
348     (defalias 'run-with-idle-timer 'ignore)
349     (defalias 'w3-coding-system-for-mime-charset 'ignore)))
350
351 ;; T-gnus stuff.
352 (eval-and-compile
353   (when (featurep 'xemacs)
354     (autoload 'c-mode "cc-mode" nil t)
355     (autoload 'font-lock-mode "font-lock" nil t)
356     (autoload 'read-kbd-macro "edmacro" nil t)
357     (autoload 'turn-on-font-lock "font-lock" nil t))
358   (autoload 'nnheader-detect-coding-region "nnheader")
359   (autoload 'std11-extract-addresses-components "nnheader")
360   (autoload 'std11-fold-region "nnheader")
361   (autoload 'std11-narrow-to-field "nnheader")
362   (autoload 'std11-unfold-region "nnheader"))
363
364 (defconst dgnushack-unexporting-files
365   (append '("dgnushack.el" "dgnuspath.el" "dgnuskwds.el" "lpath.el")
366           (unless (or (condition-case code
367                           (require 'w3-parse)
368                         (error
369                          (message "No w3: %s%s, retrying..."
370                                   (error-message-string code)
371                                   (if (setq code (locate-library "w3-parse"))
372                                       (concat " (" code ")")
373                                     ""))
374                          nil))
375                       ;; Maybe mis-configured Makefile is used (e.g.
376                       ;; configured for FSFmacs but XEmacs is running).
377                       (let ((lp (delete dgnushack-w3-directory
378                                         (copy-sequence load-path))))
379                         (if (let ((load-path lp))
380                               (condition-case nil
381                                   (require 'w3-parse)
382                                 (error nil)))
383                             ;; If success, fix `load-path' for compiling.
384                             (progn
385                               (setq load-path lp)
386                               (message " => fixed; W3DIR=%s"
387                                        (file-name-directory
388                                         (locate-library "w3-parse")))
389                               t)
390                           (message " => ignored")
391                           nil)))
392             '("nnultimate.el" "webmail.el" "nnwfm.el"))
393           (condition-case code
394               (progn (require 'mh-e) nil)
395             (error
396              (message "No mh-e: %s%s (ignored)"
397                       (error-message-string code)
398                       (if (setq code (locate-library "mh-e"))
399                           (concat " (" code ")")
400                         ""))
401              '("gnus-mh.el")))
402           (condition-case code
403               (progn (require 'xml) nil)
404             (error
405              (message "No xml: %s%s (ignored)"
406                       (error-message-string code)
407                       (if (setq code (locate-library "xml"))
408                           (concat " (" code ")")
409                         ""))
410              '("nnrss.el")))
411           (condition-case code
412               (progn (require 'bbdb) nil)
413             (error
414              (message "No bbdb: %s%s (ignored)"
415                       (error-message-string code)
416                       (if (setq code (locate-library "bbdb"))
417                           (concat " (" code ")")
418                         ""))
419              '("gnus-bbdb.el")))
420           (unless (featurep 'xemacs)
421             '("gnus-xmas.el" "messagexmas.el" "nnheaderxm.el"
422               "run-at-time.el"))
423           (when (and (fboundp 'base64-decode-string)
424                      (subrp (symbol-function 'base64-decode-string)))
425             '("base64.el"))
426           (when (and (fboundp 'md5) (subrp (symbol-function 'md5)))
427             '("md5.el"))
428           (when (featurep 'xemacs)
429             '("gnus-load.el")))
430   "Files which will not be installed.")
431
432 (defconst dgnushack-exporting-files
433   (let ((files (directory-files srcdir nil "^[^=].*\\.el$" t)))
434     (dolist (file dgnushack-unexporting-files)
435       (setq files (delete file files)))
436     (sort files 'string-lessp))
437   "Files which will be compiled and installed.")
438
439 (defun dgnushack-exporting-files ()
440   "Print name of files which will be installed."
441   (princ (mapconcat 'identity dgnushack-exporting-files " ")))
442
443 (defconst dgnushack-dont-compile-files
444   '("gnus-load.el"
445     "mm-bodies.el" "mm-decode.el" "mm-encode.el" "mm-extern.el"
446     "mm-partial.el" "mm-url.el" "mm-uu.el" "mm-view.el" "mml-sec.el"
447     "mml-smime.el" "mml.el" "mml1991.el" "mml2015.el")
448   "Files which should not be byte-compiled.")
449
450 (defun dgnushack-compile-verbosely ()
451   "Call dgnushack-compile with warnings ENABLED.  If you are compiling
452 patches to gnus, you should consider modifying make.bat to call
453 dgnushack-compile-verbosely.  All other users should continue to use
454 dgnushack-compile."
455   (dgnushack-compile t))
456
457 (defun dgnushack-compile (&optional warn)
458   ;;(setq byte-compile-dynamic t)
459   (unless warn
460     (setq byte-compile-warnings
461           '(free-vars unresolved callargs redefine)))
462
463   ;; Show `load-path'.
464   (message "load-path=(\"%s\")"
465            (mapconcat 'identity load-path "\"\n           \""))
466
467   (dolist (file dgnushack-exporting-files)
468     (setq file (expand-file-name file srcdir))
469     (when (and (file-exists-p
470                 (setq elc (concat (file-name-nondirectory file) "c")))
471                (file-newer-than-file-p file elc))
472       (delete-file elc)))
473
474   ;; Avoid barfing (from gnus-xmas) because the etc directory is not yet
475   ;; installed.
476   (when (featurep 'xemacs)
477     (setq gnus-xmas-glyph-directory "dummy"))
478
479   (let ((files dgnushack-exporting-files)
480         ;;(byte-compile-generate-call-tree t)
481         file elc)
482     (while (setq file (pop files))
483       (unless (member file dgnushack-dont-compile-files)
484         (setq file (expand-file-name file srcdir))
485         (when (or (not (file-exists-p
486                         (setq elc (concat (file-name-nondirectory file) "c"))))
487                   (file-newer-than-file-p file elc))
488           (ignore-errors
489             (byte-compile-file file)))))))
490
491 (defun dgnushack-recompile ()
492   (require 'gnus)
493   (byte-recompile-directory "." 0))
494
495 (defvar dgnushack-gnus-load-file
496   (if (featurep 'xemacs)
497       (expand-file-name "auto-autoloads.el" srcdir)
498     (expand-file-name "gnus-load.el" srcdir)))
499
500 (defvar dgnushack-cus-load-file
501   (if (featurep 'xemacs)
502       (expand-file-name "custom-load.el" srcdir)
503     (expand-file-name "cus-load.el" srcdir)))
504
505 (defun dgnushack-make-cus-load ()
506   (load "cus-dep")
507   (let ((cusload-base-file dgnushack-cus-load-file))
508     (if (fboundp 'custom-make-dependencies)
509         (custom-make-dependencies)
510       (Custom-make-dependencies))
511     (when (featurep 'xemacs)
512       (message "Compiling %s..." dgnushack-cus-load-file)
513       (byte-compile-file dgnushack-cus-load-file))))
514
515 (defun dgnushack-make-auto-load ()
516   (require 'autoload)
517   (unless (make-autoload '(define-derived-mode child parent name
518                             "docstring" body)
519                          "file")
520     (defadvice make-autoload (around handle-define-derived-mode activate)
521       "Handle `define-derived-mode'."
522       (if (eq (car-safe (ad-get-arg 0)) 'define-derived-mode)
523           (setq ad-return-value
524                 (list 'autoload
525                       (list 'quote (nth 1 (ad-get-arg 0)))
526                       (ad-get-arg 1)
527                       (nth 4 (ad-get-arg 0))
528                       t nil))
529         ad-do-it))
530     (put 'define-derived-mode 'doc-string-elt 3))
531   (let ((generated-autoload-file dgnushack-gnus-load-file)
532         (make-backup-files nil)
533         (autoload-package-name "gnus"))
534     (if (featurep 'xemacs)
535         (if (file-exists-p generated-autoload-file)
536             (delete-file generated-autoload-file))
537       (with-temp-file generated-autoload-file
538         (insert ?\014)))
539     (if (featurep 'xemacs)
540         (let ((si:message (symbol-function 'message)))
541           (defun message (fmt &rest args)
542             (cond ((and (string-equal "Generating autoloads for %s..." fmt)
543                         (file-exists-p (file-name-nondirectory (car args))))
544                    (funcall si:message
545                             fmt (file-name-nondirectory (car args))))
546                   ((string-equal "No autoloads found in %s" fmt))
547                   ((string-equal "Generating autoloads for %s...done" fmt))
548                   (t (apply si:message fmt args))))
549           (unwind-protect
550               (batch-update-autoloads)
551             (fset 'message si:message)))
552       (batch-update-autoloads))))
553
554 (defun dgnushack-make-load ()
555   (unless (featurep 'xemacs)
556     (message "Generating %s..." dgnushack-gnus-load-file)
557     (with-temp-file dgnushack-gnus-load-file
558       (insert-file-contents dgnushack-cus-load-file)
559       (delete-file dgnushack-cus-load-file)
560       (goto-char (point-min))
561       (search-forward ";;; Code:")
562       (forward-line)
563       (delete-region (point-min) (point))
564       (insert "\
565 ;;; gnus-load.el --- automatically extracted custom dependencies and autoload
566 ;;
567 ;;; Code:
568 ")
569       (goto-char (point-max))
570       (if (search-backward "custom-versions-load-alist" nil t)
571           (forward-line -1)
572         (forward-line -1)
573         (while (eq (char-after) ?\;)
574           (forward-line -1))
575         (forward-line))
576       (delete-region (point) (point-max))
577       (insert "\n")
578       ;; smiley-* are duplicated. Remove them all.
579       (let ((point (point)))
580         (insert-file-contents dgnushack-gnus-load-file)
581         (goto-char point)
582         (while (search-forward "smiley-" nil t)
583           (beginning-of-line)
584           (if (looking-at "(autoload ")
585               (delete-region (point) (progn (forward-sexp) (point)))
586             (forward-line))))
587       ;;
588       (goto-char (point-max))
589       (when (search-backward "\n(provide " nil t)
590         (forward-line -1)
591         (delete-region (point) (point-max)))
592       (insert "\
593
594 \(provide 'gnus-load)
595
596 ;;; Local Variables:
597 ;;; version-control: never
598 ;;; no-byte-compile: t
599 ;;; no-update-autoloads: t
600 ;;; End:
601 ;;; gnus-load.el ends here
602 ")
603       ))
604   (message "Compiling %s..." dgnushack-gnus-load-file)
605   (byte-compile-file dgnushack-gnus-load-file)
606   (when (featurep 'xemacs)
607     (message "Creating dummy gnus-load.el...")
608     (with-temp-file (expand-file-name "gnus-load.el")
609       (insert "\
610
611 \(provide 'gnus-load)
612
613 ;;; Local Variables:
614 ;;; version-control: never
615 ;;; no-byte-compile: t
616 ;;; no-update-autoloads: t
617 ;;; End:
618 ;;; gnus-load.el ends here"))))
619
620 \f
621 (defconst dgnushack-info-file-regexp-en
622   (let ((names '("gnus" "message" "emacs-mime"))
623         regexp name)
624     (while (setq name (pop names))
625       (setq regexp (concat regexp "^" name "\\.info\\(-[0-9]+\\)?$"
626                            (when names "\\|"))))
627     regexp)
628   "Regexp matching English info files.")
629
630 (defconst dgnushack-info-file-regexp-ja
631   (let ((names '("gnus-ja" "message-ja"))
632         regexp name)
633     (while (setq name (pop names))
634       (setq regexp (concat regexp "^" name "\\.info\\(-[0-9]+\\)?$"
635                            (when names "\\|"))))
636     regexp)
637   "Regexp matching Japanese info files.")
638
639 (defun dgnushack-remove-extra-files-in-package ()
640   "Remove extra files in the lisp directory of the XEmacs package."
641   (let ((lisp-dir (expand-file-name (concat "lisp/"
642                                             ;; GNUS_PRODUCT_NAME
643                                             (cadr command-line-args-left)
644                                             "/")
645                                     ;; PACKAGEDIR
646                                     (car command-line-args-left))))
647     (setq command-line-args-left nil)
648     (when (file-directory-p lisp-dir)
649       (let (files)
650         (dolist (file dgnushack-exporting-files)
651           (setq files (nconc files (list file (concat file "c")))))
652         (dolist (file (directory-files lisp-dir nil nil t t))
653           (unless (member file files)
654             (setq file (expand-file-name file lisp-dir))
655             (message "Removing %s..." file)
656             (condition-case nil
657                 (delete-file file)
658               (error nil))))))))
659
660 (defun dgnushack-install-package-manifest ()
661   "Install MANIFEST file as an XEmacs package."
662   (let* ((package-dir (pop command-line-args-left))
663          (product-name (pop command-line-args-left))
664          (pkginfo-dir (expand-file-name "pkginfo" package-dir))
665          (name (expand-file-name (concat "MANIFEST." product-name)
666                                  pkginfo-dir))
667          make-backup-files)
668     (unless (file-directory-p pkginfo-dir)
669       (message "Creating directory %s/..." pkginfo-dir)
670       (make-directory pkginfo-dir))
671     (message "Generating %s..." name)
672     (with-temp-file name
673       (insert "pkginfo/MANIFEST." product-name "\n")
674       (let ((lisp-dir (concat "lisp/" product-name "/"))
675             (files (sort (directory-files "." nil "\\.elc?$" t) 'string-lessp))
676             file)
677         (while (setq file (pop files))
678           (unless (member file dgnushack-unexporting-files)
679             (insert lisp-dir file "\n")))
680         (setq files
681               (sort (directory-files "../texi/" nil
682                                      (concat dgnushack-info-file-regexp-en
683                                              "\\|"
684                                              dgnushack-info-file-regexp-ja)
685                                      t)
686                     'string-lessp))
687         (while (setq file (pop files))
688           (insert "info/" file "\n"))))))
689
690 \f
691 (define-compiler-macro describe-key-briefly (&whole form key &optional insert)
692   (if (condition-case nil
693           (progn
694             (describe-key-briefly '((())) nil)
695             t)
696         (wrong-number-of-arguments nil);; Old Emacsen.
697         (error t))
698       form
699     (if insert
700         `(if ,insert
701              (insert (funcall 'describe-key-briefly ,key))
702            (funcall 'describe-key-briefly ,key))
703       `(funcall 'describe-key-briefly ,key))))
704
705 ;;; dgnushack.el ends here