Speedups; see ChangeLog for fine details.
[elisp/gnus.git-] / lisp / dgnushack.el
1 ;;; dgnushack.el --- a hack to set the load path for byte-compiling
2 ;; Copyright (C) 1994,95,96,97,98,99 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;;      Katsumi Yamaoka <yamaoka@jpl.org>
6 ;; Version: 4.19
7 ;; Keywords: news, path
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (fset 'facep 'ignore)
31
32 (require 'cl)
33 (require 'bytecomp)
34 (push "~/lisp/custom" load-path)
35 (push "." load-path)
36 (load "./lpath.el" nil t)
37
38 (defalias 'device-sound-enabled-p 'ignore)
39 (defalias 'play-sound-file 'ignore)
40 (defalias 'nndb-request-article 'ignore)
41 (defalias 'efs-re-read-dir 'ignore)
42 (defalias 'ange-ftp-re-read-dir 'ignore)
43 (defalias 'define-mail-user-agent 'ignore)
44
45 (eval-and-compile
46   (unless (string-match "XEmacs" emacs-version)
47     (fset 'get-popup-menu-response 'ignore)
48     (fset 'event-object 'ignore)
49     (fset 'x-defined-colors 'ignore)
50     (fset 'read-color 'ignore)))
51
52 (defun dgnushack-compile (&optional warn)
53   ;;(setq byte-compile-dynamic t)
54   (unless warn
55     (setq byte-compile-warnings
56           '(free-vars unresolved callargs redefine)))
57   (unless (locate-library "cus-edit")
58     (error "You do not seem to have Custom installed.
59 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
60 You also then need to add the following to the lisp/dgnushack.el file:
61
62      (push \"~/lisp/custom\" load-path)
63
64 Modify to suit your needs."))
65   (let ((files (directory-files "." nil "^[^=].*\\.el$"))
66         (xemacs (string-match "XEmacs" emacs-version))
67         ;;(byte-compile-generate-call-tree t)
68         file elc)
69     (condition-case ()
70         (require 'w3-forms)
71       (error (setq files (delete "nnweb.el" (delete "nnlistserv.el" files)))))
72     (condition-case ()
73         (require 'bbdb)
74       (error (setq files (delete "gnus-bbdb.el" files))))
75     (while (setq file (pop files))
76       (when (or (and (not xemacs)
77                      (not (member file '("gnus-xmas.el" "gnus-picon.el"
78                                          "messagexmas.el" "nnheaderxm.el"
79                                          "smiley.el" "x-overlay.el"))))
80                 (and xemacs
81                      (not (member file '("md5.el")))))
82         (when (or (not (file-exists-p (setq elc (concat file "c"))))
83                   (file-newer-than-file-p file elc))
84           (ignore-errors
85             (byte-compile-file file)))))))
86
87 (defun dgnushack-recompile ()
88   (require 'gnus)
89   (byte-recompile-directory "." 0))
90
91 \f
92 ;; Avoid byte-compile warnings.
93 (defvar gnus-product-name)
94 (defvar early-package-load-path)
95 (defvar early-packages)
96 (defvar last-package-load-path)
97 (defvar last-packages)
98 (defvar late-package-load-path)
99 (defvar late-packages)
100
101 (defconst dgnushack-info-file-regexp
102   "^\\(gnus\\|message\\|gnus-ja\\|message-ja\\)\\.info\\(-[0-9]+\\)?$")
103
104 (defconst dgnushack-texi-file-regexp
105   "^\\(gnus\\|message\\|gnus-ja\\|message-ja\\)\\.texi$")
106
107 (defun dgnushack-make-package ()
108   (require 'gnus)
109   (let* ((product-name (downcase gnus-product-name))
110          (lisp-dir (concat "lisp/" product-name "/"))
111          make-backup-files)
112
113     (message "Updating autoloads for directory %s..." default-directory)
114     (let ((generated-autoload-file "auto-autoloads.el")
115           noninteractive)
116       (update-autoloads-from-directory default-directory))
117     (byte-compile-file "auto-autoloads.el")
118
119     (with-temp-buffer
120       (let ((standard-output (current-buffer)))
121         (Custom-make-dependencies "."))
122       (message (buffer-substring (point-min) (point-max))))
123     (require 'cus-load)
124     (byte-compile-file "custom-load.el")
125
126     (message "Generating MANIFEST.%s for the package..." product-name)
127     (with-temp-buffer
128       (insert "pkginfo/MANIFEST." product-name "\n"
129               lisp-dir
130               (mapconcat
131                'identity
132                (sort (directory-files "." nil "\\.elc?$")
133                      'string-lessp)
134                (concat "\n" lisp-dir))
135               "\ninfo/"
136               (mapconcat
137                'identity
138                (sort (directory-files "../texi/"
139                                       nil dgnushack-info-file-regexp)
140                      'string-lessp)
141                "\ninfo/")
142               "\n")
143       (write-file (concat "../MANIFEST." product-name)))))
144
145 (defun dgnushack-install-package ()
146   (let ((package-dir (car command-line-args-left))
147         dirs info-dir pkginfo-dir product-name lisp-dir manifest files)
148     (unless package-dir
149       (when (boundp 'early-packages)
150         (setq dirs (delq nil (append (when early-package-load-path
151                                        early-packages)
152                                      (when late-package-load-path
153                                        late-packages)
154                                      (when last-package-load-path
155                                        last-packages))))
156         (while (and dirs (not package-dir))
157           (when (file-exists-p (car dirs))
158             (setq package-dir (car dirs)
159                   dirs (cdr dirs))))))
160     (unless package-dir
161       (error "%s" "
162 You must specify the name of the package path as follows:
163
164 % make install-package PACKAGEDIR=/usr/local/lib/xemacs/xemacs-packages
165 "
166              ))
167     (setq info-dir (expand-file-name "info/" package-dir)
168           pkginfo-dir (expand-file-name "pkginfo/" package-dir))
169     (require 'gnus)
170     (setq product-name (downcase gnus-product-name)
171           lisp-dir (expand-file-name (concat "lisp/" product-name "/")
172                                      package-dir)
173           manifest (concat "MANIFEST." product-name))
174
175     (unless (file-directory-p lisp-dir)
176       (make-directory lisp-dir t))
177     (unless (file-directory-p info-dir)
178       (make-directory info-dir))
179     (unless (file-directory-p pkginfo-dir)
180       (make-directory pkginfo-dir))
181
182     (setq files (sort (directory-files "." nil "\\.elc?$") 'string-lessp))
183     (mapcar
184      (lambda (file)
185        (unless (member file files)
186          (setq file (expand-file-name file lisp-dir))
187          (message "Removing %s..." file)
188          (condition-case nil
189              (delete-file file)
190            (error nil))))
191      (directory-files lisp-dir nil nil nil t))
192     (mapcar
193      (lambda (file)
194        (message "Copying %s to %s..." file lisp-dir)
195        (copy-file file (expand-file-name file lisp-dir) t t))
196      files)
197
198     (mapcar
199      (lambda (file)
200        (message "Copying ../texi/%s to %s..." file info-dir)
201        (copy-file (expand-file-name file "../texi/")
202                   (expand-file-name file info-dir)
203                   t t))
204      (sort (directory-files "../texi/" nil dgnushack-info-file-regexp)
205            'string-lessp))
206
207     (message "Copying ../%s to %s..." manifest pkginfo-dir)
208     (copy-file (expand-file-name manifest "../")
209                (expand-file-name manifest pkginfo-dir) t t)
210
211     (message "Done")))
212
213 (defun dgnushack-add-info-suffix-maybe ()
214   ;; This function must be invoked from lisp directory.
215   (setq default-directory "../texi/")
216   (let ((coding-system-for-read 'raw-text)
217         (coding-system-for-write 'raw-text)
218         (files (directory-files "." nil dgnushack-texi-file-regexp))
219         file make-backup-files)
220     (while (setq file (pop files))
221       (find-file file)
222       (when (and (re-search-forward
223                   "^@setfilename[\t ]+\\([^\t\n ]+\\)" nil t)
224                  (not (string-match "\\.info$" (match-string 1))))
225         (copy-file file (concat file "_") nil t)
226         (insert ".info")
227         (save-buffer))
228       (kill-buffer (current-buffer)))))
229
230 ;;; dgnushack.el ends here