tm 7.82.
[elisp/apel.git] / install.el
1 ;;; install.el --- Emacs Lisp package install utility
2
3 ;; Copyright (C) 1996 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Created: 1996/8/18
7 ;; Version: $Id: install.el,v 2.1 1996/09/04 13:57:50 morioka Exp $
8 ;; Keywords: install
9
10 ;; This file is part of tl (Tiny Library).
11
12 ;; This program is free software; you can redistribute it and/or
13 ;; modify it under the terms of the GNU General Public License as
14 ;; published by the Free Software Foundation; either version 2, or (at
15 ;; your option) any later version.
16
17 ;; This program is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 ;; General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with this program; see the file COPYING.  If not, write to
24 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Code:
28
29 (require 'emu)
30 (require 'file-detect)
31
32 ;;; @ compile Emacs Lisp files
33 ;;;
34
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"))
39         )
40     (if (or every-time
41             (file-newer-than-file-p el-file elc-file))
42         (byte-compile-file el-file)
43       )
44     ))
45
46 (defun compile-elisp-modules (modules &optional path every-time)
47   (mapcar (function
48            (lambda (module)
49              (compile-elisp-module module path every-time)
50              ))
51           modules))
52
53
54 ;;; @ install files
55 ;;;
56
57 (defvar install-overwritten-file-modes (+ (* 64 6)(* 8 4) 4))
58
59 (defun install-file (file src dest &optional move overwrite)
60   (let ((src-file (expand-file-name file src)))
61     (if (file-exists-p src-file)
62         (let ((full-path (expand-file-name file dest)))
63           (if (and (file-exists-p full-path) overwrite)
64               (set-file-modes full-path install-overwritten-file-modes)
65             )
66           (copy-file src-file full-path t t)
67           (if move
68               (catch 'tag
69                 (while (and (file-exists-p src-file)
70                             (file-writable-p src-file))
71                   (condition-case err
72                       (progn
73                         (delete-file src-file)
74                         (throw 'tag nil)
75                         )
76                     (error (princ (format "%s\n" (nth 1 err))))
77                     ))))
78           (princ (format "%s -> %s\n" file dest))
79           ))
80     ))
81
82 (defun install-files (files src dest &optional move overwrite)
83   (or (file-exists-p dest)
84       (make-directory dest t)
85       )
86   (mapcar (function (lambda (file)
87                       (install-file file src dest move overwrite)
88                       ))
89           files))
90
91
92 ;;; @@ install Emacs Lisp files
93 ;;;
94
95 (defun install-elisp-module (module src dest)
96   (let (el-file elc-file)
97     (let ((name (symbol-name module)))
98       (setq el-file (concat name ".el"))
99       (setq elc-file (concat name ".elc"))
100       )
101     (let ((src-file (expand-file-name el-file src)))
102       (if (file-exists-p src-file)
103           (let ((full-path (expand-file-name el-file dest)))
104             (if (file-exists-p full-path)
105                 (set-file-modes full-path install-overwritten-file-modes)
106               )
107             (copy-file src-file full-path t t)
108             (princ (format "%s -> %s\n" el-file dest))
109             ))
110       (setq src-file (expand-file-name elc-file src))
111       (if (file-exists-p src-file)
112           (let ((full-path (expand-file-name elc-file dest)))
113             (copy-file src-file full-path t t)
114             (catch 'tag
115               (while (file-exists-p src-file)
116                 (condition-case err
117                     (progn
118                       (delete-file src-file)
119                       (throw 'tag nil)
120                       )
121                   (error (princ (format "%s\n" (nth 1 err))))
122                   )))
123             (princ (format "%s -> %s\n" elc-file dest))
124             ))
125       )))
126
127 (defun install-elisp-modules (modules src dest)
128   (or (file-exists-p dest)
129       (make-directory dest t)
130       )
131   (mapcar (function (lambda (module)
132                       (install-elisp-module module src dest)
133                       ))
134           modules))
135
136
137 ;;; @ detect install path
138 ;;;
139
140 (defvar install-prefix
141   (if (or running-emacs-18 running-xemacs)
142       (expand-file-name "../../.." exec-directory)
143     (expand-file-name "../../../.." data-directory)
144     )) ; install to shared directory (maybe "/usr/local")
145
146 (defvar install-elisp-prefix
147   (if (>= emacs-major-version 19)
148       "site-lisp"
149     "local.lisp"))
150
151 (defun install-detect-elisp-directory (&optional prefix elisp-prefix)
152   (or prefix
153       (setq prefix install-prefix)
154       )
155   (or elisp-prefix
156       (setq elisp-prefix install-elisp-prefix)
157       )
158   (or
159    (catch 'tag
160      (let ((rest default-load-path)
161            dir)
162        (while (setq dir (car rest))
163          (if (string-match
164               (concat "^"
165                       (expand-file-name (concat ".*/" elisp-prefix) prefix)
166                       "$")
167               dir)
168              (or (string-match (format "%d\\.%d"
169                                        emacs-major-version
170                                        emacs-minor-version) dir)
171                  (throw 'tag dir)
172                  ))
173          (setq rest (cdr rest))
174          )))
175    (expand-file-name (concat
176                       (if running-emacs-19_29-or-later
177                           "share/"
178                         "lib/")
179                       (cond ((boundp 'NEMACS) "nemacs/")
180                             ((boundp 'MULE)   "mule/")
181                             (running-xemacs
182                              (if (featurep 'mule)
183                                  "xmule/"
184                                "xemacs/"))
185                             (t "emacs/"))
186                       elisp-prefix) prefix)
187    ))
188
189 (defvar install-default-elisp-directory
190   (install-detect-elisp-directory))
191
192
193 ;;; @ end
194 ;;;
195
196 (provide 'install)
197
198 ;;; install.el ends here