Initial Commit
[packages] / xemacs-packages / w3 / lisp / docomp.el
1 ;;; First things first - if they do not have the WIDGETDIR environment
2 ;;; variable set, choke, scream, and die.
3 (require 'cl)
4
5 (setq srcdir (or (getenv "W3SRCDIR") "."))
6
7 (push srcdir load-path)
8 (push (or (getenv "GNUSDIR") (expand-file-name "../../gnus/lisp/" srcdir))
9       load-path)
10 (push (or (getenv "URLDIR") (expand-file-name "../../url/lisp/" srcdir))
11       load-path)
12
13 (setq max-specpdl-size (* 1000 max-specpdl-size)
14       max-lisp-eval-depth (* 1000 max-lisp-eval-depth))
15
16 ;; If we are building w3 in a different directory than the source
17 ;; directory, we must read *.el from source directory and write *.elc
18 ;; into the building directory.  For that, we define this function
19 ;; before loading bytecomp.  Bytecomp doesn't overwrite this function.
20 (unless (featurep 'xemacs)
21   (defun byte-compile-dest-file (filename)
22     "Convert an Emacs Lisp source file name to a compiled file name.
23  In addition, remove directory name part from FILENAME."
24     (setq filename (byte-compiler-base-file-name filename))
25     (setq filename (file-name-sans-versions filename))
26     (setq filename (file-name-nondirectory filename))
27     (if (memq system-type '(win32 w32 mswindows windows-nt))
28         (setq filename (downcase filename)))
29     (cond ((eq system-type 'vax-vms)
30            (concat (substring filename 0 (string-match ";" filename)) "c"))
31           ((string-match emacs-lisp-file-regexp filename)
32            (concat (substring filename 0 (match-beginning 0)) ".elc"))
33           (t (concat filename ".elc")))))
34
35 (require 'bytecomp)
36
37 ;; Emacs 19 byte compiler complains about too much stuff by default.
38 ;; Turn off most of the warnings here.
39 ;; XEmacs; warnings, please
40 (setq ; byte-compile-warnings nil
41       byte-optimize t)
42
43 (defun compile-it ()
44   (let ((files (directory-files "." t ".*.[eE][lL]$" nil)))
45     (while files
46       (if (and (not (file-directory-p (car files)))
47                (not (string-match "w3-sysdp.el$" (car files))))
48           (byte-compile-file (car files)))
49       (setq files (cdr files)))))
50
51 (defun emacs-build-autoloads (dir autofile)
52   (require 'autoload)
53   (let ((files (directory-files dir t ".*.[eE][lL]$" nil)))
54     (save-excursion
55       (find-file autofile)
56       (erase-buffer)
57       (mapc 'generate-file-autoloads files)
58       (goto-char (point-max))
59       (insert "\n(provide 'w3-autoloads)\n")
60       (save-buffer)
61       (kill-buffer (current-buffer))))
62
63   ;; Now we need to munge that file to deal with
64   (find-file "w3-auto.el")
65   (erase-buffer)
66   (insert-file-contents autofile)
67   (goto-char (point-min))
68   (while (re-search-forward "w3-autoloads" nil t)
69       (replace-match "w3-auto"))
70   (save-buffer)
71   (kill-buffer (current-buffer))
72   (kill-emacs))
73
74 (defun emacs-batch-build-autoloads ()
75   (emacs-build-autoloads (nth 0 command-line-args-left)
76                          (nth 1 command-line-args-left)))
77
78 (defun emacs-build-custom-load (dir)
79   (let ((foundit t))
80     (save-excursion
81       (condition-case ()
82           (load-library "cus-dep")
83         (error (setq foundit nil)))
84       (if foundit
85           (let ((command-line-args-left (list dir)))
86             (Custom-make-dependencies))
87         (write-region "\n" nil "cus-load.el")))))
88
89 (defun emacs-batch-build-custom-load ()
90   (emacs-build-custom-load (car command-line-args-left)))
91
92 (or (fboundp 'declare-function)
93     (defmacro declare-function (function file &optional arglist fileonly)
94       `(autoload ',function ,file)))