Bumping manifests a=b2g-bump
[gecko.git] / build / unix / run-mozilla.sh
blobc053e60b1fcc41498eb412392b7f381bbe72ae8f
1 #!/bin/sh
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=""
12 exitcode=1
15 ## Functions
17 ##########################################################################
18 moz_usage()
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
49 ##########################################################################
50 moz_bail()
52 message=$1
53 echo
54 echo "$cmdname: $message"
55 echo
56 exit 1
58 ##########################################################################
59 moz_test_binary()
61 binary=$1
62 if [ -f "$binary" ]
63 then
64 if [ -x "$binary" ]
65 then
66 return 1
69 return 0
71 ##########################################################################
72 moz_get_debugger()
74 debuggers="ddd gdb dbx bdb native-gdb"
75 debugger="notfound"
76 done="no"
77 for d in $debuggers
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/\.$//'`
86 if [ -x "$dpath" ]
87 then
88 debugger=$dpath
89 break
91 done
92 echo $debugger
93 return 0
95 ##########################################################################
96 moz_run_program()
98 prog=$MOZ_PROGRAM
100 ## Make sure the program is executable
102 if [ ! -x "$prog" ]
103 then
104 moz_bail "Cannot execute $prog."
107 ## Run the program
109 exec "$prog" ${1+"$@"}
110 exitcode=$?
112 ##########################################################################
113 moz_debug_program()
115 prog=$MOZ_PROGRAM
117 ## Make sure the program is executable
119 if [ ! -x "$prog" ]
120 then
121 moz_bail "Cannot execute $prog."
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/\.$//'`
132 else
133 debugger=`moz_get_debugger`
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=$?
144 gdb) echo "$debugger $moz_debugger_args --args $prog" ${1+"$@"}
145 exec "$debugger" $moz_debugger_args --args "$prog" ${1+"$@"}
146 exitcode=$?
148 ddd) echo "$debugger $moz_debugger_args --gdb -- --args $prog" ${1+"$@"}
149 exec "$debugger" $moz_debugger_args --gdb -- --args "$prog" ${1+"$@"}
150 exitcode=$?
152 *) echo "$debugger $moz_debugger_args $prog ${1+"$@"}"
153 exec $debugger $moz_debugger_args "$prog" ${1+"$@"}
154 exitcode=$?
156 esac
157 else
158 moz_bail "Could not find a debugger on your system."
161 ##########################################################################
163 ## Command line arg defaults
165 moz_debug=0
166 moz_debugger=""
167 moz_debugger_args=""
170 ## Parse the command line
172 while [ $# -gt 0 ]
174 case $1 in
175 -g | --debug)
176 moz_debug=1
177 shift
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
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
198 break;
200 esac
201 done
204 ## Program name given in $1
206 if [ $# -gt 0 ]
207 then
208 MOZ_PROGRAM=$1
209 shift
212 ## Program not given, try to guess a default
214 if [ -z "$MOZ_PROGRAM" ]
215 then
217 ## Try this script's name with '-bin' appended
219 if [ -x "$MOZ_DEFAULT_NAME" ]
220 then
221 MOZ_PROGRAM=$MOZ_DEFAULT_NAME
223 ## Try mozilla-bin
225 elif [ -x "$MOZ_APPRUNNER_NAME" ]
226 then
227 MOZ_PROGRAM=$MOZ_APPRUNNER_NAME
233 ## Make sure the program is executable
235 if [ ! -x "$MOZ_PROGRAM" ]
236 then
237 moz_bail "Cannot execute $MOZ_PROGRAM."
241 ## Set MOZILLA_FIVE_HOME
243 MOZILLA_FIVE_HOME=$MOZ_DIST_BIN
245 if [ -z "$MRE_HOME" ]; then
246 MRE_HOME=$MOZILLA_FIVE_HOME
249 ## Set LD_LIBRARY_PATH
251 ## On Solaris we use $ORIGIN (set in RUNPATH) instead of LD_LIBRARY_PATH
252 ## to locate shared libraries.
254 ## When a shared library is a symbolic link, $ORIGIN will be replaced with
255 ## the real path (i.e., what the symbolic link points to) by the runtime
256 ## linker. For example, if dist/bin/libxul.so is a symbolic link to
257 ## toolkit/library/libxul.so, $ORIGIN will be "toolkit/library" instead of "dist/bin".
258 ## So the runtime linker will use "toolkit/library" NOT "dist/bin" to locate the
259 ## other shared libraries that libxul.so depends on. This only happens
260 ## when a user (developer) tries to start firefox, thunderbird, or seamonkey
261 ## under dist/bin. To solve the problem, we should rely on LD_LIBRARY_PATH
262 ## to locate shared libraries.
264 ## Note:
265 ## We test $MOZ_DIST_BIN/*.so. If any of them is a symbolic link,
266 ## we need to set LD_LIBRARY_PATH.
267 ##########################################################################
268 moz_should_set_ld_library_path()
270 [ `uname -s` != "SunOS" ] && return 0
271 for sharedlib in $MOZ_DIST_BIN/*.so
273 [ -h $sharedlib ] && return 0
274 done
275 return 1
277 if moz_should_set_ld_library_path
278 then
279 LD_LIBRARY_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARY_PATH:+":$LD_LIBRARY_PATH"}
282 if [ -n "$LD_LIBRARYN32_PATH" ]
283 then
284 LD_LIBRARYN32_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARYN32_PATH:+":$LD_LIBRARYN32_PATH"}
286 if [ -n "$LD_LIBRARYN64_PATH" ]
287 then
288 LD_LIBRARYN64_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARYN64_PATH:+":$LD_LIBRARYN64_PATH"}
290 if [ -n "$LD_LIBRARY_PATH_64" ]; then
291 LD_LIBRARY_PATH_64=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARY_PATH_64:+":$LD_LIBRARY_PATH_64"}
295 ## Set SHLIB_PATH for HPUX
296 SHLIB_PATH=${MOZ_DIST_BIN}:${MRE_HOME}${SHLIB_PATH:+":$SHLIB_PATH"}
298 ## Set LIBPATH for AIX
299 LIBPATH=${MOZ_DIST_BIN}:${MRE_HOME}${LIBPATH:+":$LIBPATH"}
301 ## Set DYLD_LIBRARY_PATH for Mac OS X (Darwin)
302 DYLD_LIBRARY_PATH=${MOZ_DIST_BIN}:${MRE_HOME}${DYLD_LIBRARY_PATH:+":$DYLD_LIBRARY_PATH"}
304 ## Solaris Xserver(Xsun) tuning - use shared memory transport if available
305 if [ "$XSUNTRANSPORT" = "" ]
306 then
307 XSUNTRANSPORT="shmem"
308 XSUNSMESIZE="512"
309 export XSUNTRANSPORT XSUNSMESIZE
312 # Disable Gnome crash dialog
313 GNOME_DISABLE_CRASH_DIALOG=1
314 export GNOME_DISABLE_CRASH_DIALOG
316 if [ "$moz_debug" -eq 1 ]
317 then
318 echo "MOZILLA_FIVE_HOME=$MOZILLA_FIVE_HOME"
319 echo " LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
320 if [ -n "$LD_LIBRARYN32_PATH" ]
321 then
322 echo "LD_LIBRARYN32_PATH=$LD_LIBRARYN32_PATH"
324 if [ -n "$LD_LIBRARYN64_PATH" ]
325 then
326 echo "LD_LIBRARYN64_PATH=$LD_LIBRARYN64_PATH"
328 if [ -n "$LD_LIBRARY_PATH_64" ]; then
329 echo "LD_LIBRARY_PATH_64=$LD_LIBRARY_PATH_64"
331 if [ -n "$DISPLAY" ]; then
332 echo "DISPLAY=$DISPLAY"
334 if [ -n "$FONTCONFIG_PATH" ]; then
335 echo "FONTCONFIG_PATH=$FONTCONFIG_PATH"
337 if [ -n "$MOZILLA_POSTSCRIPT_PRINTER_LIST" ]; then
338 echo "MOZILLA_POSTSCRIPT_PRINTER_LIST=$MOZILLA_POSTSCRIPT_PRINTER_LIST"
340 echo "DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH"
341 echo " LIBRARY_PATH=$LIBRARY_PATH"
342 echo " SHLIB_PATH=$SHLIB_PATH"
343 echo " LIBPATH=$LIBPATH"
344 echo " ADDON_PATH=$ADDON_PATH"
345 echo " MOZ_PROGRAM=$MOZ_PROGRAM"
346 echo " MOZ_TOOLKIT=$MOZ_TOOLKIT"
347 echo " moz_debug=$moz_debug"
348 echo " moz_debugger=$moz_debugger"
349 echo "moz_debugger_args=$moz_debugger_args"
352 export MOZILLA_FIVE_HOME LD_LIBRARY_PATH
353 export SHLIB_PATH LIBPATH LIBRARY_PATH ADDON_PATH DYLD_LIBRARY_PATH
355 if [ $moz_debug -eq 1 ]
356 then
357 moz_debug_program ${1+"$@"}
358 else
359 moz_run_program ${1+"$@"}
362 exit $exitcode