Synch to No Gnus 200505270324.
[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., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, 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 'smtpmail-send-it "smtpmail")
322     (autoload 'sort-numeric-fields "sort" nil t)
323     (autoload 'sort-subr "sort")
324     (autoload 'trace-function-background "trace" nil t)
325     (autoload 'w3-do-setup "w3")
326     (autoload 'w3-prepare-buffer "w3-display")
327     (autoload 'w3-region "w3-display" nil t)
328     (defalias 'frame-char-height 'frame-height)
329     (defalias 'frame-char-width 'frame-width)
330     (defalias 'frame-parameter 'frame-property)
331     (defalias 'make-overlay 'ignore)
332     (defalias 'overlay-end 'ignore)
333     (defalias 'overlay-get 'ignore)
334     (defalias 'overlay-put 'ignore)
335     (defalias 'overlay-start 'ignore)
336     (defalias 'overlays-in 'ignore)
337     (defalias 'replace-dehighlight 'ignore)
338     (defalias 'replace-highlight 'ignore)
339     (defalias 'w3-coding-system-for-mime-charset 'ignore)))
340
341 ;; T-gnus stuff.
342 (eval-and-compile
343   (when (featurep 'xemacs)
344     (autoload 'c-mode "cc-mode" nil t)
345     (autoload 'font-lock-mode "font-lock" nil t)
346     (autoload 'read-kbd-macro "edmacro" nil t)
347     (autoload 'turn-on-font-lock "font-lock" nil t))
348   (autoload 'nnheader-detect-coding-region "nnheader")
349   (autoload 'std11-extract-addresses-components "nnheader")
350   (autoload 'std11-fold-region "nnheader")
351   (autoload 'std11-narrow-to-field "nnheader")
352   (autoload 'std11-unfold-region "nnheader"))
353
354 (defconst dgnushack-unexporting-files
355   (append '("dgnushack.el" "dgnuspath.el" "dgnuskwds.el" "lpath.el"
356             "legacy-gnus-agent.el")
357           (unless (or (condition-case code
358                           (require 'w3-parse)
359                         (error
360                          (message "No w3: %s%s, retrying..."
361                                   (error-message-string code)
362                                   (if (setq code (locate-library "w3-parse"))
363                                       (concat " (" code ")")
364                                     ""))
365                          nil))
366                       ;; Maybe mis-configured Makefile is used (e.g.
367                       ;; configured for FSFmacs but XEmacs is running).
368                       (let ((lp (delete dgnushack-w3-directory
369                                         (copy-sequence load-path))))
370                         (if (let ((load-path lp))
371                               (condition-case nil
372                                   (require 'w3-parse)
373                                 (error nil)))
374                             ;; If success, fix `load-path' for compiling.
375                             (progn
376                               (setq load-path lp)
377                               (message " => fixed; W3DIR=%s"
378                                        (file-name-directory
379                                         (locate-library "w3-parse")))
380                               t)
381                           (message " => ignored")
382                           nil)))
383             '("nnultimate.el" "webmail.el" "nnwfm.el"))
384           (condition-case code
385               (progn (require 'mh-e) nil)
386             (error
387              (message "No mh-e: %s%s (ignored)"
388                       (error-message-string code)
389                       (if (setq code (locate-library "mh-e"))
390                           (concat " (" code ")")
391                         ""))
392              '("gnus-mh.el")))
393           (condition-case code
394               (progn (require 'xml) nil)
395             (error
396              (message "No xml: %s%s (ignored)"
397                       (error-message-string code)
398                       (if (setq code (locate-library "xml"))
399                           (concat " (" code ")")
400                         ""))
401              '("nnrss.el")))
402           (condition-case code
403               (progn (require 'bbdb) nil)
404             (error
405              (message "No bbdb: %s%s (ignored)"
406                       (error-message-string code)
407                       (if (setq code (locate-library "bbdb"))
408                           (concat " (" code ")")
409                         ""))
410              '("gnus-bbdb.el")))
411           (unless (featurep 'xemacs)
412             '("gnus-xmas.el" "messagexmas.el" "nnheaderxm.el"))
413           (when (and (fboundp 'base64-decode-string)
414                      (subrp (symbol-function 'base64-decode-string)))
415             '("base64.el"))
416           (when (and (fboundp 'md5) (subrp (symbol-function 'md5)))
417             '("md5.el"))
418           (when (featurep 'xemacs)
419             '("gnus-load.el")))
420   "Files which will not be installed.")
421
422 (defconst dgnushack-exporting-files
423   (let ((files (directory-files srcdir nil "^[^=].*\\.el$" t)))
424     (dolist (file dgnushack-unexporting-files)
425       (setq files (delete file files)))
426     (sort files 'string-lessp))
427   "Files which will be compiled and installed.")
428
429 (defun dgnushack-exporting-files ()
430   "Print name of files which will be installed."
431   (princ (mapconcat 'identity dgnushack-exporting-files " ")))
432
433 (defconst dgnushack-dont-compile-files
434   '("gnus-load.el"
435     "mm-bodies.el" "mm-decode.el" "mm-encode.el" "mm-extern.el"
436     "mm-partial.el" "mm-uu.el" "mm-view.el" "mml-sec.el" "mml-smime.el"
437     "mml.el" "mml1991.el" "mml2015.el")
438   "Files which should not be byte-compiled.")
439
440 (defun dgnushack-compile-verbosely ()
441   "Call dgnushack-compile with warnings ENABLED.  If you are compiling
442 patches to gnus, you should consider modifying make.bat to call
443 dgnushack-compile-verbosely.  All other users should continue to use
444 dgnushack-compile."
445   (dgnushack-compile t))
446
447 (defun dgnushack-compile (&optional warn)
448   ;;(setq byte-compile-dynamic t)
449   (unless warn
450     (setq byte-compile-warnings
451           '(free-vars unresolved callargs redefine)))
452
453   ;; Show `load-path'.
454   (message "load-path=(\"%s\")"
455            (mapconcat 'identity load-path "\"\n           \""))
456
457   (dolist (file dgnushack-exporting-files)
458     (setq file (expand-file-name file srcdir))
459     (when (and (file-exists-p
460                 (setq elc (concat (file-name-nondirectory file) "c")))
461                (file-newer-than-file-p file elc))
462       (delete-file elc)))
463
464   ;; Avoid barfing (from gnus-xmas) because the etc directory is not yet
465   ;; installed.
466   (when (featurep 'xemacs)
467     (setq gnus-xmas-glyph-directory "dummy"))
468
469   (let ((files dgnushack-exporting-files)
470         ;;(byte-compile-generate-call-tree t)
471         file elc)
472     (while (setq file (pop files))
473       (unless (member file dgnushack-dont-compile-files)
474         (setq file (expand-file-name file srcdir))
475         (when (or (not (file-exists-p
476                         (setq elc (concat (file-name-nondirectory file) "c"))))
477                   (file-newer-than-file-p file elc))
478           (ignore-errors
479             (byte-compile-file file)))))))
480
481 (defun dgnushack-recompile ()
482   (require 'gnus)
483   (byte-recompile-directory "." 0))
484
485 (defvar dgnushack-gnus-load-file
486   (if (featurep 'xemacs)
487       (expand-file-name "auto-autoloads.el" srcdir)
488     (expand-file-name "gnus-load.el" srcdir)))
489
490 (defvar dgnushack-cus-load-file
491   (if (featurep 'xemacs)
492       (expand-file-name "custom-load.el" srcdir)
493     (expand-file-name "cus-load.el" srcdir)))
494
495 (defun dgnushack-make-cus-load ()
496   (load "cus-dep")
497   (let ((cusload-base-file dgnushack-cus-load-file))
498     (if (fboundp 'custom-make-dependencies)
499         (custom-make-dependencies)
500       (Custom-make-dependencies))
501     (when (featurep 'xemacs)
502       (message "Compiling %s..." dgnushack-cus-load-file)
503       (byte-compile-file dgnushack-cus-load-file))))
504
505 (defun dgnushack-make-auto-load ()
506   (require 'autoload)
507   (unless (make-autoload '(define-derived-mode child parent name
508                             "docstring" body)
509                          "file")
510     (defadvice make-autoload (around handle-define-derived-mode activate)
511       "Handle `define-derived-mode'."
512       (if (eq (car-safe (ad-get-arg 0)) 'define-derived-mode)
513           (setq ad-return-value
514                 (list 'autoload
515                       (list 'quote (nth 1 (ad-get-arg 0)))
516                       (ad-get-arg 1)
517                       (nth 4 (ad-get-arg 0))
518                       t nil))
519         ad-do-it))
520     (put 'define-derived-mode 'doc-string-elt 3))
521   (let ((generated-autoload-file dgnushack-gnus-load-file)
522         (make-backup-files nil)
523         (autoload-package-name "gnus"))
524     (if (featurep 'xemacs)
525         (if (file-exists-p generated-autoload-file)
526             (delete-file generated-autoload-file))
527       (with-temp-file generated-autoload-file
528         (insert ?\014)))
529     (if (featurep 'xemacs)
530         (let ((si:message (symbol-function 'message)))
531           (defun message (fmt &rest args)
532             (cond ((and (string-equal "Generating autoloads for %s..." fmt)
533                         (file-exists-p (file-name-nondirectory (car args))))
534                    (funcall si:message
535                             fmt (file-name-nondirectory (car args))))
536                   ((string-equal "No autoloads found in %s" fmt))
537                   ((string-equal "Generating autoloads for %s...done" fmt))
538                   (t (apply si:message fmt args))))
539           (unwind-protect
540               (batch-update-autoloads)
541             (fset 'message si:message)))
542       (batch-update-autoloads))))
543
544 (defun dgnushack-make-load ()
545   (unless (featurep 'xemacs)
546     (message "Generating %s..." dgnushack-gnus-load-file)
547     (with-temp-file dgnushack-gnus-load-file
548       (insert-file-contents dgnushack-cus-load-file)
549       (delete-file dgnushack-cus-load-file)
550       (goto-char (point-min))
551       (search-forward ";;; Code:")
552       (forward-line)
553       (delete-region (point-min) (point))
554       (insert "\
555 ;;; gnus-load.el --- automatically extracted custom dependencies and autoload
556 ;;
557 ;;; Code:
558 ")
559       (goto-char (point-max))
560       (if (search-backward "custom-versions-load-alist" nil t)
561           (forward-line -1)
562         (forward-line -1)
563         (while (eq (char-after) ?\;)
564           (forward-line -1))
565         (forward-line))
566       (delete-region (point) (point-max))
567       (insert "\n")
568       ;; smiley-* are duplicated. Remove them all.
569       (let ((point (point)))
570         (insert-file-contents dgnushack-gnus-load-file)
571         (goto-char point)
572         (while (search-forward "smiley-" nil t)
573           (beginning-of-line)
574           (if (looking-at "(autoload ")
575               (delete-region (point) (progn (forward-sexp) (point)))
576             (forward-line))))
577       ;;
578       (goto-char (point-max))
579       (when (search-backward "\n(provide " nil t)
580         (forward-line -1)
581         (delete-region (point) (point-max)))
582       (insert "\
583
584 \(provide 'gnus-load)
585
586 ;;; Local Variables:
587 ;;; version-control: never
588 ;;; no-byte-compile: t
589 ;;; no-update-autoloads: t
590 ;;; End:
591 ;;; gnus-load.el ends here
592 ")
593       ))
594   (message "Compiling %s..." dgnushack-gnus-load-file)
595   (byte-compile-file dgnushack-gnus-load-file)
596   (when (featurep 'xemacs)
597     (message "Creating dummy gnus-load.el...")
598     (with-temp-file (expand-file-name "gnus-load.el")
599       (insert "\
600
601 \(provide 'gnus-load)
602
603 ;;; Local Variables:
604 ;;; version-control: never
605 ;;; no-byte-compile: t
606 ;;; no-update-autoloads: t
607 ;;; End:
608 ;;; gnus-load.el ends here"))))
609
610 \f
611 (defconst dgnushack-info-file-regexp-en
612   (let ((names '("gnus" "message" "emacs-mime"))
613         regexp name)
614     (while (setq name (pop names))
615       (setq regexp (concat regexp "^" name "\\.info\\(-[0-9]+\\)?$"
616                            (when names "\\|"))))
617     regexp)
618   "Regexp matching English info files.")
619
620 (defconst dgnushack-info-file-regexp-ja
621   (let ((names '("gnus-ja" "message-ja"))
622         regexp name)
623     (while (setq name (pop names))
624       (setq regexp (concat regexp "^" name "\\.info\\(-[0-9]+\\)?$"
625                            (when names "\\|"))))
626     regexp)
627   "Regexp matching Japanese info files.")
628
629 (defun dgnushack-remove-extra-files-in-package ()
630   "Remove extra files in the lisp directory of the XEmacs package."
631   (let ((lisp-dir (expand-file-name (concat "lisp/"
632                                             ;; GNUS_PRODUCT_NAME
633                                             (cadr command-line-args-left)
634                                             "/")
635                                     ;; PACKAGEDIR
636                                     (car command-line-args-left))))
637     (setq command-line-args-left nil)
638     (when (file-directory-p lisp-dir)
639       (let (files)
640         (dolist (file dgnushack-exporting-files)
641           (setq files (nconc files (list file (concat file "c")))))
642         (dolist (file (directory-files lisp-dir nil nil t t))
643           (unless (member file files)
644             (setq file (expand-file-name file lisp-dir))
645             (message "Removing %s..." file)
646             (condition-case nil
647                 (delete-file file)
648               (error nil))))))))
649
650 (defun dgnushack-install-package-manifest ()
651   "Install MANIFEST file as an XEmacs package."
652   (let* ((package-dir (pop command-line-args-left))
653          (product-name (pop command-line-args-left))
654          (pkginfo-dir (expand-file-name "pkginfo" package-dir))
655          (name (expand-file-name (concat "MANIFEST." product-name)
656                                  pkginfo-dir))
657          make-backup-files)
658     (unless (file-directory-p pkginfo-dir)
659       (message "Creating directory %s/..." pkginfo-dir)
660       (make-directory pkginfo-dir))
661     (message "Generating %s..." name)
662     (with-temp-file name
663       (insert "pkginfo/MANIFEST." product-name "\n")
664       (let ((lisp-dir (concat "lisp/" product-name "/"))
665             (files (sort (directory-files "." nil "\\.elc?$" t) 'string-lessp))
666             file)
667         (while (setq file (pop files))
668           (unless (member file dgnushack-unexporting-files)
669             (insert lisp-dir file "\n")))
670         (setq files
671               (sort (directory-files "../texi/" nil
672                                      (concat dgnushack-info-file-regexp-en
673                                              "\\|"
674                                              dgnushack-info-file-regexp-ja)
675                                      t)
676                     'string-lessp))
677         (while (setq file (pop files))
678           (insert "info/" file "\n"))
679         (insert "etc/gnus-tut.txt\n")
680         (setq files
681               (sort (directory-files "../etc/images/gnus/" nil
682                                      "\\.\\(pbm\\|xbm\\|xpm\\)\\'"
683                                      t)
684                     'string-lessp))
685         (while (setq file (pop files))
686           (insert "etc/images/gnus/" file "\n"))
687         (insert "etc/images/gnus/x-splash\n")
688         (setq files
689               (sort (directory-files "../etc/images/smilies/" nil
690                                      "\\.\\(pbm\\|xpm\\)\\'"
691                                      t)
692                     'string-lessp))
693         (while (setq file (pop files))
694           (insert "etc/images/smilies/" file "\n"))))))
695
696 ;;; dgnushack.el ends here