Source code

Revision control

Other Tools

1
#!/bin/sh
2
#
3
# This Source Code Form is subject to the terms of the Mozilla Public
4
# License, v. 2.0. If a copy of the MPL was not distributed with this
5
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
cmdname=`basename "$0"`
7
MOZ_DIST_BIN=`dirname "$0"`
8
MOZ_DEFAULT_NAME="./${cmdname}-bin"
9
MOZ_APPRUNNER_NAME="./mozilla-bin"
10
MOZ_PROGRAM=""
11
12
exitcode=1
13
#
14
##
15
## Functions
16
##
17
##########################################################################
18
moz_usage()
19
{
20
echo "Usage: ${cmdname} [options] [program]"
21
echo ""
22
echo " options:"
23
echo ""
24
echo " -g Run in debugger."
25
echo " --debug"
26
echo ""
27
echo " -d debugger Debugger to use."
28
echo " --debugger debugger"
29
echo ""
30
echo " -a debugger_args Arguments passed to [debugger]."
31
echo " --debugger-args debugger_args"
32
echo ""
33
echo " Examples:"
34
echo ""
35
echo " Run the mozilla-bin binary"
36
echo ""
37
echo " ${cmdname} mozilla-bin"
38
echo ""
39
echo " Debug the mozilla-bin binary in gdb"
40
echo ""
41
echo " ${cmdname} -g mozilla-bin -d gdb"
42
echo ""
43
echo " Run mozilla-bin under valgrind with arguments"
44
echo ""
45
echo " ${cmdname} -g -d valgrind -a '--tool=memcheck --leak-check=full' mozilla-bin"
46
echo ""
47
return 0
48
}
49
##########################################################################
50
moz_bail()
51
{
52
message=$1
53
echo
54
echo "$cmdname: $message"
55
echo
56
exit 1
57
}
58
##########################################################################
59
moz_test_binary()
60
{
61
binary=$1
62
if [ -f "$binary" ]
63
then
64
if [ -x "$binary" ]
65
then
66
return 1
67
fi
68
fi
69
return 0
70
}
71
##########################################################################
72
moz_get_debugger()
73
{
74
debuggers="ddd gdb dbx bdb native-gdb"
75
debugger="notfound"
76
done="no"
77
for d in $debuggers
78
do
79
moz_test_binary /bin/which
80
if [ $? -eq 1 ]
81
then
82
dpath=`which ${d}`
83
else
84
dpath=`LC_MESSAGES=C type ${d} | awk '{print $3;}' | sed -e 's/\.$//'`
85
fi
86
if [ -x "$dpath" ]
87
then
88
debugger=$dpath
89
break
90
fi
91
done
92
echo $debugger
93
return 0
94
}
95
##########################################################################
96
moz_run_program()
97
{
98
prog=$MOZ_PROGRAM
99
##
100
## Make sure the program is executable
101
##
102
if [ ! -x "$prog" ]
103
then
104
moz_bail "Cannot execute $prog."
105
fi
106
##
107
## Run the program
108
##
109
exec "$prog" ${1+"$@"}
110
exitcode=$?
111
}
112
##########################################################################
113
moz_debug_program()
114
{
115
prog=$MOZ_PROGRAM
116
##
117
## Make sure the program is executable
118
##
119
if [ ! -x "$prog" ]
120
then
121
moz_bail "Cannot execute $prog."
122
fi
123
if [ -n "$moz_debugger" ]
124
then
125
moz_test_binary /bin/which
126
if [ $? -eq 1 ]
127
then
128
debugger=`which $moz_debugger`
129
else
130
debugger=`LC_MESSAGES=C type $moz_debugger | awk '{print $3;}' | sed -e 's/\.$//'`
131
fi
132
else
133
debugger=`moz_get_debugger`
134
fi
135
if [ -x "$debugger" ]
136
then
137
# If you are not using ddd, gdb and know of a way to convey the arguments
138
# over to the prog then add that here- Gagan Saksena 03/15/00
139
case `basename $debugger` in
140
native-gdb) echo "$debugger $moz_debugger_args --args $prog" ${1+"$@"}
141
exec "$debugger" $moz_debugger_args --args "$prog" ${1+"$@"}
142
exitcode=$?
143
;;
144
gdb) echo "$debugger $moz_debugger_args --args $prog" ${1+"$@"}
145
exec "$debugger" $moz_debugger_args --args "$prog" ${1+"$@"}
146
exitcode=$?
147
;;
148
ddd) echo "$debugger $moz_debugger_args --gdb -- --args $prog" ${1+"$@"}
149
exec "$debugger" $moz_debugger_args --gdb -- --args "$prog" ${1+"$@"}
150
exitcode=$?
151
;;
152
*) echo "$debugger $moz_debugger_args $prog ${1+"$@"}"
153
exec $debugger $moz_debugger_args "$prog" ${1+"$@"}
154
exitcode=$?
155
;;
156
esac
157
else
158
moz_bail "Could not find a debugger on your system."
159
fi
160
}
161
##########################################################################
162
##
163
## Command line arg defaults
164
##
165
moz_debug=0
166
moz_debugger=""
167
moz_debugger_args=""
168
#
169
##
170
## Parse the command line
171
##
172
while [ $# -gt 0 ]
173
do
174
case $1 in
175
-g | --debug)
176
moz_debug=1
177
shift
178
;;
179
-d | --debugger)
180
moz_debugger=$2;
181
if [ "${moz_debugger}" != "" ]; then
182
shift 2
183
else
184
echo "-d requires an argument"
185
exit 1
186
fi
187
;;
188
-a | --debugger-args)
189
moz_debugger_args=$2;
190
if [ "${moz_debugger_args}" != "" ]; then
191
shift 2
192
else
193
echo "-a requires an argument"
194
exit 1
195
fi
196
;;
197
*)
198
break;
199
;;
200
esac
201
done
202
#
203
##
204
## Program name given in $1
205
##
206
if [ $# -gt 0 ]
207
then
208
MOZ_PROGRAM=$1
209
shift
210
fi
211
##
212
## Program not given, try to guess a default
213
##
214
if [ -z "$MOZ_PROGRAM" ]
215
then
216
##
217
## Try this script's name with '-bin' appended
218
##
219
if [ -x "$MOZ_DEFAULT_NAME" ]
220
then
221
MOZ_PROGRAM=$MOZ_DEFAULT_NAME
222
##
223
## Try mozilla-bin
224
##
225
elif [ -x "$MOZ_APPRUNNER_NAME" ]
226
then
227
MOZ_PROGRAM=$MOZ_APPRUNNER_NAME
228
fi
229
fi
230
#
231
#
232
##
233
## Make sure the program is executable
234
##
235
if [ ! -x "$MOZ_PROGRAM" ]
236
then
237
moz_bail "Cannot execute $MOZ_PROGRAM."
238
fi
239
#
240
if [ -z "$MRE_HOME" ]; then
241
MRE_HOME=$MOZ_DIST_BIN
242
fi
243
##
244
## Set LD_LIBRARY_PATH
245
##
246
## On Solaris we use $ORIGIN (set in RUNPATH) instead of LD_LIBRARY_PATH
247
## to locate shared libraries.
248
##
249
## When a shared library is a symbolic link, $ORIGIN will be replaced with
250
## the real path (i.e., what the symbolic link points to) by the runtime
251
## linker. For example, if dist/bin/libxul.so is a symbolic link to
252
## toolkit/library/libxul.so, $ORIGIN will be "toolkit/library" instead of "dist/bin".
253
## So the runtime linker will use "toolkit/library" NOT "dist/bin" to locate the
254
## other shared libraries that libxul.so depends on. This only happens
255
## when a user (developer) tries to start firefox, thunderbird, or seamonkey
256
## under dist/bin. To solve the problem, we should rely on LD_LIBRARY_PATH
257
## to locate shared libraries.
258
##
259
## Note:
260
## We test $MOZ_DIST_BIN/*.so. If any of them is a symbolic link,
261
## we need to set LD_LIBRARY_PATH.
262
##########################################################################
263
moz_should_set_ld_library_path()
264
{
265
[ `uname -s` != "SunOS" ] && return 0
266
for sharedlib in $MOZ_DIST_BIN/*.so
267
do
268
[ -h $sharedlib ] && return 0
269
done
270
return 1
271
}
272
if moz_should_set_ld_library_path
273
then
274
LD_LIBRARY_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARY_PATH:+":$LD_LIBRARY_PATH"}
275
fi
276
277
if [ -n "$LD_LIBRARYN32_PATH" ]
278
then
279
LD_LIBRARYN32_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARYN32_PATH:+":$LD_LIBRARYN32_PATH"}
280
fi
281
if [ -n "$LD_LIBRARYN64_PATH" ]
282
then
283
LD_LIBRARYN64_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARYN64_PATH:+":$LD_LIBRARYN64_PATH"}
284
fi
285
if [ -n "$LD_LIBRARY_PATH_64" ]; then
286
LD_LIBRARY_PATH_64=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARY_PATH_64:+":$LD_LIBRARY_PATH_64"}
287
fi
288
#
289
#
290
## Set SHLIB_PATH for HPUX
291
SHLIB_PATH=${MOZ_DIST_BIN}:${MRE_HOME}${SHLIB_PATH:+":$SHLIB_PATH"}
292
#
293
## Set LIBPATH for AIX
294
LIBPATH=${MOZ_DIST_BIN}:${MRE_HOME}${LIBPATH:+":$LIBPATH"}
295
#
296
## Set DYLD_LIBRARY_PATH for Mac OS X (Darwin)
297
DYLD_LIBRARY_PATH=${MOZ_DIST_BIN}:${MRE_HOME}${DYLD_LIBRARY_PATH:+":$DYLD_LIBRARY_PATH"}
298
#
299
## Solaris Xserver(Xsun) tuning - use shared memory transport if available
300
if [ "$XSUNTRANSPORT" = "" ]
301
then
302
XSUNTRANSPORT="shmem"
303
XSUNSMESIZE="512"
304
export XSUNTRANSPORT XSUNSMESIZE
305
fi
306
307
# Disable Gnome crash dialog
308
GNOME_DISABLE_CRASH_DIALOG=1
309
export GNOME_DISABLE_CRASH_DIALOG
310
311
if [ "$moz_debug" -eq 1 ]
312
then
313
echo " LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
314
if [ -n "$LD_LIBRARYN32_PATH" ]
315
then
316
echo "LD_LIBRARYN32_PATH=$LD_LIBRARYN32_PATH"
317
fi
318
if [ -n "$LD_LIBRARYN64_PATH" ]
319
then
320
echo "LD_LIBRARYN64_PATH=$LD_LIBRARYN64_PATH"
321
fi
322
if [ -n "$LD_LIBRARY_PATH_64" ]; then
323
echo "LD_LIBRARY_PATH_64=$LD_LIBRARY_PATH_64"
324
fi
325
if [ -n "$DISPLAY" ]; then
326
echo "DISPLAY=$DISPLAY"
327
fi
328
if [ -n "$FONTCONFIG_PATH" ]; then
329
echo "FONTCONFIG_PATH=$FONTCONFIG_PATH"
330
fi
331
if [ -n "$MOZILLA_POSTSCRIPT_PRINTER_LIST" ]; then
332
echo "MOZILLA_POSTSCRIPT_PRINTER_LIST=$MOZILLA_POSTSCRIPT_PRINTER_LIST"
333
fi
334
echo "DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH"
335
echo " LIBRARY_PATH=$LIBRARY_PATH"
336
echo " SHLIB_PATH=$SHLIB_PATH"
337
echo " LIBPATH=$LIBPATH"
338
echo " ADDON_PATH=$ADDON_PATH"
339
echo " MOZ_PROGRAM=$MOZ_PROGRAM"
340
echo " MOZ_TOOLKIT=$MOZ_TOOLKIT"
341
echo " moz_debug=$moz_debug"
342
echo " moz_debugger=$moz_debugger"
343
echo "moz_debugger_args=$moz_debugger_args"
344
fi
345
#
346
export LD_LIBRARY_PATH
347
export SHLIB_PATH LIBPATH LIBRARY_PATH ADDON_PATH DYLD_LIBRARY_PATH
348
349
if [ $moz_debug -eq 1 ]
350
then
351
moz_debug_program ${1+"$@"}
352
else
353
moz_run_program ${1+"$@"}
354
fi
355
356
exit $exitcode