run-mozilla.sh 8.7 KB

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