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
|
|
42 (defun paths-find-recursive-path (directories &optional exclude)
|
|
43 "Return a list of the directory hierarchy underneath DIRECTORIES.
|
|
44 The returned list is sorted by pre-order and lexicographically."
|
|
45 (let ((path '()))
|
|
46 (while directories
|
|
47 (let ((directory (file-name-as-directory
|
|
48 (expand-file-name
|
|
49 (car directories)))))
|
|
50 (if (file-directory-p directory)
|
|
51 (let ((raw-dirs (directory-files directory nil "^[^-.]" nil 'dirs-only))
|
|
52 (reverse-dirs '()))
|
|
53
|
|
54 (while raw-dirs
|
|
55 (if (null (member (car raw-dirs) exclude))
|
|
56 (setq reverse-dirs
|
|
57 (cons (expand-file-name (car raw-dirs) directory)
|
|
58 reverse-dirs)))
|
|
59 (setq raw-dirs (cdr raw-dirs)))
|
|
60
|
|
61 (let ((sub-path
|
|
62 (paths-find-recursive-path (reverse reverse-dirs) exclude)))
|
|
63 (setq path (nconc path
|
|
64 (list directory)
|
|
65 sub-path))))))
|
|
66 (setq directories (cdr directories)))
|
|
67 path))
|
|
68
|
|
69 (defun paths-find-recursive-load-path (directories)
|
|
70 "Construct a recursive load path underneath DIRECTORIES."
|
|
71 (paths-find-recursive-path directories paths-version-control-bases))
|
|
72
|
|
73 (defun paths-emacs-root-p (directory)
|
|
74 "Check if DIRECTORY is a plausible installation root for XEmacs."
|
|
75 (or
|
|
76 ;; installed
|
272
|
77 (file-directory-p (concat directory "lib/xemacs"))
|
267
|
78 ;; in-place
|
|
79 (and
|
|
80 (file-directory-p (concat directory "lib-src"))
|
|
81 (file-directory-p (concat directory "lisp"))
|
|
82 (file-directory-p (concat directory "src")))))
|
|
83
|
274
|
84 (defun paths-chase-symlink (file-name)
|
|
85 "Chase a symlink until the bitter end."
|
|
86 (let ((maybe-symlink (file-symlink-p file-name)))
|
|
87 (if maybe-symlink
|
|
88 (let* ((directory (file-name-directory file-name))
|
|
89 (destination (expand-file-name maybe-symlink directory)))
|
|
90 (paths-chase-symlink destination))
|
|
91 file-name)))
|
|
92
|
267
|
93 (defun paths-find-emacs-root
|
|
94 (invocation-directory invocation-name)
|
|
95 "Find the run-time root of XEmacs."
|
274
|
96 (let* ((executable-file-name (paths-chase-symlink
|
|
97 (concat invocation-directory
|
|
98 invocation-name)))
|
|
99 (executable-directory (file-name-directory executable-file-name))
|
|
100 (maybe-root-1 (file-name-as-directory
|
|
101 (expand-file-name ".." executable-directory)))
|
|
102 (maybe-root-2 (file-name-as-directory
|
|
103 (expand-file-name "../.." executable-directory))))
|
|
104 (or (and (paths-emacs-root-p maybe-root-1)
|
|
105 maybe-root-1)
|
|
106 (and (paths-emacs-root-p maybe-root-2)
|
|
107 maybe-root-2))))
|
267
|
108
|
|
109 (defun paths-construct-emacs-directory (root suffix base)
|
|
110 "Construct a directory name within the XEmacs hierarchy."
|
|
111 (file-name-as-directory
|
|
112 (expand-file-name
|
|
113 (concat
|
|
114 (file-name-as-directory root)
|
|
115 suffix
|
|
116 base))))
|
|
117
|
|
118 (defun paths-find-emacs-directory (roots suffix base &optional envvar default)
|
|
119 "Find a directory in the XEmacs hierarchy.
|
|
120 ROOTS must be a list of installation roots.
|
|
121 SUFFIX is the subdirectory from there.
|
|
122 BASE is the base to look for.
|
|
123 ENVVAR is the name of the environment variable that might also
|
|
124 specify the directory.
|
|
125 DEFAULT is a fall-back value."
|
|
126 (let ((envvar-value (and envvar (getenv envvar))))
|
|
127 (if (and envvar-value
|
|
128 (file-directory-p envvar-value))
|
|
129 (file-name-as-directory envvar-value)
|
|
130 (catch 'gotcha
|
|
131 (while roots
|
|
132 (let* ((root (car roots))
|
|
133 (path (paths-construct-emacs-directory root suffix base)))
|
|
134 ;; installed
|
|
135 (if (file-directory-p path)
|
|
136 (throw 'gotcha path)
|
|
137 (let ((path (paths-construct-emacs-directory root "" base)))
|
|
138 ;; in-place
|
|
139 (if (file-directory-p path)
|
|
140 (throw 'gotcha path)))))
|
|
141 (setq roots (cdr roots)))
|
|
142 (if (and default
|
|
143 (file-directory-p default))
|
|
144 (file-name-as-directory default)
|
|
145 nil)))))
|
|
146
|
|
147 (defun paths-find-site-directory (roots base &optional envvar default)
|
|
148 "Find a site-specific directory in the XEmacs hierarchy."
|
|
149 (paths-find-emacs-directory roots "lib/xemacs/" base envvar default))
|
|
150
|
|
151 (defun paths-find-version-directory (roots base &optional envvar default)
|
|
152 "Find a version-specific directory in the XEmacs hierarchy."
|
|
153 (paths-find-emacs-directory roots
|
|
154 (concat "lib/xemacs-" (construct-emacs-version) "/")
|
|
155 base
|
|
156 envvar default))
|
|
157
|
|
158 (defun paths-find-architecture-directory (roots base &optional envvar default)
|
|
159 "Find an architecture-specific directory in the XEmacs hierarchy."
|
|
160 (or
|
|
161 ;; from more to less specific
|
|
162 (paths-find-version-directory roots
|
|
163 (concat base system-configuration)
|
269
|
164 envvar)
|
|
165 (paths-find-version-directory roots
|
|
166 base
|
|
167 envvar)
|
267
|
168 (paths-find-version-directory roots
|
|
169 system-configuration
|
|
170 envvar default)))
|
|
171
|
|
172 (defvar paths-path-emacs-version nil
|
|
173 "Emacs version as it appears in paths.")
|
|
174
|
|
175 (defun construct-emacs-version ()
|
|
176 "Construct the raw version number of XEmacs in the form XX.XX."
|
|
177 ;; emacs-version isn't available early, but we really don't care then
|
|
178 (if (null (boundp 'emacs-version))
|
|
179 "XX.XX"
|
|
180 (or paths-path-emacs-version ; cache
|
|
181 (progn
|
|
182 (string-match "\\`[^0-9]*\\([0-9]+\\.[0-9]+\\)" emacs-version)
|
|
183 (let ((version (substring emacs-version
|
|
184 (match-beginning 1) (match-end 1))))
|
|
185 (if (string-match "(beta *\\([0-9]+\\))" emacs-version)
|
|
186 (setq version (concat version
|
|
187 "-b"
|
|
188 (substring emacs-version
|
|
189 (match-beginning 1) (match-end 1)))))
|
|
190 (setq paths-path-emacs-version version)
|
|
191 version)))))
|
|
192
|
|
193 (defun paths-find-emacs-path (roots suffix base &optional envvar default)
|
|
194 "Find a path in the XEmacs hierarchy.
|
|
195 ROOTS must be a list of installation roots.
|
|
196 SUFFIX is the subdirectory from there.
|
|
197 BASE is the base to look for.
|
|
198 ENVVAR is the name of the environment variable that might also
|
|
199 specify the path.
|
|
200 DEFAULT is a fall-back value."
|
|
201 (let ((envvar-value (and envvar (getenv envvar))))
|
|
202 (if envvar-value
|
|
203 (decode-path-internal envvar-value)
|
|
204 (let ((directory (paths-find-emacs-directory roots base suffix)))
|
|
205 (if (and directory (file-directory-p directory))
|
|
206 (list directory)
|
|
207 (paths-directories-which-exist default))))))
|
|
208
|
|
209 (defun paths-directories-which-exist (directories)
|
|
210 "Return the directories among DIRECTORIES."
|
|
211 (let ((reverse-directories '()))
|
|
212 (while directories
|
|
213 (if (file-directory-p (car directories))
|
|
214 (setq reverse-directories
|
|
215 (cons (car directories)
|
|
216 reverse-directories)))
|
|
217 (setq directories (cdr directories)))
|
|
218 (reverse reverse-directories)))
|
|
219
|
274
|
220 (defun paths-uniq-append (list-1 list-2)
|
|
221 "Append LIST-1 and LIST-2, omitting duplicates."
|
|
222 (let ((reverse-survivors '()))
|
|
223 (while list-2
|
|
224 (if (null (member (car list-2) list-1))
|
|
225 (setq reverse-survivors (cons (car list-2) reverse-survivors)))
|
|
226 (setq list-2 (cdr list-2)))
|
|
227 (append list-1
|
|
228 (reverse reverse-survivors))))
|
|
229
|
267
|
230 (defun paths-find-site-path (roots base &optional envvar default)
|
|
231 "Find a path underneath the site hierarchy."
|
|
232 (paths-find-emacs-path roots "lib/xemacs/" base envvar default))
|
|
233
|
|
234 (defun paths-find-version-path (roots base &optional envvar default)
|
|
235 "Find a path underneath the site hierarchy."
|
|
236 (paths-find-emacs-path roots
|
|
237 (concat "lib/xemacs-" (construct-emacs-version) "/")
|
|
238 base
|
|
239 envvar default))
|
|
240
|
|
241 (defun paths-find-emacs-roots (invocation-directory
|
|
242 invocation-name)
|
|
243 "Find all plausible installation roots for XEmacs."
|
|
244 (let ((invocation-root
|
|
245 (paths-find-emacs-root invocation-directory invocation-name))
|
|
246 (installation-root
|
272
|
247 (and configure-prefix-directory
|
|
248 (file-directory-p configure-prefix-directory)
|
|
249 (file-name-as-directory configure-prefix-directory))))
|
267
|
250 (append (and invocation-root
|
|
251 (list invocation-root))
|
|
252 (and installation-root
|
272
|
253 (paths-emacs-root-p installation-root)
|
267
|
254 (list installation-root)))))
|
|
255
|
|
256 ;;; find-paths.el ends here
|