PageRenderTime 28ms CodeModel.GetById 15ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/build/unix/run-mozilla.sh

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