All of SXEmacs' http URLs are now https. WooHoo!
[sxemacs] / lisp / setup-paths.el
1 ;;; setup-paths.el --- setup various SXEmacs 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: SXEmacs Development Team
9 ;; Keywords: internal, dumped
10
11 ;; This file is part of SXEmacs.
12
13 ;; SXEmacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
17
18 ;; SXEmacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 ;; GNU General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
25
26 ;;; Synched up with: Not in FSF.
27
28 ;;; Commentary:
29
30 ;; This file is dumped with XEmacs.
31
32 ;; This file describes and constructs the various paths into the
33 ;; XEmacs hierarchy from a global viewpoint.
34
35 ;; It requires find-paths.el and packages.el.
36 \f
37 ;;; Code:
38
39 (defvar paths-core-load-path-depth 0
40   "Depth of load-path searches in core Lisp paths.")
41
42 (defvar paths-site-load-path-depth 1
43   "Depth of load-path searches in site Lisp paths.")
44
45 (defvar paths-mule-load-path-depth 0
46   "Depth of load-path searches in Mule Lisp paths.")
47
48 (defvar paths-ffi-load-path-depth 0
49   "Depth of load-path searches in FFI Lisp paths.")
50
51 (defvar paths-module-load-path-depth 1
52   "Depth of load-path searches in emodule paths.")
53
54 (defvar paths-default-info-directories
55   (mapcar (function
56            (lambda (dirlist)
57              (paths-construct-path
58               dirlist (char-to-string directory-sep-char))))
59           '(("usr" "local" "info")
60             ("usr" "info")
61             ("usr" "local" "share" "info")
62             ("usr" "share" "info")))
63   "Directories appended to the end of the info path by default.")
64
65 (defun paths-find-site-module-directory (roots)
66   "Find the site modules directory of the XEmacs hierarchy."
67   (paths-find-site-archdep-directory roots "site-modules"
68                                        nil
69                                        configure-site-module-directory))
70
71 (defun paths-find-lisp-directory (roots)
72   "Find the main Lisp directory of the XEmacs hierarchy."
73   (or (paths-find-version-archindep-directory
74        roots "lisp" nil configure-lisp-directory)
75       (paths-find-version-archdep-directory
76        roots "lisp" nil configure-lisp-directory)))
77
78 (defun paths-find-mule-lisp-directory (roots &optional lisp-directory)
79   "Find the Mule Lisp directory of the XEmacs hierarchy."
80   ;; #### kludge
81   (if lisp-directory
82       (let ((guess
83              (file-name-as-directory
84               (paths-construct-path (list lisp-directory "mule")))))
85         (if (paths-file-readable-directory-p guess)
86             guess
87           (paths-find-version-archindep-directory
88            roots "mule-lisp" nil configure-mule-lisp-directory)))))
89
90 (defun paths-find-ffi-lisp-directory (roots &optional lisp-directory)
91   "Find the FFI Lisp directory of the SXEmacs hierarchy."
92   ;; #### kludge
93   (if lisp-directory
94       (let ((guess
95              (file-name-as-directory
96               (paths-construct-path (list lisp-directory "ffi")))))
97         (if (paths-file-readable-directory-p guess)
98             guess
99           (or (paths-find-version-archdep-directory
100                roots "ffi-lisp" nil)
101               (paths-find-version-archindep-directory
102                roots "ffi-lisp" nil))))))
103
104 (defun paths-find-module-directory (roots)
105   "Find the main modules directory of the SXEmacs hierarchy."
106   (or
107    ;; for inplace stuff
108    (paths-find-emacs-directory roots "" "modules"
109                                nil configure-module-directory)
110    (paths-find-architecture-directory roots "modules"
111                                       nil configure-module-directory)))
112
113 (defun paths-construct-module-load-path
114   (root module-directory &optional site-module-directory)
115   "Construct the modules load path.
116
117 If the environment variable \"EMACSMODULEPATH\" is set then it is used
118 for `module-load-path' and this function does squat.  EMACSMODULEPATH
119 should be a colon delimited list of directory paths.
120
121 ROOT is `emacs-roots'.  If that's nil, this will blow up.  But if
122 `emacs-roots' is nil, your SXEmacs will blow up before you get here
123 anyway.
124
125 MODULE-DIRECTORY is the directory containing the emodules distributed
126 with the core SXEmacs.  If for some reason it is nil, it'll be skipped
127 here.
128
129 If SITE-MODULE-DIRECTORY doesn't exist as a directory on disc, it is
130 skipped.  If it does exist but the argument here is nil, it is hunted
131 down."
132   (if (getenv "EMACSMODULEPATH")
133       (setq module-load-path (paths-decode-directory-path
134                               (getenv "EMACSMODULEPATH") 'drop-empties))
135     (let* ((user-path
136             (and system-configuration
137                  user-init-directory
138                  (paths-find-recursive-load-path
139                   (list (paths-construct-path
140                          (list system-configuration "modules") user-init-directory))
141                   paths-module-load-path-depth)))
142            (site-dir (paths-find-site-module-directory root))
143            (site-path
144             (or (and site-module-directory
145                      (paths-find-recursive-load-path (list site-module-directory)
146                                                      paths-module-load-path-depth))
147                 (and site-dir
148                      (paths-find-recursive-load-path
149                       (list site-dir) paths-module-load-path-depth))))
150            (module-path
151             (and module-directory
152                  (paths-find-recursive-load-path (list module-directory)
153                                                  paths-module-load-path-depth))))
154       (setq module-load-path (append (when user-path user-path)
155                                      (when site-path site-path)
156                                      (when module-path module-path))))))
157
158 (defun paths-construct-load-path
159   (roots early-package-load-path late-package-load-path last-package-load-path
160          lisp-directory
161          &optional unused mule-lisp-directory ffi-lisp-directory)
162   "Construct the load path."
163   (let* ((envvar-value (getenv "EMACSLOADPATH"))
164          (env-load-path
165           (and envvar-value
166                (paths-decode-directory-path envvar-value 'drop-empties)))
167          (mule-lisp-load-path
168           (and mule-lisp-directory
169                (paths-find-recursive-load-path (list mule-lisp-directory)
170                                                paths-mule-load-path-depth)))
171          (ffi-lisp-load-path
172           (and ffi-lisp-directory
173                (paths-find-recursive-load-path (list ffi-lisp-directory)
174                                                paths-ffi-load-path-depth)))
175          (lisp-load-path
176           (and lisp-directory
177                (paths-find-recursive-load-path (list lisp-directory)
178                                                paths-core-load-path-depth)))
179          (emod-load-path
180           (and module-directory
181                (paths-construct-module-load-path roots module-directory
182                                                  site-module-directory)))
183          (root-load-path
184           (paths-find-recursive-load-path
185            (mapcar #'(lambda (root)
186                        (expand-file-name "lisp" root))
187                    roots) 1)))
188
189     (append env-load-path
190             emod-load-path
191             early-package-load-path
192             late-package-load-path
193             mule-lisp-load-path
194             ffi-lisp-load-path
195             lisp-load-path
196             root-load-path
197             last-package-load-path)))
198
199 (defun paths-construct-info-path (roots early-packages late-packages last-packages)
200   "Construct the info path."
201   (let ((info-path-envval (getenv "INFOPATH")))
202     (paths-uniq-append
203      (append
204       (list (paths-find-emacs-directory roots "share/" "info" nil configure-info-directory))
205       (let ((info-directory
206              (or (paths-find-version-archindep-directory
207                   roots "info" nil configure-info-directory)
208                  (paths-find-version-archdep-directory
209                   roots "info" nil configure-info-directory))))
210         (and info-directory
211              (list info-directory)))
212       (packages-find-package-info-path early-packages)
213       (packages-find-package-info-path late-packages)
214       (packages-find-package-info-path last-packages)
215       (and info-path-envval
216            (paths-decode-directory-path info-path-envval 'drop-empties)))
217      (and (null info-path-envval)
218           (paths-uniq-append
219            (paths-directories-which-exist configure-info-path)
220            (paths-directories-which-exist paths-default-info-directories))))))
221
222 (defun paths-find-doc-directory (roots)
223   "Find the documentation directory."
224   (cond
225    ;; in-place from $blddir/src/.libs
226    ((file-exists-p (paths-construct-path `(".." ,internal-doc-file-name)
227                                          (invocation-directory)))
228     (expand-file-name "../" invocation-directory))
229    ;; in-place from $blddir/src
230    ((file-exists-p (expand-file-name internal-doc-file-name
231                                      (invocation-directory)))
232     (invocation-directory))
233    ;; installed
234    (t
235     (paths-find-architecture-directory roots nil nil
236                                        (or configure-doc-directory
237                                            exec-directory)))))
238
239 (defun paths-find-exec-directory (roots)
240   "Find the binary directory."
241   (paths-find-architecture-directory roots "lib-src"
242                                      nil configure-exec-directory))
243
244 (defun paths-construct-exec-path (roots exec-directory
245                                   early-packages late-packages last-packages)
246   "Find the binary path."
247   (append
248    (let ((path-envval (getenv "PATH")))
249      (if path-envval
250          (paths-decode-directory-path path-envval 'drop-empties)))
251    (packages-find-package-exec-path early-packages)
252    (packages-find-package-exec-path late-packages)
253    (let ((emacspath-envval (getenv "EMACSPATH")))
254      (and emacspath-envval
255           (split-path emacspath-envval)))
256    (and exec-directory
257         (list exec-directory))
258    (packages-find-package-exec-path last-packages)))
259
260 (defun paths-find-data-directory (roots)
261   "Find the data directory."
262   ;; better approach wanted!!! -hroptatyr
263   ;; for now we're just using the toolbar subdirectory as indicator
264   ;; of a healthy etc/ directory
265   (expand-file-name
266    "../" (or
267           ;; in-place
268           (paths-find-version-archdep-directory
269            roots "etc/toolbar" "EMACSDATA" configure-data-directory)
270           ;; installed
271           (paths-find-version-archindep-directory
272            roots "etc/toolbar" "EMACSDATA" configure-data-directory))))
273
274 (defun paths-construct-data-directory-list (data-directory
275                                             early-packages late-packages last-packages)
276   "Find the data path."
277   (append
278    (packages-find-package-data-path early-packages)
279    (packages-find-package-data-path late-packages)
280    (list data-directory)
281    (packages-find-package-data-path last-packages)))
282
283 ;;; setup-paths.el ends here