267
|
1 ;;; find-paths.el --- setup various XEmacs paths
|
|
2
|
|
3 ;; Copyright (C) 1985-1986, 1990, 1992-1997 Free Software Foundation, Inc.
|
|
4 ;; Copyright (c) 1993, 1994 Sun Microsystems, Inc.
|
|
5 ;; Copyright (C) 1995 Board of Trustees, University of Illinois
|
|
6
|
|
7 ;; Author: Mike Sperber <sperber@informatik.uni-tuebingen.de>
|
|
8 ;; Maintainer: XEmacs Development Team
|
|
9 ;; Keywords: internal, dumped
|
|
10
|
|
11 ;; This file is part of XEmacs.
|
|
12
|
|
13 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
14 ;; under the terms of the GNU General Public License as published by
|
|
15 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
16 ;; any later version.
|
|
17
|
|
18 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
21 ;; General Public License for more details.
|
|
22
|
|
23 ;; You should have received a copy of the GNU General Public License
|
|
24 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
25 ;; Free Software Foundation, 59 Temple Place - Suite 330,
|
|
26 ;; Boston, MA 02111-1307, USA.
|
|
27
|
|
28 ;;; Synched up with: Not in FSF.
|
|
29
|
|
30 ;;; Commentary:
|
|
31
|
|
32 ;; This file is dumped with XEmacs.
|
|
33
|
|
34 ;; This file contains the library functionality to find paths into the
|
|
35 ;; XEmacs hierarchy.
|
|
36
|
|
37 ;;; Code:
|
|
38
|
|
39 (defvar paths-version-control-bases '("RCS" "CVS" "SCCS")
|
|
40 "File bases associated with version control.")
|
|
41
|
276
|
42 (defun paths-find-recursive-path (directories &optional max-depth exclude)
|
267
|
43 "Return a list of the directory hierarchy underneath DIRECTORIES.
|
276
|
44 The returned list is sorted by pre-order and lexicographically.
|
|
45 MAX-DEPTH limits the depth of the search to MAX-DEPTH level,
|
|
46 if it is a number. If MAX-DEPTH is NIL, the search depth is unlimited.
|
|
47 EXCLUDE is a list of directory names to exclude from the search."
|
267
|
48 (let ((path '()))
|
|
49 (while directories
|
|
50 (let ((directory (file-name-as-directory
|
|
51 (expand-file-name
|
|
52 (car directories)))))
|
|
53 (if (file-directory-p directory)
|
276
|
54 (let ((raw-dirs
|
|
55 (if (equal 0 max-depth)
|
|
56 '()
|
|
57 (directory-files directory nil "^[^-.]" nil 'dirs-only)))
|
267
|
58 (reverse-dirs '()))
|
|
59
|
|
60 (while raw-dirs
|
|
61 (if (null (member (car raw-dirs) exclude))
|
|
62 (setq reverse-dirs
|
|
63 (cons (expand-file-name (car raw-dirs) directory)
|
|
64 reverse-dirs)))
|
|
65 (setq raw-dirs (cdr raw-dirs)))
|
|
66
|
|
67 (let ((sub-path
|
276
|
68 (paths-find-recursive-path (reverse reverse-dirs)
|
|
69 (if (numberp max-depth)
|
|
70 (- max-depth 1)
|
|
71 max-depth)
|
|
72 exclude)))
|
267
|
73 (setq path (nconc path
|
|
74 (list directory)
|
|
75 sub-path))))))
|
|
76 (setq directories (cdr directories)))
|
|
77 path))
|
|
78
|
276
|
79 (defun paths-find-recursive-load-path (directories &optional max-depth)
|
267
|
80 "Construct a recursive load path underneath DIRECTORIES."
|
276
|
81 (paths-find-recursive-path directories
|
|
82 max-depth paths-version-control-bases))
|
267
|
83
|
|
84 (defun paths-emacs-root-p (directory)
|
|
85 "Check if DIRECTORY is a plausible installation root for XEmacs."
|
|
86 (or
|
|
87 ;; installed
|
280
|
88 (file-directory-p (paths-construct-path (list directory
|
|
89 "lib"
|
|
90 emacs-program-name)))
|
267
|
91 ;; in-place
|
|
92 (and
|
276
|
93 (file-directory-p (paths-construct-path (list directory "lib-src")))
|
|
94 (file-directory-p (paths-construct-path (list directory "lisp")))
|
|
95 (file-directory-p (paths-construct-path (list directory "src"))))))
|
267
|
96
|
274
|
97 (defun paths-chase-symlink (file-name)
|
|
98 "Chase a symlink until the bitter end."
|
|
99 (let ((maybe-symlink (file-symlink-p file-name)))
|
|
100 (if maybe-symlink
|
|
101 (let* ((directory (file-name-directory file-name))
|
|
102 (destination (expand-file-name maybe-symlink directory)))
|
|
103 (paths-chase-symlink destination))
|
|
104 file-name)))
|
|
105
|
267
|
106 (defun paths-find-emacs-root
|
|
107 (invocation-directory invocation-name)
|
|
108 "Find the run-time root of XEmacs."
|
274
|
109 (let* ((executable-file-name (paths-chase-symlink
|
|
110 (concat invocation-directory
|
|
111 invocation-name)))
|
|
112 (executable-directory (file-name-directory executable-file-name))
|
|
113 (maybe-root-1 (file-name-as-directory
|
276
|
114 (paths-construct-path '("..") executable-directory)))
|
274
|
115 (maybe-root-2 (file-name-as-directory
|
276
|
116 (paths-construct-path '(".." "..") executable-directory))))
|
274
|
117 (or (and (paths-emacs-root-p maybe-root-1)
|
|
118 maybe-root-1)
|
|
119 (and (paths-emacs-root-p maybe-root-2)
|
|
120 maybe-root-2))))
|
267
|
121
|
276
|
122 (defun paths-construct-path (components &optional expand-directory)
|
|
123 "Convert list of path components COMPONENTS into a path.
|
|
124 If EXPAND-DIRECTORY is non-NIL, use it as a directory to feed
|
|
125 to EXPAND-FILE-NAME."
|
|
126 (let* ((reverse-components (reverse components))
|
|
127 (last-component (car reverse-components))
|
|
128 (first-components (reverse (cdr reverse-components)))
|
|
129 (path
|
|
130 (apply #'concat
|
|
131 (append (mapcar #'file-name-as-directory first-components)
|
|
132 (list last-component)))))
|
|
133 (if expand-directory
|
|
134 (expand-file-name path expand-directory)
|
|
135 path)))
|
|
136
|
267
|
137 (defun paths-construct-emacs-directory (root suffix base)
|
|
138 "Construct a directory name within the XEmacs hierarchy."
|
|
139 (file-name-as-directory
|
|
140 (expand-file-name
|
|
141 (concat
|
|
142 (file-name-as-directory root)
|
|
143 suffix
|
|
144 base))))
|
|
145
|
280
|
146 (defun paths-find-emacs-directory (roots suffix base
|
|
147 &optional envvar default keep-suffix)
|
267
|
148 "Find a directory in the XEmacs hierarchy.
|
|
149 ROOTS must be a list of installation roots.
|
|
150 SUFFIX is the subdirectory from there.
|
|
151 BASE is the base to look for.
|
|
152 ENVVAR is the name of the environment variable that might also
|
|
153 specify the directory.
|
280
|
154 DEFAULT is the preferred value.
|
|
155 If KEEP-SUFFIX is non-nil, the suffix must be respected in searching
|
|
156 the directory."
|
276
|
157 (let ((preferred-value (or (and envvar (getenv envvar))
|
|
158 default)))
|
|
159 (if (and preferred-value
|
|
160 (file-directory-p preferred-value))
|
|
161 (file-name-as-directory preferred-value)
|
267
|
162 (catch 'gotcha
|
|
163 (while roots
|
|
164 (let* ((root (car roots))
|
280
|
165 ;; installed
|
267
|
166 (path (paths-construct-emacs-directory root suffix base)))
|
|
167 (if (file-directory-p path)
|
|
168 (throw 'gotcha path)
|
280
|
169 ;; in-place
|
|
170 (if (null keep-suffix)
|
|
171 (let ((path (paths-construct-emacs-directory root "" base)))
|
|
172 (if (file-directory-p path)
|
|
173 (throw 'gotcha path))))))
|
267
|
174 (setq roots (cdr roots)))
|
276
|
175 nil))))
|
267
|
176
|
|
177 (defun paths-find-site-directory (roots base &optional envvar default)
|
|
178 "Find a site-specific directory in the XEmacs hierarchy."
|
276
|
179 (paths-find-emacs-directory roots
|
|
180 (file-name-as-directory
|
280
|
181 (paths-construct-path (list
|
|
182 "lib"
|
|
183 emacs-program-name)))
|
276
|
184 base
|
|
185 envvar default))
|
267
|
186
|
280
|
187 (defun paths-find-version-directory (roots base
|
|
188 &optional envvar default enforce-version)
|
|
189 "Find a version-specific directory in the XEmacs hierarchy.
|
|
190 If ENFORCE-VERSION is non-nil, the directory must contain the XEmacs version."
|
267
|
191 (paths-find-emacs-directory roots
|
276
|
192 (file-name-as-directory
|
|
193 (paths-construct-path
|
|
194 (list "lib"
|
280
|
195 (construct-emacs-version-name))))
|
267
|
196 base
|
280
|
197 envvar default
|
|
198 enforce-version))
|
267
|
199
|
|
200 (defun paths-find-architecture-directory (roots base &optional envvar default)
|
|
201 "Find an architecture-specific directory in the XEmacs hierarchy."
|
|
202 (or
|
|
203 ;; from more to less specific
|
|
204 (paths-find-version-directory roots
|
|
205 (concat base system-configuration)
|
269
|
206 envvar)
|
|
207 (paths-find-version-directory roots
|
|
208 base
|
|
209 envvar)
|
267
|
210 (paths-find-version-directory roots
|
|
211 system-configuration
|
|
212 envvar default)))
|
|
213
|
280
|
214 (defun construct-emacs-version-name ()
|
|
215 "Construct the raw XEmacs version number."
|
|
216 (concat emacs-program-name "-" emacs-program-version))
|
267
|
217
|
|
218 (defun paths-directories-which-exist (directories)
|
|
219 "Return the directories among DIRECTORIES."
|
|
220 (let ((reverse-directories '()))
|
|
221 (while directories
|
|
222 (if (file-directory-p (car directories))
|
|
223 (setq reverse-directories
|
|
224 (cons (car directories)
|
|
225 reverse-directories)))
|
|
226 (setq directories (cdr directories)))
|
|
227 (reverse reverse-directories)))
|
|
228
|
274
|
229 (defun paths-uniq-append (list-1 list-2)
|
|
230 "Append LIST-1 and LIST-2, omitting duplicates."
|
|
231 (let ((reverse-survivors '()))
|
|
232 (while list-2
|
|
233 (if (null (member (car list-2) list-1))
|
|
234 (setq reverse-survivors (cons (car list-2) reverse-survivors)))
|
|
235 (setq list-2 (cdr list-2)))
|
|
236 (append list-1
|
|
237 (reverse reverse-survivors))))
|
|
238
|
278
|
239 (defun paths-filter (predicate list)
|
276
|
240 "Delete all matches of PREDICATE from LIST."
|
|
241 (let ((reverse-result '()))
|
|
242 (while list
|
278
|
243 (if (funcall predicate (car list))
|
276
|
244 (setq reverse-result (cons (car list) reverse-result)))
|
|
245 (setq list (cdr list)))
|
|
246 (nreverse reverse-result)))
|
267
|
247
|
276
|
248 (defun paths-decode-directory-path (string &optional drop-empties)
|
|
249 "Split STRING at path separators into a directory list.
|
|
250 Non-\"\" comonents are converted into directory form.
|
|
251 If DROP-EMPTIES is non-NIL, \"\" components are dropped from the output.
|
|
252 Otherwise, they are left alone."
|
284
|
253 (let* ((components (split-path string))
|
276
|
254 (directories
|
|
255 (mapcar #'(lambda (component)
|
|
256 (if (string-equal "" component)
|
|
257 component
|
|
258 (file-name-as-directory component)))
|
|
259 components)))
|
|
260 (if drop-empties
|
278
|
261 (paths-filter #'(lambda (component)
|
|
262 (null (string-equal "" component)))
|
276
|
263 directories)
|
|
264 directories)))
|
|
265
|
267
|
266 (defun paths-find-emacs-roots (invocation-directory
|
|
267 invocation-name)
|
|
268 "Find all plausible installation roots for XEmacs."
|
278
|
269 (let* ((potential-invocation-root
|
|
270 (paths-find-emacs-root invocation-directory invocation-name))
|
|
271 (invocation-roots
|
|
272 (and potential-invocation-root
|
|
273 (list potential-invocation-root)))
|
|
274 (potential-installation-roots
|
|
275 (paths-uniq-append
|
|
276 (and configure-exec-prefix-directory
|
|
277 (list (file-name-as-directory
|
|
278 configure-exec-prefix-directory)))
|
|
279 (and configure-prefix-directory
|
|
280 (list (file-name-as-directory
|
|
281 configure-prefix-directory)))))
|
|
282 (installation-roots
|
|
283 (paths-filter #'paths-emacs-root-p potential-installation-roots)))
|
|
284 (paths-uniq-append invocation-roots
|
|
285 installation-roots)))
|
267
|
286
|
|
287 ;;; find-paths.el ends here
|