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