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