77da9b95dbb4b0a895a86df76546623e53d54a66
[gnus] / 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, 2003
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.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 (defalias 'facep 'ignore)
31
32 (require 'cl)
33
34 (defvar srcdir (or (getenv "srcdir") "."))
35
36 (defun my-getenv (str)
37   (let ((val (getenv str)))
38     (if (equal val "no") nil val)))
39
40 (if (my-getenv "lispdir")
41     (push (my-getenv "lispdir") load-path))
42
43 (push (or (my-getenv "URLDIR") (expand-file-name "../../url/lisp/" srcdir))
44       load-path)
45
46 (push (or (my-getenv "W3DIR") (expand-file-name "../../w3/lisp/" srcdir))
47       load-path)
48
49 ;(push "/usr/share/emacs/site-lisp" load-path)
50
51 ;; If we are building w3 in a different directory than the source
52 ;; directory, we must read *.el from source directory and write *.elc
53 ;; into the building directory.  For that, we define this function
54 ;; before loading bytecomp.  Bytecomp doesn't overwrite this function.
55 (defun byte-compile-dest-file (filename)
56   "Convert an Emacs Lisp source file name to a compiled file name.
57  In addition, remove directory name part from FILENAME."
58   (setq filename (byte-compiler-base-file-name filename))
59   (setq filename (file-name-sans-versions filename))
60   (setq filename (file-name-nondirectory filename))
61   (if (memq system-type '(win32 w32 mswindows windows-nt))
62       (setq filename (downcase filename)))
63   (cond ((eq system-type 'vax-vms)
64          (concat (substring filename 0 (string-match ";" filename)) "c"))
65         ((string-match emacs-lisp-file-regexp filename)
66          (concat (substring filename 0 (match-beginning 0)) ".elc"))
67         (t (concat filename ".elc"))))
68
69 (require 'bytecomp)
70 ;; To avoid having defsubsts and inlines happen.
71 ;(if (featurep 'xemacs)
72 ;    (require 'byte-optimize)
73 ;  (require 'byte-opt))
74 ;(defun byte-optimize-inline-handler (form)
75 ;  "byte-optimize-handler for the `inline' special-form."
76 ;  (cons 'progn (cdr form)))
77 ;(defalias 'byte-compile-file-form-defsubst 'byte-compile-file-form-defun)
78
79 (when (and (not (featurep 'xemacs))
80            (= emacs-major-version 21)
81            (= emacs-minor-version 3)
82            (condition-case code
83                (let ((byte-compile-error-on-warn t))
84                  (byte-optimize-form (quote (pop x)) t)
85                  nil)
86              (error (string-match "called for effect"
87                                   (error-message-string code)))))
88   (defadvice byte-optimize-form-code-walker (around silence-warn-for-pop
89                                                     (form for-effect)
90                                                     activate)
91     "Silence the warning \"...called for effect\" for the `pop' form.
92 It is effective only when the `pop' macro is defined by cl.el rather
93 than subr.el."
94     (let (tmp)
95       (if (and (eq (car-safe form) 'car)
96                for-effect
97                (setq tmp (get 'car 'side-effect-free))
98                (not byte-compile-delete-errors)
99                (not (eq tmp 'error-free))
100                (eq (car-safe (cadr form)) 'prog1)
101                (let ((var (cadr (cadr form)))
102                      (last (nth 2 (cadr form))))
103                  (and (symbolp var)
104                       (null (nthcdr 3 (cadr form)))
105                       (eq (car-safe last) 'setq)
106                       (eq (cadr last) var)
107                       (eq (car-safe (nth 2 last)) 'cdr)
108                       (eq (cadr (nth 2 last)) var))))
109           (progn
110             (put 'car 'side-effect-free 'error-free)
111             (unwind-protect
112                 ad-do-it
113               (put 'car 'side-effect-free tmp)))
114         ad-do-it))))
115
116 (push srcdir load-path)
117 (load (expand-file-name "lpath.el" srcdir) nil t)
118
119 (defalias 'device-sound-enabled-p 'ignore)
120 (defalias 'play-sound-file 'ignore)
121 (defalias 'nndb-request-article 'ignore)
122 (defalias 'efs-re-read-dir 'ignore)
123 (defalias 'ange-ftp-re-read-dir 'ignore)
124 (defalias 'define-mail-user-agent 'ignore)
125
126 (eval-and-compile
127   (unless (featurep 'xemacs)
128     (defalias 'get-popup-menu-response 'ignore)
129     (defalias 'event-object 'ignore)
130     (defalias 'x-defined-colors 'ignore)
131     (defalias 'read-color 'ignore)))
132
133 (eval-and-compile
134   (when (featurep 'xemacs)
135     ;; XEmacs 21.1 needs some extra hand holding
136     (when (eq emacs-minor-version 1)
137       (autoload 'custom-declare-face "cus-face" nil t)
138       (autoload 'cl-compile-time-init "cl-macs" nil t)
139       (autoload 'defadvice "advice" nil nil 'macro))
140     (unless (fboundp 'defadvice)
141       (autoload 'defadvice "advice" nil nil 'macro))
142     (autoload 'Info-directory "info" nil t)
143     (autoload 'Info-menu "info" nil t)
144     (autoload 'annotations-at "annotations")
145     (autoload 'apropos "apropos" nil t)
146     (autoload 'apropos-command "apropos" nil t)
147     (autoload 'bbdb-complete-name "bbdb-com" nil t)
148     (autoload 'browse-url "browse-url" nil t)
149     (autoload 'customize-apropos "cus-edit" nil t)
150     (autoload 'customize-save-variable "cus-edit" nil t)
151     (autoload 'customize-variable "cus-edit" nil t)
152     (autoload 'delete-annotation "annotations")
153     (autoload 'dolist "cl-macs" nil nil 'macro)
154     (autoload 'enriched-decode "enriched")
155     (autoload 'info "info" nil t)
156     (autoload 'make-annotation "annotations")
157     (autoload 'make-display-table "disp-table")
158     (autoload 'pp "pp")
159     (autoload 'ps-despool "ps-print" nil t)
160     (autoload 'ps-spool-buffer "ps-print" nil t)
161     (autoload 'ps-spool-buffer-with-faces "ps-print" nil t)
162     (autoload 'read-passwd "passwd")
163     (autoload 'regexp-opt "regexp-opt")
164     (autoload 'reporter-submit-bug-report "reporter")
165     (if (emacs-version>= 21 5)
166         (autoload 'setenv "process" nil t)
167       (autoload 'setenv "env" nil t))
168     (autoload 'smtpmail-send-it "smtpmail")
169     (autoload 'sort-numeric-fields "sort" nil t)
170     (autoload 'sort-subr "sort")
171     (autoload 'trace-function-background "trace" nil t)
172     (autoload 'w3-do-setup "w3")
173     (autoload 'w3-prepare-buffer "w3-display")
174     (autoload 'w3-region "w3-display" nil t)
175     (defalias 'frame-char-height 'frame-height)
176     (defalias 'frame-char-width 'frame-width)
177     (defalias 'frame-parameter 'frame-property)
178     (defalias 'make-overlay 'ignore)
179     (defalias 'overlay-end 'ignore)
180     (defalias 'overlay-get 'ignore)
181     (defalias 'overlay-put 'ignore)
182     (defalias 'overlay-start 'ignore)
183     (defalias 'overlays-in 'ignore)
184     (defalias 'replace-dehighlight 'ignore)
185     (defalias 'replace-highlight 'ignore)
186     (defalias 'run-with-idle-timer 'ignore)
187     (defalias 'w3-coding-system-for-mime-charset 'ignore)))
188
189 (defun dgnushack-compile-verbosely ()
190   "Call dgnushack-compile with warnings ENABLED.  If you are compiling
191 patches to gnus, you should consider modifying make.bat to call
192 dgnushack-compile-verbosely.  All other users should continue to use
193 dgnushack-compile."
194   (dgnushack-compile t))
195
196 (defun dgnushack-compile (&optional warn)
197   ;;(setq byte-compile-dynamic t)
198   (unless warn
199     (setq byte-compile-warnings
200           '(free-vars unresolved callargs redefine)))
201   (unless (locate-library "cus-edit")
202     (error "You do not seem to have Custom installed.
203 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
204 You also then need to add the following to the lisp/dgnushack.el file:
205
206      (push \"~/lisp/custom\" load-path)
207
208 Modify to suit your needs."))
209   (let ((files (directory-files srcdir nil "^[^=].*\\.el$"))
210         ;;(byte-compile-generate-call-tree t)
211         file elc)
212     ;; Avoid barfing (from gnus-xmas) because the etc directory is not yet
213     ;; installed.
214     (when (featurep 'xemacs)
215       (setq gnus-xmas-glyph-directory "dummy"))
216     (dolist (file '("dgnushack.el" "lpath.el"))
217       (setq files (delete file files)))
218     (when (featurep 'base64)
219       (setq files (delete "base64.el" files)))
220     (condition-case code
221         (require 'w3-parse)
222       (error
223        (message "No w3: %s %s" (cadr code) (or (locate-library "w3-parse") ""))
224        (dolist (file '("nnultimate.el" "webmail.el" "nnwfm.el"))
225          (setq files (delete file files)))))
226     (condition-case code
227         (require 'mh-e)
228       (error
229        (message "No mh-e: %s %s" (cadr code) (or (locate-library "mh-e") ""))
230        (setq files (delete "gnus-mh.el" files))))
231     (condition-case code
232         (require 'xml)
233       (error
234        (message "No xml: %s %s" (cadr code) (or (locate-library "xml") ""))
235        (setq files (delete "nnrss.el" files))))
236     (dolist (file
237              (if (featurep 'xemacs)
238                  '("md5.el")
239                '("gnus-xmas.el" "messagexmas.el" "nnheaderxm.el")))
240       (setq files (delete file files)))
241
242     (dolist (file files)
243       (setq file (expand-file-name file srcdir))
244       (when (and (file-exists-p
245                   (setq elc (concat (file-name-nondirectory file) "c")))
246                  (file-newer-than-file-p file elc))
247         (delete-file elc)))
248
249     (while (setq file (pop files))
250       (setq file (expand-file-name file srcdir))
251       (when (or (not (file-exists-p
252                       (setq elc (concat (file-name-nondirectory file) "c"))))
253                 (file-newer-than-file-p file elc))
254         (ignore-errors
255           (byte-compile-file file))))))
256
257 (defun dgnushack-recompile ()
258   (require 'gnus)
259   (byte-recompile-directory "." 0))
260
261 (defvar dgnushack-gnus-load-file
262   (if (featurep 'xemacs)
263       (expand-file-name "auto-autoloads.el")
264     (expand-file-name "gnus-load.el")))
265
266 (defvar dgnushack-cus-load-file 
267   (if (featurep 'xemacs)
268       (expand-file-name "custom-load.el")
269     (expand-file-name "cus-load.el")))
270
271 (defun dgnushack-make-cus-load ()
272   (load "cus-dep")
273   (let ((cusload-base-file dgnushack-cus-load-file))
274     (if (fboundp 'custom-make-dependencies)
275         (custom-make-dependencies)
276       (Custom-make-dependencies))
277     (when (featurep 'xemacs)
278       (message "Compiling %s..." dgnushack-cus-load-file)
279       (byte-compile-file dgnushack-cus-load-file))))
280
281 (defun dgnushack-make-auto-load ()
282   (require 'autoload)
283   (unless (make-autoload '(define-derived-mode child parent name
284                             "docstring" body)
285                          "file")
286     (defadvice make-autoload (around handle-define-derived-mode activate)
287       "Handle `define-derived-mode'."
288       (if (eq (car-safe (ad-get-arg 0)) 'define-derived-mode)
289           (setq ad-return-value
290                 (list 'autoload
291                       (list 'quote (nth 1 (ad-get-arg 0)))
292                       (ad-get-arg 1)
293                       (nth 4 (ad-get-arg 0))
294                       t nil))
295         ad-do-it))
296     (put 'define-derived-mode 'doc-string-elt 3))
297   (let ((generated-autoload-file dgnushack-gnus-load-file)
298         (make-backup-files nil)
299         (autoload-package-name "gnus"))
300     (if (featurep 'xemacs)
301         (if (file-exists-p generated-autoload-file)
302             (delete-file generated-autoload-file))
303       (with-temp-file generated-autoload-file
304         (insert ?\014)))
305     (batch-update-autoloads)))
306
307 (defun dgnushack-make-load ()
308   (unless (featurep 'xemacs)
309     (message "Generating %s..." dgnushack-gnus-load-file)
310     (with-temp-file dgnushack-gnus-load-file
311       (insert-file-contents dgnushack-cus-load-file)
312       (delete-file dgnushack-cus-load-file)
313       (goto-char (point-min))
314       (search-forward ";;; Code:")
315       (forward-line)
316       (delete-region (point-min) (point))
317       (insert "\
318 ;;; gnus-load.el --- automatically extracted custom dependencies and autoload
319 ;;
320 ;;; Code:
321 ")
322       (goto-char (point-max))
323       (if (search-backward "custom-versions-load-alist" nil t)
324           (forward-line -1)
325         (forward-line -1)
326         (while (eq (char-after) ?\;)
327           (forward-line -1))
328         (forward-line))
329       (delete-region (point) (point-max))
330       (insert "\n")
331       ;; smiley-* are duplicated. Remove them all.
332       (let ((point (point)))
333         (insert-file-contents dgnushack-gnus-load-file)
334         (goto-char point)
335         (while (search-forward "smiley-" nil t)
336           (beginning-of-line)
337           (if (looking-at "(autoload ")
338               (delete-region (point) (progn (forward-sexp) (point)))
339             (forward-line))))
340       ;;
341       (goto-char (point-max))
342       (when (search-backward "\n(provide " nil t)
343         (forward-line -1)
344         (delete-region (point) (point-max)))
345       (insert "\
346
347 \(provide 'gnus-load)
348
349 ;;; Local Variables:
350 ;;; version-control: never
351 ;;; no-byte-compile: t
352 ;;; no-update-autoloads: t
353 ;;; End:
354 ;;; gnus-load.el ends here
355 ")
356       ))
357   (message "Compiling %s..." dgnushack-gnus-load-file)
358   (byte-compile-file dgnushack-gnus-load-file)
359   (when (featurep 'xemacs)
360     (message "Creating dummy gnus-load.el...")
361     (with-temp-file (expand-file-name "gnus-load.el")
362       (insert "\
363
364 \(provide 'gnus-load)
365
366 ;;; Local Variables:
367 ;;; version-control: never
368 ;;; no-byte-compile: t
369 ;;; no-update-autoloads: t
370 ;;; End:
371 ;;; gnus-load.el ends here"))))
372
373
374 ;;; dgnushack.el ends here