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