tm 7.79.
[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 1.5 1996/08/21 12:08:41 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 (defun compile-elisp-module (module &optional path every-time)
30   (setq module (expand-file-name (symbol-name module) path))
31   (let ((el-file (concat module ".el"))
32         (elc-file (concat module ".elc"))
33         )
34     (if (or every-time
35             (file-newer-than-file-p el-file elc-file))
36         (byte-compile-file el-file)
37       )
38     ))
39
40 (defun compile-elisp-modules (modules &optional path every-time)
41   (mapcar (function
42            (lambda (module)
43              (compile-elisp-module module path every-time)
44              ))
45           modules))
46
47
48 (defvar install-overwritten-file-modes (+ (* 64 6)(* 8 4) 4))
49
50 (defun install-file (file src dest &optional move overwrite)
51   (let ((src-file (expand-file-name file src)))
52     (if (file-exists-p src-file)
53         (let ((full-path (expand-file-name file dest)))
54           (if (and (file-exists-p full-path) overwrite)
55               (set-file-modes full-path install-overwritten-file-modes)
56             )
57           (copy-file src-file full-path t t)
58           (if move
59               (catch 'tag
60                 (while (file-exists-p src-file)
61                   (condition-case err
62                       (progn
63                         (delete-file src-file)
64                         (throw 'tag nil)
65                         )
66                     (error (princ (format "%s\n" (nth 1 err))))
67                     ))))
68           (princ (format "%s -> %s\n" file dest))
69           ))
70     ))
71
72 (defun install-files (files src dest &optional move overwrite)
73   (or (file-exists-p dest)
74       (make-directory dest t)
75       )
76   (mapcar (function (lambda (file)
77                       (install-file file src dest move overwrite)
78                       ))
79           files))
80
81 (defun install-elisp-module (module src dest)
82   (let (el-file elc-file)
83     (let ((name (symbol-name module)))
84       (setq el-file (concat name ".el"))
85       (setq elc-file (concat name ".elc"))
86       )
87     (let ((src-file (expand-file-name el-file src)))
88       (if (file-exists-p src-file)
89           (let ((full-path (expand-file-name el-file dest)))
90             (if (file-exists-p full-path)
91                 (set-file-modes full-path install-overwritten-file-modes)
92               )
93             (copy-file src-file full-path t t)
94             (princ (format "%s -> %s\n" el-file dest))
95             ))
96       (setq src-file (expand-file-name elc-file src))
97       (if (file-exists-p src-file)
98           (let ((full-path (expand-file-name elc-file dest)))
99             (copy-file src-file full-path t t)
100             (catch 'tag
101               (while (file-exists-p src-file)
102                 (condition-case err
103                     (progn
104                       (delete-file src-file)
105                       (throw 'tag nil)
106                       )
107                   (error (princ (format "%s\n" (nth 1 err))))
108                   )))
109             (princ (format "%s -> %s\n" elc-file dest))
110             ))
111       )))
112
113 (defun install-elisp-modules (modules src dest)
114   (or (file-exists-p dest)
115       (make-directory dest t)
116       )
117   (mapcar (function (lambda (module)
118                       (install-elisp-module module src dest)
119                       ))
120           modules))
121
122
123 ;;; @ end
124 ;;;
125
126 (provide 'install)
127
128 ;;; install.el ends here