michael@0: #!/bin/sh michael@0: # michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: cmdname=`basename "$0"` michael@0: MOZ_DIST_BIN=`dirname "$0"` michael@0: MOZ_DEFAULT_NAME="./${cmdname}-bin" michael@0: MOZ_APPRUNNER_NAME="./mozilla-bin" michael@0: MOZ_PROGRAM="" michael@0: michael@0: exitcode=1 michael@0: # michael@0: ## michael@0: ## Functions michael@0: ## michael@0: ########################################################################## michael@0: moz_usage() michael@0: { michael@0: echo "Usage: ${cmdname} [options] [program]" michael@0: echo "" michael@0: echo " options:" michael@0: echo "" michael@0: echo " -g Run in debugger." michael@0: echo " --debug" michael@0: echo "" michael@0: echo " -d debugger Debugger to use." michael@0: echo " --debugger debugger" michael@0: echo "" michael@0: echo " -a debugger_args Arguments passed to [debugger]." michael@0: echo " --debugger-args debugger_args" michael@0: echo "" michael@0: echo " Examples:" michael@0: echo "" michael@0: echo " Run the mozilla-bin binary" michael@0: echo "" michael@0: echo " ${cmdname} mozilla-bin" michael@0: echo "" michael@0: echo " Debug the mozilla-bin binary in gdb" michael@0: echo "" michael@0: echo " ${cmdname} -g mozilla-bin -d gdb" michael@0: echo "" michael@0: echo " Run mozilla-bin under valgrind with arguments" michael@0: echo "" michael@0: echo " ${cmdname} -g -d valgrind -a '--tool=memcheck --leak-check=full' mozilla-bin" michael@0: echo "" michael@0: return 0 michael@0: } michael@0: ########################################################################## michael@0: moz_bail() michael@0: { michael@0: message=$1 michael@0: echo michael@0: echo "$cmdname: $message" michael@0: echo michael@0: exit 1 michael@0: } michael@0: ########################################################################## michael@0: moz_test_binary() michael@0: { michael@0: binary=$1 michael@0: if [ -f "$binary" ] michael@0: then michael@0: if [ -x "$binary" ] michael@0: then michael@0: return 1 michael@0: fi michael@0: fi michael@0: return 0 michael@0: } michael@0: ########################################################################## michael@0: moz_get_debugger() michael@0: { michael@0: debuggers="ddd gdb dbx bdb native-gdb" michael@0: debugger="notfound" michael@0: done="no" michael@0: for d in $debuggers michael@0: do michael@0: moz_test_binary /bin/which michael@0: if [ $? -eq 1 ] michael@0: then michael@0: dpath=`which ${d}` michael@0: else michael@0: dpath=`LC_MESSAGES=C type ${d} | awk '{print $3;}' | sed -e 's/\.$//'` michael@0: fi michael@0: if [ -x "$dpath" ] michael@0: then michael@0: debugger=$dpath michael@0: break michael@0: fi michael@0: done michael@0: echo $debugger michael@0: return 0 michael@0: } michael@0: ########################################################################## michael@0: moz_run_program() michael@0: { michael@0: prog=$MOZ_PROGRAM michael@0: ## michael@0: ## Make sure the program is executable michael@0: ## michael@0: if [ ! -x "$prog" ] michael@0: then michael@0: moz_bail "Cannot execute $prog." michael@0: fi michael@0: ## michael@0: ## Run the program michael@0: ## michael@0: exec "$prog" ${1+"$@"} michael@0: exitcode=$? michael@0: } michael@0: ########################################################################## michael@0: moz_debug_program() michael@0: { michael@0: prog=$MOZ_PROGRAM michael@0: ## michael@0: ## Make sure the program is executable michael@0: ## michael@0: if [ ! -x "$prog" ] michael@0: then michael@0: moz_bail "Cannot execute $prog." michael@0: fi michael@0: if [ -n "$moz_debugger" ] michael@0: then michael@0: moz_test_binary /bin/which michael@0: if [ $? -eq 1 ] michael@0: then michael@0: debugger=`which $moz_debugger` michael@0: else michael@0: debugger=`LC_MESSAGES=C type $moz_debugger | awk '{print $3;}' | sed -e 's/\.$//'` michael@0: fi michael@0: else michael@0: debugger=`moz_get_debugger` michael@0: fi michael@0: if [ -x "$debugger" ] michael@0: then michael@0: # If you are not using ddd, gdb and know of a way to convey the arguments michael@0: # over to the prog then add that here- Gagan Saksena 03/15/00 michael@0: case `basename $debugger` in michael@0: native-gdb) echo "$debugger $moz_debugger_args --args $prog" ${1+"$@"} michael@0: exec "$debugger" $moz_debugger_args --args "$prog" ${1+"$@"} michael@0: exitcode=$? michael@0: ;; michael@0: gdb) echo "$debugger $moz_debugger_args --args $prog" ${1+"$@"} michael@0: exec "$debugger" $moz_debugger_args --args "$prog" ${1+"$@"} michael@0: exitcode=$? michael@0: ;; michael@0: ddd) echo "$debugger $moz_debugger_args --gdb -- --args $prog" ${1+"$@"} michael@0: exec "$debugger" $moz_debugger_args --gdb -- --args "$prog" ${1+"$@"} michael@0: exitcode=$? michael@0: ;; michael@0: *) echo "$debugger $moz_debugger_args $prog ${1+"$@"}" michael@0: exec $debugger $moz_debugger_args "$prog" ${1+"$@"} michael@0: exitcode=$? michael@0: ;; michael@0: esac michael@0: else michael@0: moz_bail "Could not find a debugger on your system." michael@0: fi michael@0: } michael@0: ########################################################################## michael@0: ## michael@0: ## Command line arg defaults michael@0: ## michael@0: moz_debug=0 michael@0: moz_debugger="" michael@0: moz_debugger_args="" michael@0: # michael@0: ## michael@0: ## Parse the command line michael@0: ## michael@0: while [ $# -gt 0 ] michael@0: do michael@0: case $1 in michael@0: -g | --debug) michael@0: moz_debug=1 michael@0: shift michael@0: ;; michael@0: -d | --debugger) michael@0: moz_debugger=$2; michael@0: if [ "${moz_debugger}" != "" ]; then michael@0: shift 2 michael@0: else michael@0: echo "-d requires an argument" michael@0: exit 1 michael@0: fi michael@0: ;; michael@0: -a | --debugger-args) michael@0: moz_debugger_args=$2; michael@0: if [ "${moz_debugger_args}" != "" ]; then michael@0: shift 2 michael@0: else michael@0: echo "-a requires an argument" michael@0: exit 1 michael@0: fi michael@0: ;; michael@0: *) michael@0: break; michael@0: ;; michael@0: esac michael@0: done michael@0: # michael@0: ## michael@0: ## Program name given in $1 michael@0: ## michael@0: if [ $# -gt 0 ] michael@0: then michael@0: MOZ_PROGRAM=$1 michael@0: shift michael@0: fi michael@0: ## michael@0: ## Program not given, try to guess a default michael@0: ## michael@0: if [ -z "$MOZ_PROGRAM" ] michael@0: then michael@0: ## michael@0: ## Try this script's name with '-bin' appended michael@0: ## michael@0: if [ -x "$MOZ_DEFAULT_NAME" ] michael@0: then michael@0: MOZ_PROGRAM=$MOZ_DEFAULT_NAME michael@0: ## michael@0: ## Try mozilla-bin michael@0: ## michael@0: elif [ -x "$MOZ_APPRUNNER_NAME" ] michael@0: then michael@0: MOZ_PROGRAM=$MOZ_APPRUNNER_NAME michael@0: fi michael@0: fi michael@0: # michael@0: # michael@0: ## michael@0: ## Make sure the program is executable michael@0: ## michael@0: if [ ! -x "$MOZ_PROGRAM" ] michael@0: then michael@0: moz_bail "Cannot execute $MOZ_PROGRAM." michael@0: fi michael@0: # michael@0: ## michael@0: ## Set MOZILLA_FIVE_HOME michael@0: ## michael@0: MOZILLA_FIVE_HOME=$MOZ_DIST_BIN michael@0: michael@0: if [ -z "$MRE_HOME" ]; then michael@0: MRE_HOME=$MOZILLA_FIVE_HOME michael@0: fi michael@0: ## michael@0: ## Set LD_LIBRARY_PATH michael@0: ## michael@0: ## On Solaris we use $ORIGIN (set in RUNPATH) instead of LD_LIBRARY_PATH michael@0: ## to locate shared libraries. michael@0: ## michael@0: ## When a shared library is a symbolic link, $ORIGIN will be replaced with michael@0: ## the real path (i.e., what the symbolic link points to) by the runtime michael@0: ## linker. For example, if dist/bin/libxul.so is a symbolic link to michael@0: ## toolkit/library/libxul.so, $ORIGIN will be "toolkit/library" instead of "dist/bin". michael@0: ## So the runtime linker will use "toolkit/library" NOT "dist/bin" to locate the michael@0: ## other shared libraries that libxul.so depends on. This only happens michael@0: ## when a user (developer) tries to start firefox, thunderbird, or seamonkey michael@0: ## under dist/bin. To solve the problem, we should rely on LD_LIBRARY_PATH michael@0: ## to locate shared libraries. michael@0: ## michael@0: ## Note: michael@0: ## We test $MOZ_DIST_BIN/*.so. If any of them is a symbolic link, michael@0: ## we need to set LD_LIBRARY_PATH. michael@0: ########################################################################## michael@0: moz_should_set_ld_library_path() michael@0: { michael@0: [ `uname -s` != "SunOS" ] && return 0 michael@0: for sharedlib in $MOZ_DIST_BIN/*.so michael@0: do michael@0: [ -h $sharedlib ] && return 0 michael@0: done michael@0: return 1 michael@0: } michael@0: if moz_should_set_ld_library_path michael@0: then michael@0: LD_LIBRARY_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARY_PATH:+":$LD_LIBRARY_PATH"} michael@0: fi michael@0: michael@0: if [ -n "$LD_LIBRARYN32_PATH" ] michael@0: then michael@0: LD_LIBRARYN32_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARYN32_PATH:+":$LD_LIBRARYN32_PATH"} michael@0: fi michael@0: if [ -n "$LD_LIBRARYN64_PATH" ] michael@0: then michael@0: LD_LIBRARYN64_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARYN64_PATH:+":$LD_LIBRARYN64_PATH"} michael@0: fi michael@0: if [ -n "$LD_LIBRARY_PATH_64" ]; then michael@0: LD_LIBRARY_PATH_64=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARY_PATH_64:+":$LD_LIBRARY_PATH_64"} michael@0: fi michael@0: # michael@0: # michael@0: ## Set SHLIB_PATH for HPUX michael@0: SHLIB_PATH=${MOZ_DIST_BIN}:${MRE_HOME}${SHLIB_PATH:+":$SHLIB_PATH"} michael@0: # michael@0: ## Set LIBPATH for AIX michael@0: LIBPATH=${MOZ_DIST_BIN}:${MRE_HOME}${LIBPATH:+":$LIBPATH"} michael@0: # michael@0: ## Set DYLD_LIBRARY_PATH for Mac OS X (Darwin) michael@0: DYLD_LIBRARY_PATH=${MOZ_DIST_BIN}:${MRE_HOME}${DYLD_LIBRARY_PATH:+":$DYLD_LIBRARY_PATH"} michael@0: # michael@0: ## Solaris Xserver(Xsun) tuning - use shared memory transport if available michael@0: if [ "$XSUNTRANSPORT" = "" ] michael@0: then michael@0: XSUNTRANSPORT="shmem" michael@0: XSUNSMESIZE="512" michael@0: export XSUNTRANSPORT XSUNSMESIZE michael@0: fi michael@0: michael@0: # Disable Gnome crash dialog michael@0: GNOME_DISABLE_CRASH_DIALOG=1 michael@0: export GNOME_DISABLE_CRASH_DIALOG michael@0: michael@0: if [ "$moz_debug" -eq 1 ] michael@0: then michael@0: echo "MOZILLA_FIVE_HOME=$MOZILLA_FIVE_HOME" michael@0: echo " LD_LIBRARY_PATH=$LD_LIBRARY_PATH" michael@0: if [ -n "$LD_LIBRARYN32_PATH" ] michael@0: then michael@0: echo "LD_LIBRARYN32_PATH=$LD_LIBRARYN32_PATH" michael@0: fi michael@0: if [ -n "$LD_LIBRARYN64_PATH" ] michael@0: then michael@0: echo "LD_LIBRARYN64_PATH=$LD_LIBRARYN64_PATH" michael@0: fi michael@0: if [ -n "$LD_LIBRARY_PATH_64" ]; then michael@0: echo "LD_LIBRARY_PATH_64=$LD_LIBRARY_PATH_64" michael@0: fi michael@0: if [ -n "$DISPLAY" ]; then michael@0: echo "DISPLAY=$DISPLAY" michael@0: fi michael@0: if [ -n "$FONTCONFIG_PATH" ]; then michael@0: echo "FONTCONFIG_PATH=$FONTCONFIG_PATH" michael@0: fi michael@0: if [ -n "$MOZILLA_POSTSCRIPT_PRINTER_LIST" ]; then michael@0: echo "MOZILLA_POSTSCRIPT_PRINTER_LIST=$MOZILLA_POSTSCRIPT_PRINTER_LIST" michael@0: fi michael@0: echo "DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH" michael@0: echo " LIBRARY_PATH=$LIBRARY_PATH" michael@0: echo " SHLIB_PATH=$SHLIB_PATH" michael@0: echo " LIBPATH=$LIBPATH" michael@0: echo " ADDON_PATH=$ADDON_PATH" michael@0: echo " MOZ_PROGRAM=$MOZ_PROGRAM" michael@0: echo " MOZ_TOOLKIT=$MOZ_TOOLKIT" michael@0: echo " moz_debug=$moz_debug" michael@0: echo " moz_debugger=$moz_debugger" michael@0: echo "moz_debugger_args=$moz_debugger_args" michael@0: fi michael@0: # michael@0: export MOZILLA_FIVE_HOME LD_LIBRARY_PATH michael@0: export SHLIB_PATH LIBPATH LIBRARY_PATH ADDON_PATH DYLD_LIBRARY_PATH michael@0: michael@0: if [ $moz_debug -eq 1 ] michael@0: then michael@0: moz_debug_program ${1+"$@"} michael@0: else michael@0: moz_run_program ${1+"$@"} michael@0: fi michael@0: michael@0: exit $exitcode