* lisp/Makefile.in (clever): Change the quoting style for the elisp
[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
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       ((boundp 'MULE)
41        (put '*coding-category-sjis* 'priority (length *predefined-category*)))
42       ((featurep 'mule)
43        (if (memq 'coding-category-sjis coding-category-list)
44            (set-coding-priority
45             (append (delq 'coding-category-sjis
46                           (copy-sequence coding-category-list))
47                     '(coding-category-sjis))))))
48
49 (defalias 'facep 'ignore)
50
51 (require 'cl)
52 (unless (dolist (var nil t))
53   ;; Override the macro `dolist' which may have been defined in egg.el.
54   (load "cl-macs" nil t))
55
56 (defvar srcdir (or (getenv "srcdir") "."))
57
58 (let ((urldir (getenv "URLDIR")))
59   (unless (zerop (length urldir))
60     (push (file-name-as-directory urldir) load-path)))
61
62 (defvar dgnushack-w3-directory (let ((w3dir (getenv "W3DIR")))
63                                  (unless (zerop (length w3dir))
64                                    (file-name-as-directory w3dir))))
65 (when dgnushack-w3-directory
66   (push dgnushack-w3-directory load-path))
67
68 ;; If we are building w3 in a different directory than the source
69 ;; directory, we must read *.el from source directory and write *.elc
70 ;; into the building directory.  For that, we define this function
71 ;; before loading bytecomp.  Bytecomp doesn't overwrite this function.
72 (defun byte-compile-dest-file (filename)
73   "Convert an Emacs Lisp source file name to a compiled file name.
74  In addition, remove directory name part from FILENAME."
75   (setq filename (byte-compiler-base-file-name filename))
76   (setq filename (file-name-sans-versions filename))
77   (setq filename (file-name-nondirectory filename))
78   (if (memq system-type '(win32 w32 mswindows windows-nt))
79       (setq filename (downcase filename)))
80   (cond ((eq system-type 'vax-vms)
81          (concat (substring filename 0 (string-match ";" filename)) "c"))
82         ((string-match emacs-lisp-file-regexp filename)
83          (concat (substring filename 0 (match-beginning 0)) ".elc"))
84         (t (concat filename ".elc"))))
85
86 (require 'bytecomp)
87
88 (when (boundp 'MULE)
89   (let (current-load-list)
90     ;; Make the function to be silent at compile-time.
91     (defun locate-library (library &optional nosuffix)
92       "Show the full path name of Emacs library LIBRARY.
93 This command searches the directories in `load-path' like `M-x load-library'
94 to find the file that `M-x load-library RET LIBRARY RET' would load.
95 Optional second arg NOSUFFIX non-nil means don't add suffixes `.elc' or `.el'
96 to the specified name LIBRARY (a la calling `load' instead of `load-library')."
97       (interactive "sLocate library: ")
98       (catch 'answer
99         (mapcar
100          '(lambda (dir)
101             (mapcar
102              '(lambda (suf)
103                 (let ((try (expand-file-name (concat library suf) dir)))
104                   (and (file-readable-p try)
105                        (null (file-directory-p try))
106                        (progn
107                          (or noninteractive
108                              (message "Library is file %s" try))
109                          (throw 'answer try)))))
110              (if nosuffix '("") '(".elc" ".el" ""))))
111          load-path)
112         (or noninteractive
113             (message "No library %s in search path" library))
114         nil))
115     (byte-compile 'locate-library)))
116
117 (unless (fboundp 'si:byte-optimize-form-code-walker)
118   (byte-optimize-form nil);; Load `byte-opt' or `byte-optimize'.
119   (setq max-specpdl-size 3000)
120   (defalias 'si:byte-optimize-form-code-walker
121     (symbol-function 'byte-optimize-form-code-walker))
122   (defun byte-optimize-form-code-walker (form for-effect)
123     (if (and for-effect (memq (car-safe form) '(and or)))
124         ;; Fix bug in and/or forms.
125         (let ((fn (car form))
126               (backwards (reverse (cdr form))))
127           (while (and backwards
128                       (null (setcar backwards
129                                     (byte-optimize-form (car backwards) t))))
130             (setq backwards (cdr backwards)))
131           (if (and (cdr form) (null backwards))
132               (byte-compile-log
133                "  all subforms of %s called for effect; deleted" form))
134           (if backwards
135               (let ((head backwards))
136                 (while (setq backwards (cdr backwards))
137                   (setcar backwards (byte-optimize-form (car backwards)
138                                                         nil)))
139                 (cons fn (nreverse head)))))
140       (si:byte-optimize-form-code-walker form for-effect)))
141   (byte-compile 'byte-optimize-form-code-walker))
142
143 (condition-case nil
144     (char-after)
145   (wrong-number-of-arguments
146    ;; Optimize byte code for `char-after'.
147    (put 'char-after 'byte-optimizer 'byte-optimize-char-after)
148    (defun byte-optimize-char-after (form)
149      (if (null (cdr form))
150          '(char-after (point))
151        form))))
152
153 (condition-case nil
154     (char-before)
155   (wrong-number-of-arguments
156    ;; Optimize byte code for `char-before'.
157    (put 'char-before 'byte-optimizer 'byte-optimize-char-before)
158    (defun byte-optimize-char-before (form)
159      (if (null (cdr form))
160          '(char-before (point))
161        form))))
162
163 (load (expand-file-name "dgnuspath.el" srcdir) nil nil t)
164
165 (condition-case err
166     (load "~/.lpath.el" t nil t)
167   (error (message "Error in \"~/.lpath.el\" file: %s" err)))
168
169 ;; Don't load path-util until `char-after' and `char-before' have been
170 ;; optimized because it requires `poe' and then modify the functions.
171
172 ;; If the APEL modules are installed under the directory
173 ;; "/usr/local/share/mule/site-lisp/apel/", the parent directory
174 ;; "/usr/local/share/mule/site-lisp/" should be included in the
175 ;; standard `load-path' or added by the configure option
176 ;; "--with-addpath=".  And also the directory where the EMU modules
177 ;; are installed (e.g. "/usr/local/share/mule/19.34/site-lisp/")
178 ;; should be included in the standard `load-path' or added by the
179 ;; configure option "--with-addpath=".
180 (condition-case nil
181     (require 'path-util)
182   (error
183    (let ((path (locate-library "apel/path-util")))
184      (if path
185          (progn
186            (when (string-match "/$" (setq path (file-name-directory path)))
187              (setq path (substring path 0 (match-beginning 0))))
188            (unless (or (member path load-path)
189                        (member (file-name-as-directory path) load-path))
190              (push path load-path))
191            (require 'path-util))
192        (error "
193 APEL modules does not found in %s.
194 Try to re-configure with --with-addpath=APEL_PATH and run make again.
195 "
196               load-path)))))
197 (unless (locate-library "mel")
198   (add-path "flim"))
199 (unless (module-installed-p 'mel)
200   ;; FLIM 1.14 may have installed in two "flim" subdirectories.
201   (push (expand-file-name "flim"
202                           (file-name-directory (get-latest-path "^apel$" t)))
203         load-path)
204   (unless (module-installed-p 'mel)
205     (error "
206 FLIM modules does not found in %s.
207 Try to re-configure with --with-addpath=FLIM_PATH and run make again.
208 "
209            load-path)))
210 (add-path "semi")
211
212 (push srcdir load-path)
213 (load (expand-file-name "lpath.el" srcdir) nil t t)
214
215 (load (expand-file-name "gnus-clfns.el" srcdir) nil t t)
216
217 (require 'custom)
218
219 ;; Bind functions defined by `defun-maybe'.
220 (put 'defun-maybe 'byte-hunk-handler 'byte-compile-file-form-defun-maybe)
221 (defun byte-compile-file-form-defun-maybe (form)
222   (if (and (not (fboundp (nth 1 form)))
223            (memq 'unresolved byte-compile-warnings))
224       (setq byte-compile-function-environment
225             (cons (cons (nth 1 form)
226                         (cons 'lambda (cdr (cdr form))))
227                   byte-compile-function-environment)))
228   form)
229
230 (condition-case nil
231     :symbol-for-testing-whether-colon-keyword-is-available-or-not
232   (void-variable
233    (defun dgnushack-bind-colon-keywords ()
234      "Bind all the colon keywords for old Emacsen."
235      (let ((cache (expand-file-name "dgnuskwds.el" srcdir))
236            (makefile (expand-file-name "Makefile" srcdir))
237            (buffer (get-buffer-create " *colon keywords*"))
238            keywords ignores files file dirs dir form elem make-backup-files)
239        (save-excursion
240          (set-buffer buffer)
241          (let (buffer-file-format
242                format-alist
243                insert-file-contents-post-hook
244                insert-file-contents-pre-hook
245                jam-zcat-filename-list
246                jka-compr-compression-info-list)
247            (if (and (file-exists-p cache)
248                     (file-exists-p makefile)
249                     (file-newer-than-file-p cache makefile))
250                (progn
251                  (insert-file-contents cache nil nil nil t)
252                  (setq keywords (read buffer)))
253              (setq
254               ignores
255               '(:symbol-for-testing-whether-colon-keyword-is-available-or-not
256                 ;; The following keywords will be bound by CUSTOM.
257                 :get :group :initialize :link :load :options :prefix
258                 :require :set :tag :type)
259               files (list (locate-library "semi-def")
260                           (locate-library "mailcap")
261                           (locate-library "mime-def")
262                           (locate-library "path-util")
263                           (locate-library "poem"))
264               dirs (list (file-name-as-directory (expand-file-name srcdir))))
265              (while files
266                (when (setq file (pop files))
267                  (setq dir (file-name-directory file))
268                  (unless (member dir dirs)
269                    (push dir dirs))))
270              (message "Searching for all the colon keywords in:")
271              (while dirs
272                (setq dir (pop dirs))
273                (message " %s..." dir)
274                (setq files (directory-files dir t
275                                             "\\.el\\(\\.gz\\|\\.bz2\\)?$"))
276                (while files
277                  (setq file (pop files))
278                  (if (string-match "\\(\\.gz$\\)\\|\\.bz2$" file)
279                      (let ((temp (expand-file-name "dgnustemp.el" srcdir)))
280                        (when
281                            (let* ((binary (if (boundp 'MULE)
282                                               '*noconv*
283                                             'binary))
284                                   (coding-system-for-read binary)
285                                   (coding-system-for-write binary)
286                                   (input-coding-system binary)
287                                   (output-coding-system binary)
288                                   (default-process-coding-system
289                                     (cons binary binary))
290                                   call-process-hook)
291                              (insert-file-contents file nil nil nil t)
292                              (when
293                                  (condition-case code
294                                      (progn
295                                        (if (match-beginning 1)
296                                            (call-process-region
297                                             (point-min) (point-max)
298                                             "gzip" t buffer nil "-cd")
299                                          (call-process-region
300                                           (point-min) (point-max)
301                                           "bzip2" t buffer nil "-d"))
302                                        t)
303                                    (error
304                                     (erase-buffer)
305                                     (message "In file %s: %s" file code)
306                                     nil))
307                                (write-region (point-min) (point-max) temp
308                                              nil 'silent)
309                                t))
310                          (unwind-protect
311                              (insert-file-contents temp nil nil nil t)
312                            (delete-file temp))))
313                    (insert-file-contents file nil nil nil t))
314                  (while (setq form (condition-case nil
315                                        (read buffer)
316                                      (error nil)))
317                    (while form
318                      (setq elem (pop form))
319                      (unless (memq (car-safe elem)
320                                    '(\` backquote
321                                      defcustom defface defgroup
322                                      define-widget quote))
323                        (while (consp elem)
324                          (push (car elem) form)
325                          (setq elem (cdr elem)))
326                        (when (and elem
327                                   (symbolp elem)
328                                   (not (eq ': elem))
329                                   (eq ?: (aref (symbol-name elem) 0))
330                                   (not (memq elem ignores))
331                                   (not (memq elem keywords)))
332                          (push elem keywords)))))))
333              (setq keywords (sort keywords
334                                   (lambda (a b)
335                                     (string-lessp (symbol-name a)
336                                                   (symbol-name b)))))
337              (erase-buffer)
338              (insert (format "%s" keywords))
339              (write-region (point-min) (point) cache nil 'silent)
340              (message
341               "The following colon keywords will be bound at run-time:\n %s"
342               keywords))))
343        (kill-buffer buffer)
344        (defconst dgnushack-colon-keywords keywords)
345        (while keywords
346          (set (car keywords) (car keywords))
347          (setq keywords (cdr keywords)))))
348    (byte-compile 'dgnushack-bind-colon-keywords)
349    (dgnushack-bind-colon-keywords)))
350
351 (if (boundp 'MULE)
352     (progn
353       (setq :version ':version
354             :set-after ':set-after)
355       (require 'custom)
356       (defadvice custom-handle-keyword
357         (around dont-signal-an-error-even-if-unsupported-keyword-is-given
358                 activate)
359         "Don't signal an error even if unsupported keyword is given."
360         (if (not (memq (ad-get-arg 1) '(:version :set-after)))
361             ad-do-it))))
362
363 (when (boundp 'MULE)
364   (put 'custom-declare-face 'byte-optimizer
365        'byte-optimize-ignore-unsupported-custom-keywords)
366   (put 'custom-declare-group 'byte-optimizer
367        'byte-optimize-ignore-unsupported-custom-keywords)
368   (defun byte-optimize-ignore-unsupported-custom-keywords (form)
369     (if (or (memq ':version (nthcdr 4 form))
370             (memq ':set-after (nthcdr 4 form)))
371         (let ((newform (list (car form) (nth 1 form)
372                              (nth 2 form) (nth 3 form)))
373               (args (nthcdr 4 form)))
374           (while args
375             (or (memq (car args) '(:version :set-after))
376                 (setq newform (nconc newform (list (car args)
377                                                    (car (cdr args))))))
378             (setq args (cdr (cdr args))))
379           newform)
380       form))
381
382   (put 'custom-declare-variable 'byte-hunk-handler
383        'byte-compile-file-form-custom-declare-variable)
384   (defun byte-compile-file-form-custom-declare-variable (form)
385     ;; Bind defcustom'ed variables.
386     (if (memq 'free-vars byte-compile-warnings)
387         (setq byte-compile-bound-variables
388               (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
389     (if (memq ':version (nthcdr 4 form))
390         ;; Make the variable uncustomizable.
391         `(defvar ,(nth 1 (nth 1 form)) ,(nth 1 (nth 2 form))
392            ,(substring (nth 3 form) (if (string-match "^[\t *]+" (nth 3 form))
393                                         (match-end 0)
394                                       0)))
395       ;; Ignore unsupported keyword(s).
396       (if (memq ':set-after (nthcdr 4 form))
397           (let ((newform (list (car form) (nth 1 form)
398                                (nth 2 form) (nth 3 form)))
399                 (args (nthcdr 4 form)))
400             (while args
401               (or (eq (car args) ':set-after)
402                   (setq newform (nconc newform (list (car args)
403                                                      (car (cdr args))))))
404               (setq args (cdr (cdr args))))
405             newform)
406         form))))
407
408 ;; Unknown variables and functions.
409 (unless (boundp 'buffer-file-coding-system)
410   (defvar buffer-file-coding-system (symbol-value 'file-coding-system)))
411 (unless (featurep 'xemacs)
412   (defalias 'Custom-make-dependencies 'ignore)
413   (defalias 'update-autoloads-from-directory 'ignore))
414
415 (defalias 'device-sound-enabled-p 'ignore)
416 (defalias 'play-sound-file 'ignore)
417 (defalias 'nndb-request-article 'ignore)
418 (defalias 'efs-re-read-dir 'ignore)
419 (defalias 'ange-ftp-re-read-dir 'ignore)
420 (defalias 'define-mail-user-agent 'ignore)
421
422 (defconst dgnushack-unexporting-files
423   (append '("dgnushack.el" "dgnuspath.el" "dgnuskwds.el" "lpath.el")
424           (condition-case nil
425               (progn (require 'shimbun) nil)
426             (error '("nnshimbun.el")))
427           (unless (or (condition-case code
428                           (require 'w3-forms)
429                         (error
430                          (message "No w3: %s %s retrying..." code
431                                   (locate-library "w3-forms"))
432                          nil))
433                       ;; Maybe mis-configured Makefile is used (e.g.
434                       ;; configured for FSFmacs but XEmacs is running).
435                       (let ((lp (delete dgnushack-w3-directory
436                                         (copy-sequence load-path))))
437                         (if (let ((load-path lp))
438                               (condition-case nil
439                                   (require 'w3-forms)
440                                 (error nil)))
441                             ;; If success, fix `load-path' for compiling.
442                             (progn
443                               (setq load-path lp)
444                               (message " => fixed; W3DIR=%s"
445                                        (file-name-directory
446                                         (locate-library "w3-forms")))
447                               t)
448                           (message " => ignored")
449                           nil)))
450             '("nnweb.el" "nnlistserv.el" "nnultimate.el"
451               "nnslashdot.el" "nnwarchive.el" "webmail.el"
452               "nnwfm.el" "nnrss.el"))
453           (condition-case nil
454               (progn (require 'bbdb) nil)
455             (error '("gnus-bbdb.el")))
456           (unless (featurep 'xemacs)
457             '("gnus-xmas.el" "gnus-picon.el" "messagexmas.el"
458               "nnheaderxm.el" "smiley.el"))
459           (when (or (featurep 'xemacs) (<= emacs-major-version 20))
460             '("smiley-ems.el"))
461           (when (and (fboundp 'base64-decode-string)
462                      (subrp (symbol-function 'base64-decode-string)))
463             '("base64.el"))
464           (when (and (fboundp 'md5) (subrp (symbol-function 'md5)))
465             '("md5.el")))
466   "Files which will not be installed.")
467
468 (defconst dgnushack-exporting-files
469   (let ((files (directory-files srcdir nil "^[^=].*\\.el$" t)))
470     (dolist (file dgnushack-unexporting-files)
471       (setq files (delete file files)))
472     (sort files 'string-lessp))
473   "Files which will be compiled and installed.")
474
475 (defun dgnushack-exporting-files ()
476   "Print name of files which will be installed."
477   (princ (mapconcat 'identity dgnushack-exporting-files " ")))
478
479 (defun dgnushack-compile (&optional warn)
480   ;;(setq byte-compile-dynamic t)
481   (unless warn
482     (setq byte-compile-warnings
483           '(free-vars unresolved callargs redefine)))
484   (unless (locate-library "cus-edit")
485     (error "You do not seem to have Custom installed.
486 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
487 You also then need to add the following to the lisp/dgnushack.el file:
488
489      (push \"~/lisp/custom\" load-path)
490
491 Modify to suit your needs."))
492
493   ;; Show `load-path'.
494   (message "load-path=(\"%s\")"
495            (mapconcat 'identity load-path "\"\n           \""))
496
497   (dolist (file dgnushack-exporting-files)
498     (setq file (expand-file-name file srcdir))
499     (when (and (file-exists-p
500                 (setq elc (concat (file-name-nondirectory file) "c")))
501                (file-newer-than-file-p file elc))
502       (delete-file elc)))
503
504   (let ((files dgnushack-exporting-files)
505         ;;(byte-compile-generate-call-tree t)
506         file elc)
507     ;; Avoid barfing (from gnus-xmas) because the etc directory is not yet
508     ;; installed.
509     (when (featurep 'xemacs)
510       (setq gnus-xmas-glyph-directory "dummy"))
511     (while (setq file (pop files))
512       (setq file (expand-file-name file srcdir))
513       (when (or (not (file-exists-p
514                       (setq elc (concat (file-name-nondirectory file) "c"))))
515                 (file-newer-than-file-p file elc))
516         (ignore-errors
517           (byte-compile-file file))))))
518
519 (defun dgnushack-recompile ()
520   (require 'gnus)
521   (byte-recompile-directory "." 0))
522
523 (defvar dgnushack-gnus-load-file (expand-file-name "gnus-load.el" srcdir))
524 (defvar dgnushack-cus-load-file (expand-file-name "cus-load.el" srcdir))
525 (defvar dgnushack-auto-load-file (expand-file-name "auto-autoloads.el" srcdir))
526
527 (defun dgnushack-make-cus-load ()
528   (when (condition-case nil
529             (load "cus-dep")
530           (error nil))
531     (let ((cusload-base-file dgnushack-cus-load-file))
532       (if (fboundp 'custom-make-dependencies)
533           (custom-make-dependencies)
534         (Custom-make-dependencies)))))
535
536 (defun dgnushack-make-auto-load ()
537   (require 'autoload)
538   (let ((generated-autoload-file dgnushack-gnus-load-file)
539         (make-backup-files nil)
540         (autoload-package-name "gnus"))
541     (if (featurep 'xemacs)
542         (progn
543           (if (file-exists-p generated-autoload-file)
544               (delete-file generated-autoload-file))
545           (if (file-exists-p dgnushack-auto-load-file)
546               (delete-file dgnushack-auto-load-file)))
547       (with-temp-file generated-autoload-file
548         (insert ?\014)))
549     (if (featurep 'xemacs)
550         (let ((si:message (symbol-function 'message)))
551           (defun message (fmt &rest args)
552             (cond ((and (string-equal "Generating autoloads for %s..." fmt)
553                         (file-exists-p (file-name-nondirectory (car args))))
554                    (funcall si:message
555                             fmt (file-name-nondirectory (car args))))
556                   ((string-equal "No autoloads found in %s" fmt))
557                   ((string-equal "Generating autoloads for %s...done" fmt))
558                   (t (apply si:message fmt args))))
559           (unwind-protect
560               (batch-update-autoloads)
561             (fset 'message si:message)))
562       (batch-update-autoloads))))
563
564 (defun dgnushack-make-load ()
565   (message (format "Generating %s..." dgnushack-gnus-load-file))
566   (with-temp-file dgnushack-gnus-load-file
567     (if (file-exists-p dgnushack-cus-load-file)
568         (progn
569           (insert-file-contents dgnushack-cus-load-file)
570           (delete-file dgnushack-cus-load-file)
571           (goto-char (point-min))
572           (search-forward ";;; Code:")
573           (forward-line)
574           (delete-region (point-min) (point))
575           (unless (re-search-forward "\
576 ^[\t ]*(autoload[\t\n ]+\\('\\|(quote[\t\n ]+\\)custom-add-loads[\t\n ]"
577                                      nil t)
578             (insert "\n(autoload 'custom-add-loads \"cus-load\")\n"))
579           (goto-char (point-min))
580           (insert "\
581 ;;; gnus-load.el --- automatically extracted custom dependencies and autoload
582 ;;
583 ;;; Code:
584 ")
585           (goto-char (point-max))
586           (if (search-backward "custom-versions-load-alist" nil t)
587               (forward-line -1)
588             (forward-line -1)
589             (while (eq (char-after) ?\;)
590               (forward-line -1))
591             (forward-line))
592           (delete-region (point) (point-max))
593           (insert "\n"))
594       (insert "\
595 ;;; gnus-load.el --- automatically extracted autoload
596 ;;
597 ;;; Code:
598 "))
599     ;; smiley-* are duplicated. Remove them all.
600     (let ((point (point)))
601       (insert-file-contents dgnushack-gnus-load-file)
602       (goto-char point)
603       (while (search-forward "smiley-" nil t)
604         (beginning-of-line)
605         (if (looking-at "(autoload ")
606             (delete-region (point) (progn (forward-sexp) (point)))
607           (forward-line))))
608     ;;
609     (goto-char (point-max))
610     (when (search-backward "\n(provide " nil t)
611       (forward-line -1)
612       (delete-region (point) (point-max)))
613     (insert "\
614
615 \(provide 'gnus-load)
616
617 ;;; Local Variables:
618 ;;; version-control: never
619 ;;; no-byte-compile: t
620 ;;; no-update-autoloads: t
621 ;;; End:
622 ;;; gnus-load.el ends here\n"))
623   (message (format "Compiling %s..." dgnushack-gnus-load-file))
624   (byte-compile-file dgnushack-gnus-load-file))
625
626 \f
627 (defun dgnushack-compose-package ()
628   "Re-split the file gnus-load.el into custom-load.el and
629 auto-autoloads.el.  It is silly, should be improved!"
630   (message "
631 Re-splitting gnus-load.el into custom-load.el and auto-autoloads.el...")
632   (let ((customload (expand-file-name "custom-load.el" srcdir))
633         (autoloads (expand-file-name "auto-autoloads.el" srcdir))
634         start)
635     (with-temp-buffer
636       (insert-file-contents dgnushack-gnus-load-file)
637       (delete-file dgnushack-gnus-load-file)
638       (when (file-exists-p (concat dgnushack-gnus-load-file "c"))
639         (delete-file (concat dgnushack-gnus-load-file "c")))
640       (while (prog1
641                  (looking-at "[\t ;]")
642                (forward-line 1)))
643       (setq start (point))
644       (insert "\
645 ;;; custom-load.el --- automatically extracted custom dependencies\n
646 ;;; Code:\n\n")
647       (goto-char (point-max))
648       (while (progn
649                (forward-line -1)
650                (not (looking-at "[\t ]*(custom-add-loads[\t\n ]"))))
651       (forward-list 1)
652       (forward-line 1)
653       (insert "\n;;; custom-load.el ends here\n")
654       (write-region start (point) customload)
655       (while (looking-at "[\t ]*$")
656         (forward-line 1))
657       (setq start (point))
658       (if (re-search-forward "^[\t\n ]*(if[\t\n ]+(featurep[\t\n ]" nil t)
659           (let ((from (goto-char (match-beginning 0))))
660             (delete-region from (progn
661                                   (forward-list 1)
662                                   (forward-line 1)
663                                   (point))))
664         (while (looking-at "[\t ;]")
665           (forward-line 1)))
666       (insert "(if (featurep 'gnus-autoloads) (error \"Already loaded\"))\n")
667       (goto-char (point-max))
668       (while (progn
669                (forward-line -1)
670                (not (looking-at "[\t ]*(provide[\t\n ]"))))
671       (insert "(provide 'gnus-autoloads)\n")
672       (write-region start (point) autoloads))
673     (byte-compile-file customload)
674     (byte-compile-file autoloads))
675   (message "\
676 Re-splitting gnus-load.el into custom-load.el and auto-autoloads.el...done
677 \n"))
678
679 \f
680 (defconst dgnushack-info-file-regexp-en
681   (let ((names '("gnus" "message" "emacs-mime"))
682         regexp name)
683     (while (setq name (pop names))
684       (setq regexp (concat regexp "^" name "\\.info\\(-[0-9]+\\)?$"
685                            (when names "\\|"))))
686     regexp)
687   "Regexp matching English info files.")
688
689 (defconst dgnushack-info-file-regexp-ja
690   (let ((names '("gnus-ja" "message-ja"))
691         regexp name)
692     (while (setq name (pop names))
693       (setq regexp (concat regexp "^" name "\\.info\\(-[0-9]+\\)?$"
694                            (when names "\\|"))))
695     regexp)
696   "Regexp matching Japanese info files.")
697
698 (defun dgnushack-remove-extra-files-in-package ()
699   "Remove extra files in the lisp directory of the XEmacs package."
700   (let ((lisp-dir (expand-file-name (concat "lisp/"
701                                             ;; GNUS_PRODUCT_NAME
702                                             (cadr command-line-args-left)
703                                             "/")
704                                     ;; PACKAGEDIR
705                                     (car command-line-args-left))))
706     (when (file-directory-p lisp-dir)
707       (let (files)
708         (dolist (file dgnushack-exporting-files)
709           (setq files (nconc files (list file (concat file "c")))))
710         (dolist (file (directory-files lisp-dir nil nil t t))
711           (unless (member file files)
712             (setq file (expand-file-name file lisp-dir))
713             (message "Removing %s..." file)
714             (condition-case nil
715                 (delete-file file)
716               (error nil))))))))
717
718 (defun dgnushack-install-package-manifest ()
719   "Install MANIFEST file as an XEmacs package."
720   (let* ((package-dir (car command-line-args-left))
721          (product-name (cadr command-line-args-left))
722          (name (expand-file-name (concat "pkginfo/MANIFEST." product-name)
723                                  package-dir))
724          make-backup-files)
725     (message "Generating %s..." name)
726     (with-temp-file name
727       (insert "pkginfo/MANIFEST." product-name "\n")
728       (let ((lisp-dir (concat "lisp/" product-name "/"))
729             (files (sort (directory-files "." nil "\\.elc?$" t) 'string-lessp))
730             file)
731         (while (setq file (pop files))
732           (unless (member file dgnushack-unexporting-files)
733             (insert lisp-dir file "\n")))
734         (setq files
735               (sort (directory-files "../texi/" nil
736                                      (concat dgnushack-info-file-regexp-en
737                                              "\\|"
738                                              dgnushack-info-file-regexp-ja)
739                                      t)
740                     'string-lessp))
741         (while (setq file (pop files))
742           (insert "info/" file "\n"))))))
743
744 \f
745 (define-compiler-macro describe-key-briefly (&whole form key &optional insert)
746   (if (condition-case nil
747           (progn
748             (describe-key-briefly '((())) nil)
749             t)
750         (wrong-number-of-arguments nil);; Old Emacsen.
751         (error t))
752       form
753     (if insert
754         `(if ,insert
755              (insert (funcall 'describe-key-briefly ,key))
756            (funcall 'describe-key-briefly ,key))
757       `(funcall 'describe-key-briefly ,key))))
758
759 ;;; dgnushack.el ends here