3 # Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 # Copyright (C) INRIA - 2006-2008 - Sylvestre Ledru
5 # Copyright (C) INRIA - 2008 - Simon Lipp
6 # Copyright (C) DIGITEO - 2009 - Sylvestre Ledru
7 # This file must be used under the terms of the CeCILL.
8 # This source file is licensed as described in the file COPYING, which
9 # you should have received as part of this distribution. The terms
10 # are also available at
11 # http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
14 # - clean up (get rid of unnecessary sci_args)
15 # - accept arguments with spaces, e.g.
16 # -e "disp(1); disp(2)" (fix bug #2606)
20 # Scilab can be installed/used in different ways :
21 # * ./configure; make install
22 # => will install Scilab into /usr/local/ and split files to
23 # /usr/local/bin, /usr/local/share/scilab/, /usr/local/lib/scilab/,
24 # /usr/local/include/scilab/
25 # * ./configure --prefix=/my/dir/; make install
26 # => will install Scilab into /my/dir/ and split files to
27 # /my/dir/bin/, /my/dir/share/scilab/, /my/dir/lib/scilab/
28 # /my/dir/include/scilab/
29 # Scilab official binary uses this arch
30 # * ./configure; make install prefix=$(DESTDIR)/usr \
31 # bindir=$(DESTDIR)/usr/bin \
32 # datadir=$(DESTDIR)/usr/share/scilab ...
33 # Solution used mainly by Linux packagers
35 ## First, this script will look for scilab-bin in :
36 # * If specified, in the $SCI variable
37 # * Into the scilab/bin/ directory
38 # * Into the scilab/ directory (if the user is using a source version and
39 # scilab has been compiled in this directory)
40 # * if this file is a symlink to the real one. We browse symlink(s) until we
41 # find the real "scilab" script file and consider that it is the right
43 # * That is all. Don't hesitate to contact us if you see one missing.
47 if test ! -z "$SCIVERBOSE"; then
53 if test -n "$SCI"; then
54 if test ! -d "$SCI/modules"; then
55 echo "Cannot find directory $SCI/modules/ !"
56 echo "SCI should point to the root data directory of Scilab"
61 DISABLE_JAVA_DETECTION=0
63 # Electric fence is a tool to check problem of memory
64 start_electric_fence() {
65 echo "Running Scilab with Electric Fence : " LD_PRELOAD=libefence.so.0.0 "$SCILABBIN" "$@"
66 LD_PRELOAD=libefence.so.0.0 "$SCILABBIN" "$@"
70 if test -n "$DEVENV"; then
71 echo "Running debug of Scilab [gdb] : " "$SCI"/libtool --mode=execute gdb --args "$SCILABBIN" "$@"
72 "$SCI"/libtool --mode=execute gdb --args "$SCILABBIN" "$@"
74 echo "Running debug of Scilab [gdb] : " gdb --args "$SCILABBIN" "$@"
75 gdb --args "$SCILABBIN" "$@"
80 if test -n "$DEVENV"; then
81 echo "Running debug of Scilab [kdbg] : " "$SCI"/libtool --mode=execute kdbg "$SCILABBIN"
82 "$SCI"/libtool --mode=execute kdbg "$SCILABBIN"
84 echo "Running debug of Scilab [kdbg] : " kdbg "$SCILABBIN"
90 VALGRIND_OPTIONS=" --show-below-main=yes --num-callers=6 --demangle=no --leak-check=full --show-reachable=yes --smc-check=all --db-attach=yes --gen-suppressions=all --suppressions=$SCI/tools/profiling/valgrind.supp"
91 if test -n "$DEVENV"; then
92 echo "Running profiling of Scilab : " "$SCI"/libtool --mode=execute valgrind $VALGRIND_OPTIONS "$SCILABBIN" "$@"
93 "$SCI"/libtool --mode=execute valgrind $VALGRIND_OPTIONS "$SCILABBIN" "$@"
95 echo "Running profiling of Scilab : " valgrind $VALGRIND_OPTIONS "$SCILABBIN" "$@"
96 valgrind $VALGRIND_OPTIONS "$SCILABBIN" "$@"
101 start_profiling_visu() {
102 VALGRIND_VISU_OPTIONS=" --tool=callgrind --trace-children=yes --smc-check=all --trace-jump=yes --dump-line=yes --separate-threads=yes"
104 if test -n "$DEVENV"; then
105 echo "Running profiling visualization of Scilab : " "$SCI"/libtool --mode=execute valgrind $VALGRIND_VISU_OPTIONS "$SCILABBIN" "$@"
106 "$SCI"/libtool --mode=execute valgrind $VALGRIND_VISU_OPTIONS "$SCILABBIN" "$@"
108 echo "Running profiling visualization of Scilab : " valgrind $VALGRIND_VISU_OPTIONS "$SCILABBIN" "$@"
109 valgrind $VALGRIND_VISU_OPTIONS "$SCILABBIN" "$@"
113 find_docbook_path() {
114 if test -z "$DOCBOOK_ROOT"; then
115 for dir in $SCI/thirdparty/docbook /usr/share/sgml/docbook/stylesheet/xsl/nwalsh /usr/share/docbook2X/xslt/man/ /usr/share/xml/docbook/stylesheet/nwalsh/ /usr/share/xml/docbook/stylesheet/nwalsh/current/ /sw/share/xml/xsl/docbook-xsl /usr/share/xml/docbook/xsl-stylesheets-*/ /usr/share/sgml/docbook/xsl-stylesheets-*/; do
116 if test -r "$dir/javahelp/javahelp.xsl"; then
117 if test -z "$DOCBOOK_ROOT"; then
124 if test $SCIVERBOSE -ne 0; then
125 echo "DOCBOOK : $DOCBOOK_ROOT"
129 detect_type_of_scilab(){
132 SCILABBIN="scilab-bin"
133 if echo "$progname"|grep "scilab-adv-cli$" 2>&1 > /dev/null; then
135 # We are using scilab-bin here because we are going to force the arg -nw
136 SCILABBIN="scilab-bin"
139 if echo "$progname"|grep "scilab-cli$" 2>&1 > /dev/null; then
141 SCILABBIN="scilab-cli-bin"
142 DISABLE_JAVA_DETECTION=1
144 if test $SCIVERBOSE -ne 0; then
145 echo "SCILABBIN : $SCILABBIN"
146 echo "DISABLE_JAVA_DETECTION : $DISABLE_JAVA_DETECTION"
147 echo "SCILAB_MODE : $SCILAB_MODE"
151 detect_type_of_scilab
153 detect_scilab_path() {
157 # Use scilab-bin in the current dir if it exists
158 # If not, then start resolving symlinks until we find scilab-bin
161 curdir=`dirname "$progname"`
164 progbase=`basename "$progname"`
165 run_sci="$curdir/$SCILABBIN"
166 if test -x "$run_sci"; then # scilab-bin is in the /bin/ directory
172 run_sci="$curdir/../$SCILABBIN"
173 if test -x "$run_sci"; then # scilab-bin is in the / directory
174 # which is the case in a dev env
181 while test -h "$progname"; do
182 bn=`basename "$progname"`
183 cd `dirname "$progname"`
184 # Browse the symlink to the real one
185 progname=`/bin/ls -l "$bn" | sed -e 's/^.* -> //' `
186 if test ! -x "$progname"; then
189 curdir=`dirname "$progname"`
190 if test -x "$curdir"; then
193 SCIBIN="$curdir/$SCILABBIN"
197 # The current file ($0), probably scilab is a symlink to the
198 # real one and here, it is the dev env
199 run_sci="$curdir/../$SCILABBIN"
200 if test -x "$run_sci"; then
210 if test $SCIVERBOSE -ne 0; then
211 echo "I think I found Scilab here : $SCI"
216 if test -x "$SCI/bin/$SCILABBIN"; then
218 SCILABBIN=$SCI/bin/$SCILABBIN
219 SCI=$SCI/share/scilab/
221 if test -x "$SCI/$SCILABBIN"; then
223 SCILABBIN=$SCI/$SCILABBIN
225 # add modelica in the path
226 PATH="$PATH:$SCI/modules/scicos/"
228 echo "Cannot find $SCILABBIN ..."
237 ############# JAVA DETECTION ##############
238 # Basic inspiration from Eclipse
240 # Scilab is looking for Java in various places with different ways :
241 # * if JAVA_HOME is specificed, use it
242 # * Check in 'standard' places we know Java could be installed
243 # if some are missing, please contact us
244 # * look in the PATH if there is a java binary
245 # if it is the case, resolve the symlink and set the JAVA_HOME from it
247 # Once we have JAVA_HOME, we check that native libraries (libjava.so and
248 # 2 others) are available
251 if test "${OS}" = ""; then
252 OS=`uname -s` # Retrieve the Operating System
254 if test "${MODEL}" = ""; then
255 MODEL=`uname -m` # Retrieve the model
258 # Get the proc name matching to the one of the JVM
259 # Inspiration and data are from http://www.google.com/codesearch?hl=en&q=+java+ppc+libjava.so+show:a78sz0SP41k:zxNozD-vc0A:FWiIy7Hinmg&sa=N&cd=2&ct=rc&cs_p=http://fresh.t-systems-sfr.com/unix/src/misc/tclBlendSrc1.2.5.tar.gz&cs_f=tclBlend1.2.5/configure.in#a0
260 # For Mac OS X, we will get stuff like that:
261 # uname -s Power Macintosh
264 # If the user has the variable JAVA_HOME in the ENV
265 if test -n "$JAVA_HOME" ; then
266 if test $SCIVERBOSE -ne 0; then
267 echo "Using specified vm: $JAVA_HOME"
269 if test ! -x "$JAVA_HOME/bin/java" ; then
270 echo "Cannot find $JAVA_HOME/bin/java"
275 if test -z "$JAVA_HOME"; then
278 # Seems to be always that under Mac OS X. Don't hesitate to submit a bug report if it is not the case.
279 JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Home/"
280 LD_LIBRARY_PATH="$JAVA_HOME/../Libraries:$LD_LIBRARY_PATH"
281 if test $SCIVERBOSE -ne 0; then
282 echo "Using default Mac OS X vm: $JAVA_HOME"
283 echo "And LD_LIBRARY_PATH: $LD_LIBRARY_PATH"
291 # Browse "default directory" (if it means anything under Unix/Linux) of Java
292 # to find where it could be !
293 if test -z "$JAVA_HOME"; then
294 JAVA_DEFAULT_DIR="/usr/lib/jvm/java-6-openjdk/ /usr/lib/jvm/java/ /usr/lib/jvm/java-6-sun/ /usr/lib/j2se/1.6 /usr/java/jdk1.6.0*/ /usr/java/jdk1.5.0*/ /usr/lib/j2sdk1.6-ibm /usr/lib/jvm/java-1.5.0-sun /usr/java/ /usr/lib/j2se/1.5 /usr/lib/j2se/1.4 /usr/java/jre1.6.0*/ /usr/java/jre1.5.0*/ /usr/lib/j2sdk1.5-ibm /usr/lib/j2sdk1.4-ibm /usr/lib/j2sdk1.5-sun /usr/lib/j2sdk1.4-sun /usr/lib/jvm/java-gcj /usr/lib/jvm/java-1.5.0-gcj/ /usr/lib/kaffe/pthreads /usr/lib/jvm/java-1.7.0-icedtea-*/ /usr/lib/jvm/jre/"
295 for JAVA_HOME in $JAVA_DEFAULT_DIR ; do
296 if test $SCIVERBOSE -ne 0; then
297 echo "Trying to find Java in $JAVA_HOME "
299 if test -x "${JAVA_HOME}/bin/java" ; then
301 if test $SCIVERBOSE -ne 0; then
309 # JAVA_HOME still haven't been found. Well, we can now try to find it in the path
311 if test -z "$JAVA_HOME"; then
313 as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
314 if test $SCIVERBOSE -ne 0; then
315 echo "Look the binary java in the PATH. If it is a symlink, try to resolve it"
318 if test -f $DIR/java; then
322 # Will probably bug if a file contains -> in the name
323 while ls -ld "$_cur" 2>/dev/null | grep " -> " >/dev/null; do
324 _cur=`ls -ld "$_cur" | sed 's/.* -> //'`
326 # symlink resolved to the real file
328 # Now, create JAVA_HOME
330 JAVA_HOME=`dirname $TMP`
331 if test ! -z "$JAVA_HOME"; then
338 if test ! -z "$JAVA_HOME"; then
339 if test $SCIVERBOSE -ne 0; then
340 echo "JAVA_HOME : $JAVA_HOME"
343 # Manage JRE & JDK because libjava.so and others are stored in the JRE
344 if test -d $JAVA_HOME/jre; then
345 JRE_HOME=$JAVA_HOME/jre
350 # Configuring LD_LIBRARY_PATH for libjava.so libhpi.so and libxxxx.so
352 JAVA_SHLIB="libjava.so"
362 if test -d ${JRE_HOME}/lib/`uname -m` ; then
378 echo "Could not find the Java configuration for the model <${MODEL}>. Please contact us."
383 JAVA_SHLIB="libjava.sl"
384 proc="lib" # TODO : check if it is right or not ... seems not !
391 "i86pc") # solaris x86
394 # check for the 64 bits syntax
399 echo "Could not find the Java configuration for the model <${MODEL}>. Please contact us."
403 *win32* | *WIN32* | *CYGWIN_NT*)
407 *darwin* | *Darwin*) # MacOS X
408 # For Mac OS X, Since path are different from the JVM normal tree,
409 # don't need to detect the CPU
410 JAVA_SHLIB="libjava.jnilib"
413 echo "Could not find the Java configuration for the OS <${OS}>. Please contact us or submit a bug report with your detailed configuration http://bugzilla.scilab.org/"
418 # Check if the lib exists or not (we should manage system where .so is not the
420 LIBJAVA="$JRE_HOME/lib/$proc/$JAVA_SHLIB"
421 if test ! -f $LIBJAVA; then
422 if test $SCIVERBOSE -ne 0; then
423 echo "Cannot find $LIBJAVA"
426 CLASSPATH="$CLASSPATH:$SCI/modules/jvm/jar/org.scilab.modules.jvm.jar"
427 # @TODO This is the default path of the official sun JVM.
428 # It is different for other implementation of the JVM....
429 LD_LIBRARY_PATH="$JRE_HOME/lib/$proc/:$JRE_HOME/lib/$proc/server/:$JRE_HOME/lib/$proc/native_threads/:$LD_LIBRARY_PATH"
432 if test $SCIVERBOSE -ne 0; then
433 echo "Have not been able to find any Java VM on this computer. Some features may be broken."
437 ####### END OF JAVA ENV DETECTION/SETTING ######
442 PATH="$SCI:$SCI/bin:$PATH"
444 # If we are calling scilab-cli, no need to detect java.
445 if test $DISABLE_JAVA_DETECTION -ne 1; then
449 # See http://bugzilla.scilab.org/show_bug.cgi?id=3486
450 # Some Java stuff raises spurious SIGSEGV. The problem is that when bug-buddy
451 # is enabled, it catches the signal and terminate Scilab. We have to
452 # desactivate bug-buddy.
453 # See also https://bugzilla.novell.com/show_bug.cgi?id=331618
454 # and: http://bugzilla.gnome.org/show_bug.cgi?id=479929
455 GTK_MODULES=`echo $GTK_MODULES | sed s/gnomebreakpad//g`
458 if test $SCIVERBOSE -ne 0; then
460 echo "SCIBIN : $SCIBIN"
464 # Returns to the original path
467 #if test "$DISPLAY" = ""; then
472 #if test "$PVM_ROOT" = ""; then
473 # PVM_ROOT="@PVMROOTR@"
477 #if test "$PVM_ARCH" = ""; then
478 # PVM_ARCH=`$PVM_ROOT/lib/pvmgetarch`
482 SCILIB=$SCI/bin:$SCI/lib/scilab/:$SCI/lib64/scilab/
483 LD_LIBRARY_PATH=$SCILIB${LD_LIBRARY_PATH+:$LD_LIBRARY_PATH}
486 *darwin* | *Darwin*) # MacOS X
487 # When using some packaging tools like fink which are storing the info in /sw/lib
488 LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/sw/lib/"
489 # Export the path to the Scilab lib when Scilab has been install ...
490 # to a Mac os x specific variable used by the linker before LD_LIBRARY_PATH
491 DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$SCI/../../lib/scilab/
492 export DYLD_LIBRARY_PATH
498 if test $SCIVERBOSE -ne 0; then
499 echo "LD_LIBRARY_PATH : $LD_LIBRARY_PATH"
500 if test ! -z "$DYLD_LIBRARY_PATH"; then
501 echo "DYLD_LIBRARY_PATH: $DYLD_LIBRARY_PATH"
504 export LD_LIBRARY_PATH
518 echo "scilab <options>"
520 echo " Possible options are:"
521 echo " -display Display: for use under Xwindow systems to set a specific X server display."
522 echo " -d Display : equivalent to display Display."
523 echo " -debug : Start Scilab under gdb (Unix/linux only)."
524 echo " -debug-kdbg : Start Scilab under kdbg (Unix/linux only)."
525 echo " -profiling : Start Scilab under valgrind (Unix/linux only)."
526 echo " -profiling-visu : Start Scilab under callgrind (Unix/linux only)."
527 echo " -electric-fence : Start Scilab with the Electric Fence (Unix/linux only)."
528 echo " -e Instruction : execute the scilab instruction given in Instruction argument."
529 echo " -e and -f options are mutually exclusive."
530 echo " -f File : execute the scilab script given in File argument."
531 echo " -e and -f options are mutually exclusive."
532 echo " -l Lang : set the current language. Lang can be equal to fr or en."
533 echo " -mem N : set the initial stacksize, for use with -ns option."
534 echo " -nb : do not display the Scilab banner at starting time."
535 echo " -ns : do not execute scilab.start startup file."
536 echo " -nouserstartup : do not execute the user startup files SCIHOME/.scilab or SCIHOME/scilab.ini."
537 echo " -nw : start Scilab without specialized Scilab Window."
538 echo " -nwni : start Scilab without the GUI, graphic and help features (batch mode). This option disables the need of Java."
539 echo " -nogui : start Scilab without user GUI (batch mode)."
540 echo " -version : print product version and exit."
541 echo " --texmacs : reserved for TeXMacs."
543 echo " All these arguments can be retrieved by the Scilab function sciargs."
552 name=`basename $1 .sci`
553 echo generating $name.bin
554 echo "predef();getf('$name.sci');save('$name.bin');quit"\
555 | $SCILABBIN -ns -nwni | sed 1,8d 1>report 2>&1
556 if (grep error report 1> /dev/null 2>&1);
557 then cat report;echo " "
558 echo see `pwd`/report for more informations
559 grep libok report>/dev/null;
570 echo "$1=lib('$2/');save('$2/lib',$1);quit"\
571 | $SCILABBIN -ns -nwni |sed 1,/--\>/d 1>report 2>&1
572 if (grep error report 1> /dev/null 2>&1);
573 then cat report;echo " "
574 echo see `pwd`/report for more informations
575 grep libok report>/dev/null;
583 if test "$SCILAB_MODE" = "nw"; then
587 # calling Scilab with no argument or special cases of calling Scilab
590 0) # No arg, run Scilab
622 # really calling Scilab with arguments
624 if test "$rest" = "yes"; then
635 # If the previous argument needs an argument, skip current one.
636 if test -n "$prevarg"; then
642 -nogui|-version|-ns|-nb|-nw|-nouserstartup|--texmacs|-nwni)
645 # Under Mac OS X, .app is adding the arg -psn_0_xxxx
646 # (psn = ProcessSerialNumber). It is not used (but could be in the future)
648 -display|-f|-l|-e|-d|-args|-mem)
655 DEBUG_KDBG="-debug-kdbg"
658 PROFILING="-profiling"
661 PROFILING_VISU="-profiling-visu"
664 ELECTRIC_FENCE="-electric-fence"
672 if test -n "$DEBUG"; then
673 start_debug "$@" $MORE_OPT
675 if test -n "$DEBUG_KDBG"; then
676 start_debug_kdbg "$@" $MORE_OPT
678 if test -n "$PROFILING"; then
679 start_profiling "$@" $MORE_OPT
681 if test -n "$PROFILING_VISU"; then
682 start_profiling_visu "$@" $MORE_OPT
684 if test -n "$ELECTRIC_FENCE"; then
685 start_electric_fence "$@" $MORE_OPT
687 do_scilex "$@" $MORE_OPT
688 fi # not electric fense
689 fi # not profiling visu