1 |
578 |
markom |
/* paths.c - Find IDE and application Tcl libraries.
|
2 |
|
|
Copyright (C) 1997 Cygnus Solutions.
|
3 |
|
|
Written by Tom Tromey <tromey@cygnus.com>. */
|
4 |
|
|
|
5 |
|
|
#include <tk.h>
|
6 |
|
|
#include <tcl.h>
|
7 |
|
|
|
8 |
|
|
#include "guitcl.h"
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
/* This Tcl code sets up all the path information we care about.
|
13 |
|
|
|
14 |
|
|
We first look for the gui library. This can be set by the
|
15 |
|
|
CYGNUS_GUI_LIBRARY environment variable. Otherwise, it is named
|
16 |
|
|
gui, and is found in $prefix/share/cygnus, where $prefix is
|
17 |
|
|
determined by looking at the directory where the running executable
|
18 |
|
|
is installed.
|
19 |
|
|
|
20 |
|
|
We then look for the ide library. This can be set by the
|
21 |
|
|
CYGNUS_IDE_LIBRARY environment variable. Otherwise, it is named
|
22 |
|
|
ide, and is also found in $prefix/share/cygnus.
|
23 |
|
|
|
24 |
|
|
It is OK if only one of these libraries exist. If neither exists,
|
25 |
|
|
we report an error.
|
26 |
|
|
|
27 |
|
|
We also set the following elements in the global Paths array.
|
28 |
|
|
|
29 |
|
|
prefix -- as in the configure argument
|
30 |
|
|
exec_prefix -- ditto
|
31 |
|
|
bindir -- ditto
|
32 |
|
|
libexecdir -- ditto
|
33 |
|
|
guidir -- the gui directory (not set if it does not exist)
|
34 |
|
|
idedir -- the ide directory (not set if it does not exist)
|
35 |
|
|
appdir -- see below
|
36 |
|
|
bitmapdir -- see below
|
37 |
|
|
|
38 |
|
|
Paths(appdir) is set based on the ide_initialize_paths APPNAME
|
39 |
|
|
parameter. If a directory $prefix/share/cygnus/APPNAME exists, we
|
40 |
|
|
set Paths(appdir) to it. More precisely, we set Paths(appdir) if
|
41 |
|
|
an APPNAME directory exists which is a sibling directory of the gui
|
42 |
|
|
or ide directory. For convenience of some tools, we also check for
|
43 |
|
|
$prefix/share/APPNAME, or, more precisely, we check whether APPNAME
|
44 |
|
|
is a sibling directory of the parent of the gui or ide directory.
|
45 |
|
|
|
46 |
|
|
Paths(bitmapdir) is set if gui or ide have a sibling directory
|
47 |
|
|
named bitmaps. */
|
48 |
|
|
|
49 |
|
|
#ifndef _MSC_VER
|
50 |
|
|
static char init_script[] = "\
|
51 |
|
|
proc initialize_paths {} {\n\
|
52 |
|
|
global ide_application_name auto_path env Paths\n\
|
53 |
|
|
global tcl_library\n\
|
54 |
|
|
rename initialize_paths {}\n\
|
55 |
|
|
# First find the GUI library.\n\
|
56 |
|
|
set guidirs {}\n\
|
57 |
|
|
set prefdirs {}\n\
|
58 |
|
|
if [info exists env(CYGNUS_GUI_LIBRARY)] {\n\
|
59 |
|
|
lappend guidirs $env(CYGNUS_GUI_LIBRARY)\n\
|
60 |
|
|
}\n\
|
61 |
|
|
set here [pwd]\n\
|
62 |
|
|
set exec_name [info nameofexecutable]\n\
|
63 |
|
|
if {[string compare [file type $exec_name] \"link\"] == 0} {\n\
|
64 |
|
|
set exec_name [file readlink $exec_name]\n\
|
65 |
|
|
if {[string compare [file pathtype $exec_name] \"relative\"] == 0} {\n\
|
66 |
|
|
set exec_name [file join [pwd] $exec_name]\n\
|
67 |
|
|
}\n\
|
68 |
|
|
}\n\
|
69 |
|
|
cd [file dirname $exec_name]\n\
|
70 |
|
|
# Handle build with --exec-prefix and build without.\n\
|
71 |
|
|
set d [file join [file dirname [pwd]] usr share]\n\
|
72 |
|
|
lappend prefdirs $d\n\
|
73 |
|
|
lappend guidirs [file join $d cygnus gui]\n\
|
74 |
|
|
set d [file join [file dirname [pwd]] share]\n\
|
75 |
|
|
lappend prefdirs $d\n\
|
76 |
|
|
lappend guidirs [file join $d cygnus gui]\n\
|
77 |
|
|
set d [file join [file dirname [file dirname [pwd]]] share]\n\
|
78 |
|
|
lappend prefdirs $d\n\
|
79 |
|
|
lappend guidirs [file join $d cygnus gui]\n\
|
80 |
|
|
set Paths(bindir) [pwd]\n\
|
81 |
|
|
# Base `prefix' on where the `share' dir is found\n\
|
82 |
|
|
foreach sd $prefdirs {\n\
|
83 |
|
|
if [file isdirectory $sd] {\n\
|
84 |
|
|
set Paths(prefix) [file dirname $sd]\n\
|
85 |
|
|
break\n\
|
86 |
|
|
}\n\
|
87 |
|
|
}\n\
|
88 |
|
|
if {[file isdirectory [file join [file dirname [pwd]] libexec]]} {\n\
|
89 |
|
|
set Paths(libexecdir) [file join [file dirname [pwd]] libexec]\n\
|
90 |
|
|
} else {\n\
|
91 |
|
|
set Paths(libexecdir) $Paths(bindir)\n\
|
92 |
|
|
}\n\
|
93 |
|
|
set Paths(exec_prefix) [file dirname [pwd]]\n\
|
94 |
|
|
cd $here\n\
|
95 |
|
|
# Try to handle running from the build tree:\n\
|
96 |
|
|
lappend guidirs [file join [file dirname [file dirname $tcl_library]] libgui library]\n\
|
97 |
|
|
foreach sd $guidirs {\n\
|
98 |
|
|
if {[file exists [file join $sd tclIndex]]} {\n\
|
99 |
|
|
lappend auto_path $sd\n\
|
100 |
|
|
set Paths(guidir) $sd\n\
|
101 |
|
|
break\n\
|
102 |
|
|
}\n\
|
103 |
|
|
}\n\
|
104 |
|
|
# Now find the IDE library, if it exists.\n\
|
105 |
|
|
set idedirs {}\n\
|
106 |
|
|
if [info exists env(CYGNUS_IDE_LIBRARY)] {\n\
|
107 |
|
|
lappend idedirs $env(CYGNUS_IDE_LIBRARY)\n\
|
108 |
|
|
}\n\
|
109 |
|
|
foreach d $prefdirs {\n\
|
110 |
|
|
lappend idedirs [file join $d cygnus ide]\n\
|
111 |
|
|
}\n\
|
112 |
|
|
# Try to handle running from the build tree:\n\
|
113 |
|
|
lappend idedirs [file join [file dirname [file dirname $tcl_library]] libide library]\n\
|
114 |
|
|
foreach sd $idedirs {\n\
|
115 |
|
|
if {[file exists [file join $sd tclIndex]]} {\n\
|
116 |
|
|
lappend auto_path $sd\n\
|
117 |
|
|
set Paths(idedir) $sd\n\
|
118 |
|
|
break\n\
|
119 |
|
|
}\n\
|
120 |
|
|
}\n\
|
121 |
|
|
# Now set the bitmap directory:\n\
|
122 |
|
|
foreach v [list guidir idedir] {\n\
|
123 |
|
|
if {[info exists Paths($v)]} {\n\
|
124 |
|
|
set d [file dirname $Paths($v)]\n\
|
125 |
|
|
if {[file isdirectory [file join $d bitmaps]]} {\n\
|
126 |
|
|
set Paths(bitmapdir) [file join $d bitmaps]\n\
|
127 |
|
|
}\n\
|
128 |
|
|
}\n\
|
129 |
|
|
}\n\
|
130 |
|
|
\n\
|
131 |
|
|
# We do things in a somewhat roundabout way here. This lets us\n\
|
132 |
|
|
# run from the source directory, if we're willing to be a little messy\n\
|
133 |
|
|
# in our test scripts. FIXME: find a cleaner way.\n\
|
134 |
|
|
# This routine is really meant to find the libgui & libide library directories.\n\
|
135 |
|
|
#\n\
|
136 |
|
|
# The client may not want it trying to find the application library\n\
|
137 |
|
|
# Signal that by setting ide_application_name to empty string\n\
|
138 |
|
|
if {$ide_application_name != \"\"} {\n\
|
139 |
|
|
foreach v [list guidir idedir] {\n\
|
140 |
|
|
if {[info exists Paths($v)]} {\n\
|
141 |
|
|
set d [file dirname $Paths($v)]\n\
|
142 |
|
|
if {[file isdirectory [file join $d $ide_application_name]]} {\n\
|
143 |
|
|
lappend auto_path [file join $d $ide_application_name]\n\
|
144 |
|
|
set Paths(appdir) [file join $d $ide_application_name]\n\
|
145 |
|
|
}\n\
|
146 |
|
|
}\n\
|
147 |
|
|
}\n\
|
148 |
|
|
if {! [info exists Paths(appdir)]} {\n\
|
149 |
|
|
foreach v [list guidir idedir] {\n\
|
150 |
|
|
if {[info exists Paths($v)]} {\n\
|
151 |
|
|
set d [file dirname [file dirname $Paths($v)]]\n\
|
152 |
|
|
if {[file isdirectory [file join $d $ide_application_name]]} {\n\
|
153 |
|
|
lappend auto_path [file join $d $ide_application_name]\n\
|
154 |
|
|
set Paths(appdir) [file join $d $ide_application_name]\n\
|
155 |
|
|
}\n\
|
156 |
|
|
}\n\
|
157 |
|
|
}\n\
|
158 |
|
|
}\n\
|
159 |
|
|
}\n\
|
160 |
|
|
if {[info exists Paths(guidir)] || [info exists Paths(idedir)]} {\n\
|
161 |
|
|
return\n\
|
162 |
|
|
}\n\
|
163 |
|
|
# FIXME: must run this message through gettext.\n\
|
164 |
|
|
# Can only do this once gettext is in C and not just a stub.\n\
|
165 |
|
|
set msg \"Can't find the GUI Tcl library in the following directories:\n\"\n\
|
166 |
|
|
append msg \" $guidirs $idedirs\n\"\n\
|
167 |
|
|
error $msg\n\
|
168 |
|
|
}\n\
|
169 |
|
|
initialize_paths";
|
170 |
|
|
#else
|
171 |
|
|
static char init_script[] = "\
|
172 |
|
|
proc initialize_paths {} {\n\
|
173 |
|
|
global ide_application_name auto_path env Paths\n\
|
174 |
|
|
global tcl_library\n\
|
175 |
|
|
rename initialize_paths {}\n\
|
176 |
|
|
set guidirs {}\n\
|
177 |
|
|
set here [pwd]\n\
|
178 |
|
|
cd [file dirname [info nameofexecutable]]\n\
|
179 |
|
|
set d [file join [file dirname [pwd]] share]\n\
|
180 |
|
|
lappend guidirs [file join $d cygnus gui]\n\
|
181 |
|
|
set d [file join [file dirname [file dirname [pwd]]] share]\n\
|
182 |
|
|
lappend guidirs [file join $d cygnus gui]\n\
|
183 |
|
|
lappend guidirs [file join [file dirname [file dirname $tcl_library]] libgui library]\n\
|
184 |
|
|
foreach sd $guidirs {\n\
|
185 |
|
|
if {[file exists [file join $sd tclIndex]]} {\n\
|
186 |
|
|
lappend auto_path $sd\n\
|
187 |
|
|
set Paths(guidir) $sd\n\
|
188 |
|
|
break\n\
|
189 |
|
|
}\n\
|
190 |
|
|
}\n\
|
191 |
|
|
foreach v [list guidir] {\n\
|
192 |
|
|
if {[info exists Paths($v)]} {\n\
|
193 |
|
|
set d [file dirname $Paths($v)]\n\
|
194 |
|
|
if {[file isdirectory [file join $d bitmaps]]} {\n\
|
195 |
|
|
set Paths(bitmapdir) [file join $d bitmaps]\n\
|
196 |
|
|
}\n\
|
197 |
|
|
}\n\
|
198 |
|
|
}\n\
|
199 |
|
|
\n\
|
200 |
|
|
if {$ide_application_name != \"\"} {\n\
|
201 |
|
|
foreach v [list guidir ] {\n\
|
202 |
|
|
if {[info exists Paths($v)]} {\n\
|
203 |
|
|
set d [file dirname $Paths($v)]\n\
|
204 |
|
|
if {[file isdirectory [file join $d $ide_application_name]]} {\n\
|
205 |
|
|
lappend auto_path [file join $d $ide_application_name]\n\
|
206 |
|
|
set Paths(appdir) [file join $d $ide_application_name]\n\
|
207 |
|
|
}\n\
|
208 |
|
|
}\n\
|
209 |
|
|
}\n\
|
210 |
|
|
if {! [info exists Paths(appdir)]} {\n\
|
211 |
|
|
foreach v [list guidir] {\n\
|
212 |
|
|
if {[info exists Paths($v)]} {\n\
|
213 |
|
|
set d [file dirname [file dirname $Paths($v)]]\n\
|
214 |
|
|
if {[file isdirectory [file join $d $ide_application_name]]} {\n\
|
215 |
|
|
lappend auto_path [file join $d $ide_application_name]\n\
|
216 |
|
|
set Paths(appdir) [file join $d $ide_application_name]\n\
|
217 |
|
|
}\n\
|
218 |
|
|
}\n\
|
219 |
|
|
}\n\
|
220 |
|
|
}\n\
|
221 |
|
|
}\n\
|
222 |
|
|
if {[info exists Paths(guidir)]} {\n\
|
223 |
|
|
return\n\
|
224 |
|
|
}\n\
|
225 |
|
|
set msg \"Can't find the GUI Tcl library in the following directories:\n\"\n\
|
226 |
|
|
append msg \" $guidirs\n\"\n\
|
227 |
|
|
error $msg\n\
|
228 |
|
|
}\n\
|
229 |
|
|
initialize_paths";
|
230 |
|
|
#endif
|
231 |
|
|
|
232 |
|
|
/* Initialize the global Paths variable. */
|
233 |
|
|
int
|
234 |
|
|
ide_initialize_paths (Tcl_Interp *interp, char *appname)
|
235 |
|
|
{
|
236 |
|
|
if (Tcl_SetVar (interp, "ide_application_name", appname,
|
237 |
|
|
TCL_GLOBAL_ONLY) == NULL)
|
238 |
|
|
return (TCL_ERROR);
|
239 |
|
|
return (Tcl_GlobalEval (interp, init_script));
|
240 |
|
|
}
|
241 |
|
|
|
242 |
|
|
#ifdef TCLPRO_DEBUGGER
|
243 |
|
|
static char run_app_script[] = "\
|
244 |
|
|
proc initialize_find_app_script {} {\n\
|
245 |
|
|
global Paths env ide_application_name\n\
|
246 |
|
|
rename initialize_find_app_script {}\n\
|
247 |
|
|
if {[info exists env(TCLPRO_DEBUG_DIR)]} {\n\
|
248 |
|
|
source [file join $env(TCLPRO_DEBUG_DIR) prodebug.tcl]\n\
|
249 |
|
|
debugger_init\n\
|
250 |
|
|
}\n\
|
251 |
|
|
# Look in idedir for the sake of test apps like idetrace.\n\
|
252 |
|
|
foreach v [list appdir idedir] {\n\
|
253 |
|
|
if {[info exists Paths($v)]} {\n\
|
254 |
|
|
set file [file join $Paths($v) ${ide_application_name}.tcl]\n\
|
255 |
|
|
if {[file exists $file]} {\n\
|
256 |
|
|
if {[info exists env(TCLPRO_DEBUG_DIR)]} {\n\
|
257 |
|
|
# Right now, only one process can be debugged at a time.\n\
|
258 |
|
|
# Unset the debug dir, so we won't try to debug any\n\
|
259 |
|
|
# child processes...\n\
|
260 |
|
|
unset env(TCLPRO_DEBUG_DIR)\n\
|
261 |
|
|
uplevel #0 debugger_eval [list source $file]\n\
|
262 |
|
|
} else {\n\
|
263 |
|
|
uplevel #0 [list source $file]\n\
|
264 |
|
|
}\n\
|
265 |
|
|
return\n\
|
266 |
|
|
}\n\
|
267 |
|
|
}\n\
|
268 |
|
|
}\n\
|
269 |
|
|
# FIXME: must run message through gettext.\n\
|
270 |
|
|
error \"Can't find ${ide_application_name}.tcl\"\n\
|
271 |
|
|
}\n\
|
272 |
|
|
initialize_find_app_script";
|
273 |
|
|
#else
|
274 |
|
|
static char run_app_script[] = "\
|
275 |
|
|
proc initialize_find_app_script {} {\n\
|
276 |
|
|
global Paths ide_application_name\n\
|
277 |
|
|
rename initialize_find_app_script {}\n\
|
278 |
|
|
# Look in idedir for the sake of test apps like idetrace.\n\
|
279 |
|
|
foreach v [list appdir idedir] {\n\
|
280 |
|
|
if {[info exists Paths($v)]} {\n\
|
281 |
|
|
set file [file join $Paths($v) ${ide_application_name}.tcl]\n\
|
282 |
|
|
if {[file exists $file]} {\n\
|
283 |
|
|
uplevel #0 [list source $file]\n\
|
284 |
|
|
return\n\
|
285 |
|
|
}\n\
|
286 |
|
|
}\n\
|
287 |
|
|
}\n\
|
288 |
|
|
# FIXME: must run message through gettext.\n\
|
289 |
|
|
error \"Can't find ${ide_application_name}.tcl\"\n\
|
290 |
|
|
}\n\
|
291 |
|
|
initialize_find_app_script";
|
292 |
|
|
#endif
|
293 |
|
|
|
294 |
|
|
/* Run the application-specific init script. */
|
295 |
|
|
int
|
296 |
|
|
ide_run_app_script (Tcl_Interp *interp)
|
297 |
|
|
{
|
298 |
|
|
return (Tcl_GlobalEval (interp, run_app_script));
|
299 |
|
|
}
|