1 ;;; install.el --- Emacs Lisp package install utility
3 ;; Copyright (C) 1996,1997,1998,1999 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 ;; for historical reason, we do (require 'emu) in this file.
29 ;; but you should do (require 'emu) explicitly if you use functions and/or
30 ;; variables defined in emu module.
32 (require 'path-util) ; default-load-path
34 (defvar emacs-major-version (string-to-int emacs-version)
35 "Major version number of this version of Emacs.
36 This variable first existed in version 19.23.")
38 (defvar emacs-minor-version
40 (substring emacs-version
41 (string-match (format "%d\\." emacs-major-version)
43 "Minor version number of this version of Emacs.
44 This variable first existed in version 19.23.")
46 ;; verbatim copy of `defun-maybe' from poe.el, and
47 ;; `make-directory-internal' and `make-directory' from poe-18.el
48 (defmacro defun-maybe (name &rest everything-else)
49 "Define NAME as a function if NAME is not defined.
50 See also the function `defun'."
51 (or (and (fboundp name)
52 (not (get name 'defun-maybe)))
53 (` (or (fboundp (quote (, name)))
55 (defun (, name) (,@ everything-else))
56 (put (quote (, name)) 'defun-maybe t))))))
58 (defun-maybe make-directory-internal (dirname)
59 "Create a directory. One argument, a file name string."
60 (let ((dir (expand-file-name dirname)))
61 (if (file-exists-p dir)
62 (error "Creating directory: %s is already exist" dir)
63 (call-process "mkdir" nil nil nil dir))))
65 (defun-maybe make-directory (dir &optional parents)
66 "Create the directory DIR and any nonexistent parent dirs.
67 The second (optional) argument PARENTS says whether
68 to create parent directories if they don't exist."
69 (let ((len (length dir))
72 (while (and (< p len) (string-match "[^/]*/?" dir p))
73 (setq p1 (match-end 0))
76 (setq path (substring dir 0 p1))
77 (if (not (file-directory-p path))
78 (cond ((file-exists-p path)
79 (error "Creating directory: %s is not directory" path))
81 (error "Creating directory: %s is not exist" path))
83 (make-directory-internal path))))
85 (make-directory-internal dir)))
88 ;;; @ compile Emacs Lisp files
91 (defun compile-elisp-module (module &optional path every-time)
92 (setq module (expand-file-name (symbol-name module) path))
93 (let ((el-file (concat module ".el"))
94 (elc-file (concat module ".elc")))
96 (file-newer-than-file-p el-file elc-file))
97 (byte-compile-file el-file))))
99 (defun compile-elisp-modules (modules &optional path every-time)
102 (compile-elisp-module module path every-time)))
109 (defvar install-overwritten-file-modes (+ (* 64 6)(* 8 4) 4))
111 (defun install-file (file src dest &optional move overwrite just-print)
113 (princ (format "%s -> %s\n" file dest))
114 (let ((src-file (expand-file-name file src)))
115 (if (file-exists-p src-file)
116 (let ((full-path (expand-file-name file dest)))
117 (if (and (file-exists-p full-path) overwrite)
118 (delete-file full-path))
119 (copy-file src-file full-path t t)
122 (while (and (file-exists-p src-file)
123 (file-writable-p src-file))
126 (delete-file src-file)
128 (error (princ (format "%s\n" (nth 1 err))))))))
129 (princ (format "%s -> %s\n" file dest)))))))
131 (defun install-files (files src dest &optional move overwrite just-print)
132 (or (file-exists-p dest)
133 (make-directory dest t))
136 (install-file file src dest move overwrite just-print)))
140 ;;; @@ install Emacs Lisp files
143 (defun install-elisp-module (module src dest &optional just-print)
144 (let (el-file elc-file)
145 (let ((name (symbol-name module)))
146 (setq el-file (concat name ".el"))
147 (setq elc-file (concat name ".elc")))
148 (let ((src-file (expand-file-name el-file src)))
149 (if (not (file-exists-p src-file))
152 (princ (format "%s -> %s\n" el-file dest))
153 (let ((full-path (expand-file-name el-file dest)))
154 (if (file-exists-p full-path)
155 (delete-file full-path))
156 (copy-file src-file full-path t t)
157 (princ (format "%s -> %s\n" el-file dest)))))
158 (setq src-file (expand-file-name elc-file src))
159 (if (not (file-exists-p src-file))
162 (princ (format "%s -> %s\n" elc-file dest))
163 (let ((full-path (expand-file-name elc-file dest)))
164 (if (file-exists-p full-path)
165 (delete-file full-path))
166 (copy-file src-file full-path t t)
168 (while (file-exists-p src-file)
171 (delete-file src-file)
173 (error (princ (format "%s\n" (nth 1 err)))))))
174 (princ (format "%s -> %s\n" elc-file dest))))))))
176 (defun install-elisp-modules (modules src dest &optional just-print)
177 (or (file-exists-p dest)
178 (make-directory dest t))
181 (install-elisp-module module src dest just-print)))
185 ;;; @ detect install path
188 ;; install to shared directory (maybe "/usr/local")
189 (defvar install-prefix
190 (if (or (<= emacs-major-version 18) ; running-emacs-18
191 (featurep 'xemacs) ; running-xemacs
192 (and (boundp 'system-configuration-options) ; 19.29 or later
193 (string= system-configuration-options "NT"))) ; for Meadow
194 (expand-file-name "../../.." exec-directory)
195 (expand-file-name "../../../.." data-directory)))
197 (defvar install-elisp-prefix
198 (if (>= emacs-major-version 19)
202 (defun install-detect-elisp-directory (&optional prefix elisp-prefix
203 allow-version-specific)
205 (setq prefix install-prefix))
207 (setq elisp-prefix install-elisp-prefix))
210 (let ((rest default-load-path)
212 (expand-file-name (concat ".*/" elisp-prefix) prefix)
215 (if (string-match pat (car rest))
216 (if (or allow-version-specific
217 (not (string-match (format "/%d\\.%d"
221 (throw 'tag (car rest))))
222 (setq rest (cdr rest)))))
223 (expand-file-name (concat
224 (if (and ; running-emacs-19_29-or-later
225 (not (featurep 'xemacs))
226 (or (>= emacs-major-version 20)
227 (and (= emacs-major-version 19)
228 (>= emacs-minor-version 29))))
231 (cond ((boundp 'NEMACS) "nemacs/")
232 ((boundp 'MULE) "mule/")
233 ((featurep 'xemacs) ; running-xemacs
241 (defvar install-default-elisp-directory
242 (install-detect-elisp-directory))
250 ;;; install.el ends here