051c2f5f43a2204ae3c2499e8ae4b4a42bcb809f
[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"
75                                  (delete "mess-bbdb.el" files)))))
76     (while (setq file (pop files))
77       (when (or (and (not xemacs)
78                      (not (member file '("gnus-xmas.el" "gnus-picon.el"
79                                          "messagexmas.el" "nnheaderxm.el"
80                                          "smiley.el" "x-overlay.el"))))
81                 (and xemacs
82                      (not (member file '("md5.el")))))
83         (when (or (not (file-exists-p (setq elc (concat file "c"))))
84                   (file-newer-than-file-p file elc))
85           (ignore-errors
86             (byte-compile-file file)))))))
87
88 (defun dgnushack-recompile ()
89   (require 'gnus)
90   (byte-recompile-directory "." 0))
91
92 \f
93 ;; Avoid byte-compile warnings.
94 (defvar gnus-product-name)
95 (defvar early-package-load-path)
96 (defvar early-packages)
97 (defvar last-package-load-path)
98 (defvar last-packages)
99 (defvar late-package-load-path)
100 (defvar late-packages)
101
102 (defconst dgnushack-info-file-regexp
103   "^\\(gnus\\|message\\|gnus-ja\\|message-ja\\)\\.info\\(-[0-9]+\\)?$")
104
105 (defconst dgnushack-texi-file-regexp
106   "^\\(gnus\\|message\\|gnus-ja\\|message-ja\\)\\.texi$")
107
108 (defun dgnushack-make-package ()
109   (require 'gnus)
110   (let* ((product-name (downcase gnus-product-name))
111          (lisp-dir (concat "lisp/" product-name "/"))
112          make-backup-files)
113
114     (message "Updating autoloads for directory %s..." default-directory)
115     (let ((generated-autoload-file "auto-autoloads.el")
116           noninteractive)
117       (update-autoloads-from-directory default-directory))
118     (byte-compile-file "auto-autoloads.el")
119
120     (with-temp-buffer
121       (let ((standard-output (current-buffer)))
122         (Custom-make-dependencies "."))
123       (message (buffer-string)))
124     (require 'cus-load)
125     (byte-compile-file "custom-load.el")
126
127     (message "Generating MANIFEST.%s for the package..." product-name)
128     (with-temp-buffer
129       (insert "pkginfo/MANIFEST." product-name "\n"
130               lisp-dir
131               (mapconcat
132                'identity
133                (sort (directory-files "." nil "\\.elc?$")
134                      'string-lessp)
135                (concat "\n" lisp-dir))
136               "\ninfo/"
137               (mapconcat
138                'identity
139                (sort (directory-files "../texi/"
140                                       nil dgnushack-info-file-regexp)
141                      'string-lessp)
142                "\ninfo/")
143               "\n")
144       (write-file (concat "../MANIFEST." product-name)))))
145
146 (defun dgnushack-install-package ()
147   (let ((package-dir (car command-line-args-left))
148         dirs info-dir pkginfo-dir product-name lisp-dir manifest files)
149     (unless package-dir
150       (when (boundp 'early-packages)
151         (setq dirs (delq nil (append (when early-package-load-path
152                                        early-packages)
153                                      (when late-package-load-path
154                                        late-packages)
155                                      (when last-package-load-path
156                                        last-packages))))
157         (while (and dirs (not package-dir))
158           (when (file-exists-p (car dirs))
159             (setq package-dir (car dirs)
160                   dirs (cdr dirs))))))
161     (unless package-dir
162       (error "%s" "
163 You must specify the name of the package path as follows:
164
165 % make install-package PACKAGEDIR=/usr/local/lib/xemacs/xemacs-packages
166 "
167              ))
168     (setq info-dir (expand-file-name "info/" package-dir)
169           pkginfo-dir (expand-file-name "pkginfo/" package-dir))
170     (require 'gnus)
171     (setq product-name (downcase gnus-product-name)
172           lisp-dir (expand-file-name (concat "lisp/" product-name "/")
173                                      package-dir)
174           manifest (concat "MANIFEST." product-name))
175
176     (unless (file-directory-p lisp-dir)
177       (make-directory lisp-dir t))
178     (unless (file-directory-p info-dir)
179       (make-directory info-dir))
180     (unless (file-directory-p pkginfo-dir)
181       (make-directory pkginfo-dir))
182
183     (setq files (sort (directory-files "." nil "\\.elc?$") 'string-lessp))
184     (mapcar
185      (lambda (file)
186        (unless (member file files)
187          (setq file (expand-file-name file lisp-dir))
188          (message "Removing %s..." file)
189          (condition-case nil
190              (delete-file file)
191            (error nil))))
192      (directory-files lisp-dir nil nil nil t))
193     (mapcar
194      (lambda (file)
195        (message "Copying %s to %s..." file lisp-dir)
196        (copy-file file (expand-file-name file lisp-dir) t t))
197      files)
198
199     (mapcar
200      (lambda (file)
201        (message "Copying ../texi/%s to %s..." file info-dir)
202        (copy-file (expand-file-name file "../texi/")
203                   (expand-file-name file info-dir)
204                   t t))
205      (sort (directory-files "../texi/" nil dgnushack-info-file-regexp)
206            'string-lessp))
207
208     (message "Copying ../%s to %s..." manifest pkginfo-dir)
209     (copy-file (expand-file-name manifest "../")
210                (expand-file-name manifest pkginfo-dir) t t)
211
212     (message "Done")))
213
214 (defun dgnushack-add-info-suffix-maybe ()
215   ;; This function must be invoked from lisp directory.
216   (setq default-directory "../texi/")
217   (let ((coding-system-for-read 'raw-text)
218         (coding-system-for-write 'raw-text)
219         (files (directory-files "." nil dgnushack-texi-file-regexp))
220         file make-backup-files)
221     (while (setq file (pop files))
222       (find-file file)
223       (when (and (re-search-forward
224                   "^@setfilename[\t ]+\\([^\t\n ]+\\)" nil t)
225                  (not (string-match "\\.info$" (match-string 1))))
226         (copy-file file (concat file "_") nil t)
227         (insert ".info")
228         (save-buffer))
229       (kill-buffer (current-buffer)))))
230
231 ;;; dgnushack.el ends here