2001-01-21 00:00:00 ShengHuo ZHU <zsh@cs.rochester.edu>
[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
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 (push (or (getenv "lispdir")
37           "/usr/share/emacs/site-lisp")
38       load-path)
39
40 (push (or (getenv "W3DIR") (expand-file-name "../../w3/lisp/" srcdir))
41       load-path)
42
43 (push "/usr/share/emacs/site-lisp" load-path)
44
45 (unless (featurep 'xemacs)
46   (define-compiler-macro last (&whole form x &optional n)
47     (if (and (fboundp 'last)
48              (subrp (symbol-function 'last)))
49         form
50       (if n
51           `(let* ((x ,x)
52                   (n ,n)
53                   (m 0)
54                   (p x))
55              (while (consp p)
56                (incf m)
57                (pop p))
58              (if (<= n 0)
59                  p
60                (if (< n m)
61                    (nthcdr (- m n) x)
62                  x)))
63         `(let ((x ,x))
64            (while (consp (cdr x))
65              (pop x))
66            x))))
67   )
68
69 ;; If we are building w3 in a different directory than the source
70 ;; directory, we must read *.el from source directory and write *.elc
71 ;; into the building directory.  For that, we define this function
72 ;; before loading bytecomp.  Bytecomp doesn't overwrite this function.
73 (defun byte-compile-dest-file (filename)
74   "Convert an Emacs Lisp source file name to a compiled file name.
75  In addition, remove directory name part from FILENAME."
76   (setq filename (byte-compiler-base-file-name filename))
77   (setq filename (file-name-sans-versions filename))
78   (setq filename (file-name-nondirectory filename))
79   (if (memq system-type '(win32 w32 mswindows windows-nt))
80       (setq filename (downcase filename)))
81   (cond ((eq system-type 'vax-vms)
82          (concat (substring filename 0 (string-match ";" filename)) "c"))
83         ((string-match emacs-lisp-file-regexp filename)
84          (concat (substring filename 0 (match-beginning 0)) ".elc"))
85         (t (concat filename ".elc"))))
86
87 (require 'bytecomp)
88
89 (push srcdir load-path)
90 (load (expand-file-name "lpath.el" srcdir) nil t)
91
92 (defalias 'device-sound-enabled-p 'ignore)
93 (defalias 'play-sound-file 'ignore)
94 (defalias 'nndb-request-article 'ignore)
95 (defalias 'efs-re-read-dir 'ignore)
96 (defalias 'ange-ftp-re-read-dir 'ignore)
97 (defalias 'define-mail-user-agent 'ignore)
98
99 (eval-and-compile
100   (unless (featurep 'xemacs)
101     (defalias 'get-popup-menu-response 'ignore)
102     (defalias 'event-object 'ignore)
103     (defalias 'x-defined-colors 'ignore)
104     (defalias 'read-color 'ignore)))
105
106 (defun dgnushack-compile (&optional warn)
107   ;;(setq byte-compile-dynamic t)
108   (unless warn
109     (setq byte-compile-warnings
110           '(free-vars unresolved callargs redefine)))
111   (unless (locate-library "cus-edit")
112     (error "You do not seem to have Custom installed.
113 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
114 You also then need to add the following to the lisp/dgnushack.el file:
115
116      (push \"~/lisp/custom\" load-path)
117
118 Modify to suit your needs."))
119   (let ((files (directory-files srcdir nil "^[^=].*\\.el$"))
120         ;;(byte-compile-generate-call-tree t)
121         file elc)
122     ;; Avoid barfing (from gnus-xmas) because the etc directory is not yet
123     ;; installed.
124     (when (featurep 'xemacs)
125       (setq gnus-xmas-glyph-directory "dummy"))
126     (dolist (file '("dgnushack.el" "lpath.el"))
127       (setq files (delete file files)))
128     (when (featurep 'base64)
129       (setq files (delete "base64.el" files)))
130     (condition-case code
131         (require 'w3-forms)
132       (error
133        (message "No w3: %s %s" code (locate-library "w3-forms"))
134        (dolist (file '("nnweb.el" "nnlistserv.el" "nnultimate.el"
135                        "nnslashdot.el" "nnwarchive.el" "webmail.el"
136                        "nnwfm.el"))
137          (setq files (delete file files)))))
138     (dolist (file
139              (if (featurep 'xemacs)
140                  '("md5.el" "smiley-ems.el")
141                '("gnus-xmas.el" "gnus-picon.el" "messagexmas.el"
142                  "nnheaderxm.el" "smiley.el")))
143       (setq files (delete file files)))
144
145     (dolist (file files)
146       (setq file (expand-file-name file srcdir))
147       (when (and (file-exists-p
148                   (setq elc (concat (file-name-nondirectory file) "c")))
149                  (file-newer-than-file-p file elc))
150         (delete-file elc)))
151
152     (while (setq file (pop files))
153       (setq file (expand-file-name file srcdir))
154       (when (or (not (file-exists-p
155                       (setq elc (concat (file-name-nondirectory file) "c"))))
156                 (file-newer-than-file-p file elc))
157         (ignore-errors
158           (byte-compile-file file))))))
159
160 (defun dgnushack-recompile ()
161   (require 'gnus)
162   (byte-recompile-directory "." 0))
163
164 ;;; dgnushack.el ends here