1 | ;;; install.el --- Emacs Lisp package install utility |
---|
2 | |
---|
3 | ;; Copyright (C) 1996,1997,1998,1999 Free Software Foundation, Inc. |
---|
4 | |
---|
5 | ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp> |
---|
6 | ;; Created: 1996/08/18 |
---|
7 | ;; Keywords: install, byte-compile, directory detection |
---|
8 | |
---|
9 | ;; This file is part of APEL (A Portable Emacs Library). |
---|
10 | |
---|
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. |
---|
15 | |
---|
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. |
---|
20 | |
---|
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. |
---|
25 | |
---|
26 | ;;; Code: |
---|
27 | |
---|
28 | (require 'poe) ; make-directory for v18 |
---|
29 | (require 'path-util) ; default-load-path |
---|
30 | |
---|
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 | (if (or every-time |
---|
40 | (file-newer-than-file-p el-file elc-file)) |
---|
41 | (byte-compile-file el-file)))) |
---|
42 | |
---|
43 | (defun compile-elisp-modules (modules &optional path every-time) |
---|
44 | (mapcar |
---|
45 | (function |
---|
46 | (lambda (module) |
---|
47 | (compile-elisp-module module path every-time))) |
---|
48 | modules)) |
---|
49 | |
---|
50 | |
---|
51 | ;;; @ install files |
---|
52 | ;;; |
---|
53 | |
---|
54 | (defvar install-overwritten-file-modes (+ (* 64 6)(* 8 4) 4)) ; 0644 |
---|
55 | |
---|
56 | (defun install-file (file src dest &optional move overwrite just-print) |
---|
57 | (if 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 | (if move |
---|
66 | (catch 'tag |
---|
67 | (while (and (file-exists-p src-file) |
---|
68 | (file-writable-p src-file)) |
---|
69 | (condition-case err |
---|
70 | (progn |
---|
71 | (delete-file src-file) |
---|
72 | (throw 'tag nil)) |
---|
73 | (error (princ (format "%s\n" (nth 1 err)))))))) |
---|
74 | (princ (format "%s -> %s\n" file dest))))))) |
---|
75 | |
---|
76 | (defun install-files (files src dest &optional move overwrite just-print) |
---|
77 | (or (file-exists-p dest) |
---|
78 | (make-directory dest t)) |
---|
79 | (mapcar |
---|
80 | (function |
---|
81 | (lambda (file) |
---|
82 | (install-file file src dest move overwrite just-print))) |
---|
83 | files)) |
---|
84 | |
---|
85 | |
---|
86 | ;;; @@ install Emacs Lisp files |
---|
87 | ;;; |
---|
88 | |
---|
89 | (defun install-elisp-module (module src dest &optional just-print) |
---|
90 | (let (el-file elc-file) |
---|
91 | (let ((name (symbol-name module))) |
---|
92 | (setq el-file (concat name ".el")) |
---|
93 | (setq elc-file (concat name ".elc"))) |
---|
94 | (let ((src-file (expand-file-name el-file src))) |
---|
95 | (if (not (file-exists-p src-file)) |
---|
96 | nil |
---|
97 | (if just-print |
---|
98 | (princ (format "%s -> %s\n" el-file dest)) |
---|
99 | (let ((full-path (expand-file-name el-file dest))) |
---|
100 | (if (file-exists-p full-path) |
---|
101 | (delete-file full-path)) |
---|
102 | (copy-file src-file full-path t t) |
---|
103 | (princ (format "%s -> %s\n" el-file dest))))) |
---|
104 | (setq src-file (expand-file-name elc-file src)) |
---|
105 | (if (not (file-exists-p src-file)) |
---|
106 | nil |
---|
107 | (if just-print |
---|
108 | (princ (format "%s -> %s\n" elc-file dest)) |
---|
109 | (let ((full-path (expand-file-name elc-file dest))) |
---|
110 | (if (file-exists-p full-path) |
---|
111 | (delete-file full-path)) |
---|
112 | (copy-file src-file full-path t t) |
---|
113 | (catch 'tag |
---|
114 | (while (file-exists-p src-file) |
---|
115 | (condition-case err |
---|
116 | (progn |
---|
117 | (delete-file src-file) |
---|
118 | (throw 'tag nil)) |
---|
119 | (error (princ (format "%s\n" (nth 1 err))))))) |
---|
120 | (princ (format "%s -> %s\n" elc-file dest)))))))) |
---|
121 | |
---|
122 | (defun install-elisp-modules (modules src dest &optional just-print) |
---|
123 | (or (file-exists-p dest) |
---|
124 | (make-directory dest t)) |
---|
125 | (mapcar |
---|
126 | (function |
---|
127 | (lambda (module) |
---|
128 | (install-elisp-module module src dest just-print))) |
---|
129 | modules)) |
---|
130 | |
---|
131 | |
---|
132 | ;;; @ detect install path |
---|
133 | ;;; |
---|
134 | |
---|
135 | ;; install to shared directory (maybe "/usr/local") |
---|
136 | (defvar install-prefix |
---|
137 | (if (or (<= emacs-major-version 18) |
---|
138 | (featurep 'xemacs) |
---|
139 | (and (boundp 'system-configuration-options) ; 19.29 or later |
---|
140 | (string= system-configuration-options "NT"))) ; for Meadow |
---|
141 | (expand-file-name "../../.." exec-directory) |
---|
142 | (expand-file-name "../../../.." data-directory))) |
---|
143 | |
---|
144 | (defvar install-elisp-prefix |
---|
145 | (if (>= emacs-major-version 19) |
---|
146 | "site-lisp" |
---|
147 | ;; v18 does not have standard site directory. |
---|
148 | "local.lisp")) |
---|
149 | |
---|
150 | (defun install-detect-elisp-directory (&optional prefix elisp-prefix |
---|
151 | allow-version-specific) |
---|
152 | (or prefix |
---|
153 | (setq prefix install-prefix)) |
---|
154 | (or elisp-prefix |
---|
155 | (setq elisp-prefix install-elisp-prefix)) |
---|
156 | (or (catch 'tag |
---|
157 | (let ((rest default-load-path) |
---|
158 | (regexp (concat "^" |
---|
159 | (expand-file-name (concat ".*/" elisp-prefix) |
---|
160 | prefix) |
---|
161 | "/?$"))) |
---|
162 | (while rest |
---|
163 | (if (string-match regexp (car rest)) |
---|
164 | (if (or allow-version-specific |
---|
165 | (not (string-match (format "/%d\\.%d" |
---|
166 | emacs-major-version |
---|
167 | emacs-minor-version) |
---|
168 | (car rest)))) |
---|
169 | (throw 'tag (car rest)))) |
---|
170 | (setq rest (cdr rest))))) |
---|
171 | (expand-file-name (concat (if (and (not (featurep 'xemacs)) |
---|
172 | (or (>= emacs-major-version 20) |
---|
173 | (and (= emacs-major-version 19) |
---|
174 | (> emacs-minor-version 28)))) |
---|
175 | "share/" |
---|
176 | "lib/") |
---|
177 | (cond |
---|
178 | ((featurep 'xemacs) |
---|
179 | (if (featurep 'mule) |
---|
180 | "xmule/" |
---|
181 | "xemacs/")) |
---|
182 | ;; unfortunately, unofficial mule based on |
---|
183 | ;; 19.29 and later use "emacs/" by default. |
---|
184 | ((boundp 'MULE) "mule/") |
---|
185 | ((boundp 'NEMACS) "nemacs/") |
---|
186 | (t "emacs/")) |
---|
187 | elisp-prefix) |
---|
188 | prefix))) |
---|
189 | |
---|
190 | (defvar install-default-elisp-directory |
---|
191 | (install-detect-elisp-directory)) |
---|
192 | |
---|
193 | |
---|
194 | ;;; @ for XEmacs package system |
---|
195 | ;;; |
---|
196 | |
---|
197 | (defun install-update-package-files (package dir &optional just-print) |
---|
198 | (cond |
---|
199 | (just-print |
---|
200 | (princ (format "Updating autoloads in directory %s..\n\n" dir)) |
---|
201 | |
---|
202 | (princ (format "Processing %s\n" dir)) |
---|
203 | (princ "Generating custom-load.el...\n\n") |
---|
204 | |
---|
205 | (princ (format "Compiling %s...\n" |
---|
206 | (expand-file-name "auto-autoloads.el" dir))) |
---|
207 | (princ (format "Wrote %s\n" |
---|
208 | (expand-file-name "auto-autoloads.elc" dir))) |
---|
209 | |
---|
210 | (princ (format "Compiling %s...\n" |
---|
211 | (expand-file-name "custom-load.el" dir))) |
---|
212 | (princ (format "Wrote %s\n" |
---|
213 | (expand-file-name "custom-load.elc" dir)))) |
---|
214 | (t |
---|
215 | (setq autoload-package-name package) |
---|
216 | |
---|
217 | (let ((command-line-args-left (list dir))) |
---|
218 | (batch-update-directory)) |
---|
219 | |
---|
220 | (let ((command-line-args-left (list dir))) |
---|
221 | (Custom-make-dependencies)) |
---|
222 | |
---|
223 | (byte-compile-file (expand-file-name "auto-autoloads.el" dir)) |
---|
224 | (byte-compile-file (expand-file-name "custom-load.el" dir))))) |
---|
225 | |
---|
226 | |
---|
227 | ;;; @ Other Utilities |
---|
228 | ;;; |
---|
229 | |
---|
230 | (defun install-just-print-p () |
---|
231 | (let ((flag (getenv "MAKEFLAGS")) |
---|
232 | (case-fold-search nil)) |
---|
233 | (princ (format "%s\n" flag)) |
---|
234 | (if flag |
---|
235 | (string-match "^\\(\\(--[^ ]+ \\)+-\\|[^ =-]\\)*n" flag)))) |
---|
236 | |
---|
237 | |
---|
238 | ;;; @ end |
---|
239 | ;;; |
---|
240 | |
---|
241 | (require 'product) |
---|
242 | (product-provide (provide 'install) (require 'apel-ver)) |
---|
243 | |
---|
244 | ;;; install.el ends here |
---|