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