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