1 ;;; install.el --- Emacs Lisp package install utility
3 ;; Copyright (C) 1996,1997,1998,1999,2001 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Keywords: install, byte-compile, directory detection
9 ;; This file is part of APEL (A Portable Emacs Library).
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
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
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 (require 'poe) ; make-directory for v18
29 (require 'path-util) ; default-load-path
32 ;;; @ compile Emacs Lisp files
35 (defun compile-elisp-module (module &optional path every-time)
36 (setq module (expand-file-name (symbol-name module) path))
37 (let ((el-file (concat module ".el"))
38 (elc-file (concat module ".elc")))
40 (file-newer-than-file-p el-file elc-file))
41 (byte-compile-file el-file))))
43 (defun compile-elisp-modules (modules &optional path every-time)
47 (compile-elisp-module module path every-time)))
54 (defvar install-overwritten-file-modes (+ (* 64 6)(* 8 4) 4)) ; 0644
56 (defun install-file (file src dest &optional move overwrite just-print)
58 (princ (format "%s -> %s\n" file dest))
59 (let ((src-file (expand-file-name file src)))
60 (if (file-exists-p src-file)
61 (let ((full-path (expand-file-name file dest)))
62 (if (and (file-exists-p full-path) overwrite)
63 (delete-file full-path))
64 (copy-file src-file full-path t t)
65 (set-file-modes full-path install-overwritten-file-modes)
68 (while (and (file-exists-p src-file)
69 (file-writable-p src-file))
72 (delete-file src-file)
74 (error (princ (format "%s\n" (nth 1 err))))))))
75 (princ (format "%s -> %s\n" file dest)))))))
77 (defun install-files (files src dest &optional move overwrite just-print)
80 (make-directory dest t))
84 (install-file file src dest move overwrite just-print)))
88 ;;; @@ install Emacs Lisp files
91 (defun install-elisp-module (module src dest &optional just-print del-elc)
92 (let (el-file elc-file)
93 (let ((name (symbol-name module)))
94 (setq el-file (concat name ".el"))
95 (setq elc-file (concat name ".elc")))
96 (let ((src-file (expand-file-name el-file src)))
97 (if (not (file-exists-p src-file))
100 (princ (format "%s -> %s\n" el-file dest))
101 (let ((full-path (expand-file-name el-file dest)))
102 (if (file-exists-p full-path)
103 (delete-file full-path))
104 (copy-file src-file full-path t t)
105 (set-file-modes full-path install-overwritten-file-modes)
106 (princ (format "%s -> %s\n" el-file dest)))))
107 (setq src-file (expand-file-name elc-file src))
108 (if (not (file-exists-p src-file))
109 (let ((full-path (expand-file-name elc-file dest)))
110 (if (and del-elc (file-exists-p full-path))
112 (princ (format "%s -> to be deleted\n" full-path))
113 (delete-file full-path)
114 (princ (format "%s -> deleted\n" full-path)))))
116 (princ (format "%s -> %s\n" elc-file dest))
117 (let ((full-path (expand-file-name elc-file dest)))
118 (if (file-exists-p full-path)
119 (delete-file full-path))
120 (copy-file src-file full-path t t)
121 (set-file-modes full-path install-overwritten-file-modes)
123 (while (file-exists-p src-file)
126 (delete-file src-file)
128 (error (princ (format "%s\n" (nth 1 err)))))))
129 (princ (format "%s -> %s\n" elc-file dest))))))))
131 (defun install-elisp-modules (modules src dest &optional just-print del-elc)
134 (make-directory dest t))
138 (install-elisp-module module src dest just-print del-elc)))
142 ;;; @ detect install path
145 ;; install to shared directory (maybe "/usr/local")
146 (defvar install-prefix
147 (if (or (<= emacs-major-version 18)
149 (featurep 'meadow) ; for Meadow
150 (and (eq system-type 'windows-nt) ; for NTEmacs
151 (>= emacs-major-version 20)))
152 (expand-file-name "../../.." exec-directory)
153 (expand-file-name "../../../.." data-directory)))
155 (defvar install-elisp-prefix
156 (if (>= emacs-major-version 19)
158 ;; v18 does not have standard site directory.
161 (defun install-detect-elisp-directory (&optional prefix elisp-prefix
162 allow-version-specific)
164 (setq prefix install-prefix))
166 (setq elisp-prefix install-elisp-prefix))
168 (let ((rest default-load-path)
170 (expand-file-name (concat ".*/" elisp-prefix)
174 (if (string-match regexp (car rest))
175 (if (or allow-version-specific
176 (not (string-match (format "/%d\\.%d"
180 (throw 'tag (car rest))))
181 (setq rest (cdr rest)))))
182 (expand-file-name (concat (if (and (not (featurep 'xemacs))
183 (or (>= emacs-major-version 20)
184 (and (= emacs-major-version 19)
185 (> emacs-minor-version 28))))
193 ;; unfortunately, unofficial mule based on
194 ;; 19.29 and later use "emacs/" by default.
195 ((boundp 'MULE) "mule/")
196 ((boundp 'NEMACS) "nemacs/")
201 (defvar install-default-elisp-directory
202 (install-detect-elisp-directory))
205 ;;; @ for XEmacs package system
208 (defun install-update-package-files (package dir &optional just-print)
211 (princ (format "Updating autoloads in directory %s..\n\n" dir))
213 (princ (format "Processing %s\n" dir))
214 (princ "Generating custom-load.el...\n\n")
216 (princ (format "Compiling %s...\n"
217 (expand-file-name "auto-autoloads.el" dir)))
218 (princ (format "Wrote %s\n"
219 (expand-file-name "auto-autoloads.elc" dir)))
221 (princ (format "Compiling %s...\n"
222 (expand-file-name "custom-load.el" dir)))
223 (princ (format "Wrote %s\n"
224 (expand-file-name "custom-load.elc" dir))))
226 (setq autoload-package-name package)
228 (let ((command-line-args-left (list dir)))
229 (batch-update-directory))
231 (let ((command-line-args-left (list dir)))
232 (Custom-make-dependencies))
234 (byte-compile-file (expand-file-name "auto-autoloads.el" dir))
235 (byte-compile-file (expand-file-name "custom-load.el" dir)))))
238 ;;; @ Other Utilities
241 (defun install-just-print-p ()
242 (let ((flag (getenv "MAKEFLAGS"))
243 (case-fold-search nil))
244 (princ (format "%s\n" flag))
246 (string-match "^\\(\\(--[^ ]+ \\)+-\\|[^ =-]\\)*n" flag))))
253 (product-provide (provide 'install) (require 'apel-ver))
255 ;;; install.el ends here