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