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