Fix variable name + prepare for new TCL/TK path in binary versions
[scilab.git] / scilab / bin / scilab
1 #!/bin/sh
2 #
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-2011 - Sylvestre Ledru
7 # Copyright (C) DIGITEO - 2010-2011 - Bruno JOFRET
8 # This file must be used under the terms of the CeCILL.
9 # This source file is licensed as described in the file COPYING, which
10 # you should have received as part of this distribution.  The terms
11 # are also available at
12 # http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
13
14 ####
15 #
16 # Scilab can be installed/used in different ways :
17 # * ./configure; make install
18 #    => will install Scilab into /usr/local/ and split files to
19 #    /usr/local/bin, /usr/local/share/scilab/, /usr/local/lib/scilab/,
20 #    /usr/local/include/scilab/
21 # * ./configure --prefix=/my/dir/; make install
22 #    => will install Scilab into /my/dir/ and split files to
23 #    /my/dir/bin/, /my/dir/share/scilab/, /my/dir/lib/scilab/
24 #    /my/dir/include/scilab/
25 #    Scilab official binary uses this arch
26 # * ./configure; make install prefix=$(DESTDIR)/usr \
27 #                   bindir=$(DESTDIR)/usr/bin \
28 #                   datadir=$(DESTDIR)/usr/share/scilab ...
29 #    Solution used mainly by Linux packagers
30 #
31 ## First, this script will look for scilab-bin in :
32 # * If specified, in the $SCI variable
33 # * Into the scilab/bin/ directory
34 # * Into the scilab/ directory (if the user is using a source version and
35 # scilab has been compiled in this directory)
36 # * if this file is a symlink to the real one. We browse symlink(s) until we
37 # find the real "scilab" script file and consider that it is the right
38 # directory
39 # * That is all. Don't hesitate to contact us if you see one missing.
40 #
41 ###
42
43 if test ! -z "$SCIVERBOSE"; then
44     SCIVERBOSE=1
45 else
46     SCIVERBOSE=0
47 fi
48
49 if test -n "$SCI"; then
50     if test ! -d "$SCI/modules"; then
51         echo "Cannot find directory $SCI/modules/ !"
52         echo "SCI should point to the root data directory of Scilab"
53         exit -1
54     fi
55 fi
56
57 DISABLE_JAVA_DETECTION=0
58 IS_SCILAB_BINARY=0
59
60 start_debug() {
61     if test -n "$DEVENV"; then
62         echo "Running debug of Scilab [gdb]  : " "$SCI"/libtool --mode=execute gdb $SCILAB_GDB_OPT --args "$SCILABBIN" "$@"
63         "$SCI"/libtool --mode=execute gdb $SCILAB_GDB_OPT --args "$SCILABBIN" "$@"
64     else
65         echo "Running debug of Scilab [gdb]  : " gdb $SCILAB_GDB_OPT --args "$SCILABBIN" "$@"
66         gdb $SCILAB_GDB_OPT --args "$SCILABBIN" "$@"
67     fi
68 }
69
70 start_debug_kdbg() {
71     if test -n "$DEVENV"; then
72         echo "Running debug of Scilab [kdbg]  : " "$SCI"/libtool --mode=execute kdbg "$SCILABBIN"
73         "$SCI"/libtool --mode=execute kdbg "$SCILABBIN"
74     else
75         echo "Running debug of Scilab [kdbg]  : " kdbg "$SCILABBIN"
76         kdbg "$SCILABBIN"
77     fi
78 }
79
80 start_profiling() {
81     VALGRIND_OPTIONS=" --show-below-main=yes --num-callers=12 --demangle=yes --leak-check=full --show-reachable=yes --smc-check=all --db-attach=yes --gen-suppressions=all --show-below-main=yes --track-origins=yes --suppressions=$SCI/tools/profiling/valgrind.supp $SCILAB_VALGRIND_OPT"
82     if test -n "$DEVENV"; then
83         echo "Running profiling of Scilab  : " "$SCI"/libtool --mode=execute valgrind $VALGRIND_OPTIONS "$SCILABBIN" "$@"
84         "$SCI"/libtool --mode=execute valgrind $VALGRIND_OPTIONS "$SCILABBIN" "$@"
85     else
86         echo "Running profiling of Scilab  : " valgrind $VALGRIND_OPTIONS "$SCILABBIN" "$@"
87         valgrind $VALGRIND_OPTIONS "$SCILABBIN" "$@"
88     fi
89
90 }
91
92 start_profiling_visu() {
93     VALGRIND_VISU_OPTIONS=" --tool=callgrind --trace-children=yes --smc-check=all --trace-jump=yes --dump-line=yes --separate-threads=yes $SCILAB_VALGRIND_OPT"
94 #--dump-instr=yes
95     if test -n "$DEVENV"; then
96         echo "Running profiling visualization of Scilab  : " "$SCI"/libtool --mode=execute valgrind $VALGRIND_VISU_OPTIONS "$SCILABBIN" "$@"
97         "$SCI"/libtool --mode=execute valgrind $VALGRIND_VISU_OPTIONS "$SCILABBIN" "$@"
98     else
99         echo "Running profiling visualization of Scilab  : " valgrind $VALGRIND_VISU_OPTIONS "$SCILABBIN" "$@"
100         valgrind $VALGRIND_VISU_OPTIONS "$SCILABBIN" "$@"
101     fi
102 }
103
104 find_docbook_path() {
105     if test -z "$DOCBOOK_ROOT"; then
106         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-*/ /usr/share/sgml/docbook/xsl-stylesheets /usr/share/sgml/docbook/xsl-ns-stylesheets-*/ /usr/share/xml/docbook/stylesheet/docbook-xsl /opt/local/share/xsl/docbook-xsl; do
107             if test -r "$dir/fo/docbook.xsl"; then
108                 if test -z "$DOCBOOK_ROOT"; then
109                     DOCBOOK_ROOT=$dir
110                     export DOCBOOK_ROOT
111                 fi
112             fi
113         done
114     fi
115     if test $SCIVERBOSE -ne 0; then
116         echo "DOCBOOK : $DOCBOOK_ROOT"
117     fi
118 }
119
120 detect_type_of_scilab(){
121
122     progname="$0"
123     SCILAB_MODE="gui"
124     SCILABBIN="scilab-bin"
125
126     if (echo "$progname"|grep "scilab-adv-cli$" 2>&1 > /dev/null;) || (echo "$@"|grep "\-nw" 2>&1 > /dev/null;) then
127         SCILAB_MODE="nw"
128         # We are using scilab-bin here because we are going to force the arg -nw
129         SCILABBIN="scilab-bin"
130     fi
131
132     if (echo "$progname"|grep "scilab-cli$" 2>&1 > /dev/null;) || (echo "$@"|grep "\-nwni" 2>&1 > /dev/null;) then
133         SCILAB_MODE="nwni"
134         SCILABBIN="scilab-cli-bin"
135         DISABLE_JAVA_DETECTION=1
136     fi
137
138     if (echo "$progname"|grep "scinotes$" 2>&1 > /dev/null;) then
139         SCILAB_MODE="scinotes"
140         SCILABBIN="scilab-bin"
141         extraarg=1
142     fi
143
144     if (echo "$progname"|grep "xcos$" 2>&1 > /dev/null;) then
145         SCILAB_MODE="xcos"
146         SCILABBIN="scilab-bin"
147         extraarg=1
148     fi
149
150     if test $SCIVERBOSE -ne 0; then
151         echo "SCILABBIN : $SCILABBIN"
152         echo "DISABLE_JAVA_DETECTION : $DISABLE_JAVA_DETECTION"
153         echo "SCILAB_MODE : $SCILAB_MODE"
154     fi
155 }
156
157 detect_os() {
158
159     if test "${OS}" = ""; then
160         OS=$(uname -s) # Retrieve the Operating System
161     fi
162     if test "${MODEL}" = ""; then
163         MODEL=$(uname -m) # Retrieve the model
164     fi
165
166     if test $SCIVERBOSE -ne 0; then
167         echo "OS : $OS"
168         echo "MODEL : $MODEL"
169     fi
170 }
171
172 detect_type_of_scilab $@
173
174 detect_os
175
176 detect_scilab_path() {
177
178     LOCALOLDPWD=$(pwd)
179
180     # If we are running Scilab binary, it is trivial to set paths.
181     curdir=$(dirname "$progname")
182
183     # If the script is a symlink, it might be a symlink to the Scilab binary
184     # We could run into the bug #9125
185     if test -h $progname; then
186         while test -h "$progname"; do
187             bn=$(basename "$progname")
188             cd $(dirname "$progname")
189
190             # Browse the symlink to the real one
191             progname=$(/bin/ls -l "$bn" | sed -e 's/^.* -> //' )
192
193             if test ! -x "$progname"; then
194                 break
195             fi
196         done
197         cd $(dirname "$progname")
198         curdir=$(pwd)
199     fi
200
201     if test -d $curdir/../thirdparty/ -a -d $curdir/../share/scilab; then
202         # We are in the Scilab binary
203         IS_SCILAB_BINARY=1
204         # export the bin directory to the PATH first (avoid to take the packaged version)
205         PATH="$curdir:$PATH"
206         cd "$curdir/../"
207         SCIBINARYBASE=$(pwd)
208         SCI=$SCIBINARYBASE/share/scilab
209         export SCI
210         return
211     fi
212
213     # Use scilab-bin in the current dir if it exists
214     # If not, then start resolving symlinks until we find scilab-bin
215     found=0
216     cd $(dirname "$progname")
217     curdir=$(pwd -P)
218     PATH="$curdir:$PATH"
219
220     progbase=$(basename "$progname")
221     run_sci="$curdir/$SCILABBIN"
222     if test -x "$run_sci"; then # scilab-bin is in the /bin/ directory
223         cd "$curdir/../"
224         SCI=$(pwd)
225         SCIBIN=$run_sci
226         found=1
227     else
228         run_sci="$curdir/../$SCILABBIN"
229         if test -x "$run_sci"; then # scilab-bin is in the / directory
230         # which is the case in a dev env
231             cd "$curdir/../"
232             SCI=$(pwd)
233             SCIBIN=$run_sci
234             found=1
235         else
236             here=$(/bin/pwd)
237             while test -h "$progname"; do
238                 bn=$(basename "$progname")
239                 cd $(dirname "$progname")
240             # Browse the symlink to the real one
241                 progname=$(/bin/ls -l "$bn" | sed -e 's/^.* -> //' )
242                 if test ! -x "$progname"; then
243                     break
244                 fi
245                 curdir=$(dirname "$progname")
246                 if test -x "$curdir"; then
247                     cd "$curdir/../"
248                     SCI=$(pwd)
249                     SCIBIN="$curdir/$SCILABBIN"
250                     found=1
251
252                     break
253                 fi
254             # The current file ($0), probably scilab is a symlink to the
255             # real one and here, it is the dev env
256                 run_sci="$curdir/../$SCILABBIN"
257                 if test -x "$run_sci"; then
258                     cd "$curdir/../"
259                     SCI=$(pwd)
260                     SCIBIN=$run_sci
261                     found=1
262                     break
263                 fi
264             done
265             cd "$here"
266         fi
267         if test $SCIVERBOSE -ne 0; then
268             echo "I think I found Scilab here : $SCI"
269         fi
270     fi
271
272
273     if test -x "$SCI/bin/$SCILABBIN"; then
274 # real env
275         SCILABBIN=$SCI/bin/$SCILABBIN
276         SCI=$SCI/share/scilab/
277     else
278         if test -x "$SCI/$SCILABBIN"; then
279         # dev env
280             SCILABBIN=$SCI/$SCILABBIN
281             DEVENV=1
282         # add modelica in the path
283             PATH="$PATH:$SCI/modules/scicos/"
284         else
285             echo "Cannot find $SCILABBIN ..."
286             exit 1
287         fi
288     fi
289
290     export SCI
291 }
292
293
294 set_macosx_java_vm () {
295     # For Mac OS X, Since path are different from the JVM normal tree,
296     # don't need to detect the CPU
297     JAVA_SHLIB="libjava.jnilib"
298     if test -z "$JAVA_HOME"; then
299       JAVA_HOME=$(/usr/libexec/java_home --arch x86_64 --failfast --version 1.6+)
300     fi
301     DYLD_LIBRARY_PATH="$JAVA_HOME/../Libraries${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}"
302
303 }
304
305 set_embedded_java_vm () {
306
307        # Scilab binary => no Java detection since we are using the embeded JRE
308         # Here, we are handling 3 cases: GNU/Linux 32bit, GNU/Linux 64bit,
309         # Mac OS X
310         case $OS in
311             "Linux")
312                 case $MODEL in
313                     "x86_64")
314                         proc="amd64"
315                         ;;
316                     i?86)
317                         # We embed java/lib/i386 with Scilab Binary
318                         # force proc to i386 even if systems answer i686
319                         proc="i386"
320                         ;;
321                     *)
322                         echo "Could not find the Java configuration for the model <${MODEL}>. Please contact us on http://bugzilla.scilab.org"
323                         ;;
324                 esac
325                 ;;
326             *darwin* | *Darwin*) # MacOS X
327                 set_macosx_java_vm
328                 ;;
329             *)
330             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/"
331             echo "Fallback on the model <${MODEL}> found by uname -m"
332             proc=$MODEL
333             ;;
334     esac
335     JRE_HOME="$SCIBINARYBASE/thirdparty/java/"
336
337 }
338
339 # If enabled, disable se_linux
340 check_and_disable_selinux() {
341     if test -x /usr/sbin/selinuxenabled -a $IS_SCILAB_BINARY -eq 1; then
342         /usr/sbin/selinuxenabled
343         if test $? = 0; then
344             if test $SCIVERBOSE -ne 0; then
345                 echo "Disabling SELinux on Scilab"
346             fi
347
348             JVMLIB_32=$SCIBINARYBASE/java/lib/i386/server/libjvm.so
349             if test -f $JVMLIB_32; then
350                 /usr/bin/chcon -t textrel_shlib_t "$JVMLIB_32"
351                 if test $? != 0; then
352                     echo "Error: Cannot chcon $JVMLIB_32"
353                 fi
354             fi
355             JVMLIB_64=$SCIBINARYBASE/java/lib/amd64/server/libjvm.so
356             if test -f $JVMLIB_64; then
357                 /usr/bin/chcon -t textrel_shlib_t "$JVMLIB_64"
358                 if test $? != 0; then
359                     echo "Error: Cannot chcon $JVMLIB_64"
360                 fi
361             fi
362             /usr/bin/chcon -t execmem_exec_t "$SCIBINARYBASE/bin/scilab-bin"
363             if test $? != 0; then
364                 echo "Error: Cannot chcon 'scilab-bin'"
365             fi
366
367             /usr/bin/chcon -t execmem_exec_t "$SCIBINARYBASE/bin/scilab-cli-bin"
368             if test $? != 0; then
369                 echo "Error: Cannot chcon 'scilab-cli-bin'"
370             fi
371
372         fi
373     fi
374 }
375
376 detect_java_vm() {
377
378     JAVA_SHLIB="libjava.so"
379
380     if test $IS_SCILAB_BINARY -eq 1; then
381         set_embedded_java_vm
382     else  # NOT IS_SCILAB_BINARY
383
384 ############# JAVA DETECTION ##############
385 # Basic inspiration from Eclipse
386 #
387 # Scilab is looking for Java in various places with different ways :
388 # * if JAVA_HOME is specificed, use it
389 # * Check in 'standard' places we know Java could be installed
390 # if some are missing, please contact us
391 # * look in the PATH if there is a java binary
392 # if it is the case, resolve the symlink and set the JAVA_HOME from it
393 #
394 # Once we have JAVA_HOME, we check that native libraries (libjava.so and
395 # 2 others) are available
396 ###
397
398 # Get the proc name matching to the one of the JVM
399 # 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
400 # For Mac OS X, we will get stuff like that:
401 # uname -s Power Macintosh
402 # uname -m Darwin
403
404 # If the user has the variable JAVA_HOME in the ENV
405         if test -n "$JAVA_HOME" ; then
406                 if test $SCIVERBOSE -ne 0; then
407                     echo "Using specified vm: $JAVA_HOME"
408                 fi
409                 if test ! -x "$JAVA_HOME/bin/java" ; then
410                     echo "Cannot find $JAVA_HOME/bin/java"
411                     exit 1
412                 fi
413         else
414
415             case $OS in
416                 *darwin* | *Darwin*)
417                     set_macosx_java_vm
418                     if test $SCIVERBOSE -ne 0; then
419                         echo "Using default Mac OS X vm: $JAVA_HOME"
420                         echo "And LD_LIBRARY_PATH: $LD_LIBRARY_PATH"
421                         echo "And DYLD_LIBRARY_PATH: $DYLD_LIBRARY_PATH"
422                     fi
423                     ;;
424                 *)
425                     ;;
426             esac
427
428 # Browse "default directory" (if it means anything under Unix/Linux) of Java
429 # to find where it could be !
430             if test -z "$JAVA_HOME"; then
431                 JAVA_DEFAULT_DIR="/usr/lib/jvm/default-java /usr/lib/jvm/java-6-openjdk/ /usr/lib/jvm/java-7-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/ /usr/local/diablo-jdk1.6.0/"
432                 for DIR in $JAVA_DEFAULT_DIR ; do
433                     if test $SCIVERBOSE -ne 0; then
434                         echo "Trying to find Java in $DIR "
435                     fi
436                     if test -x "${DIR}/bin/java" ; then
437                         # resolve symlinked dir
438                         cd $DIR
439                         JAVA_HOME=$(pwd -P)
440                         cd $OLDPWD
441
442                         export JAVA_HOME
443                         if test $SCIVERBOSE -ne 0; then
444                             echo "Java found in $JAVA_HOME"
445                         fi
446                         break
447                     fi
448                 done
449             fi
450
451 # if JAVA_HOME still haven't been found. Well, we can now try to find it in the path
452             if test ! -d "$JAVA_HOME"; then
453
454                 PATH_SEPARATOR=:
455                 as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
456                 if test $SCIVERBOSE -ne 0; then
457                     echo "Look for the java binary in the PATH. If it is a symlink, try to resolve it"
458                 fi
459                 for DIR in $PATH; do
460                     if test -f $DIR/java; then
461
462                         _cur=$DIR/java
463                 # resolve symlink
464                 # Will probably bug if a file contains -> in the name
465                         while ls -ld "$_cur" 2>/dev/null | grep " -> " >/dev/null; do
466                             _cur=$(ls -ld "$_cur" | sed 's/.* -> //')
467                         done
468                 # symlink resolved to the real file
469
470                 # Now, create JAVA_HOME
471                         TMP=$(dirname $_cur)
472                         JAVA_HOME=$(dirname $TMP)
473                         if test ! -z "$JAVA_HOME"; then
474                             break;
475                         fi
476                     fi
477                 done
478                 IFS=$as_save_IFS
479             fi
480         fi
481         if test ! -z "$JAVA_HOME"; then
482             if test $SCIVERBOSE -ne 0; then
483                 echo "JAVA_HOME : $JAVA_HOME"
484             fi
485 # Manage JRE & JDK because libjava.so and others are stored in the JRE
486             if test -d $JAVA_HOME/jre; then
487                 JRE_HOME=$JAVA_HOME/jre
488             else
489                 JRE_HOME=$JAVA_HOME
490             fi
491 # Configuring LD_LIBRARY_PATH for libjava.so libhpi.so and libxxxx.so
492
493             case $OS in
494                 "Linux")
495                     case $MODEL in
496                         "x86_64")
497                             proc="amd64"
498                             ;;
499                         i?86)
500
501                             if test -d ${JRE_HOME}/lib/$(uname -m) ; then
502                                 proc=$(uname -m)
503                             else
504                                 proc="i386"
505                             fi
506                             ;;
507                         "alpha")
508                             proc="alpha"
509                             ;;
510                         "sparc"|"sparc64")
511                             proc="sparc"
512                             ;;
513                         sh*)
514                             proc="sh"
515                             ;;
516                         "ia64")
517                             proc="ia64"
518                             ;;
519                         mips*) # under mipsel, uname -m is
520                     # usually returning mips or mips64...
521                     # but binary are in mipsel
522                             if test -d ${JRE_HOME}/lib/mipsel ; then
523                                 proc="mipsel"
524                             else
525                                 proc="mips"
526                             fi
527                             ;;
528                         "ppc"|"powerpc"|"ppc64")
529                             proc="ppc"
530                             ;;
531                         "s390")
532                             proc="s390"
533                             ;;
534                         "s390x")
535                             proc="s390x"
536                             ;;
537                         armv*)
538                             proc="arm"
539                             ;;
540                         *)
541                             echo "Could not find the Java configuration for the model <${MODEL}>. Please contact us on http://bugzilla.scilab.org"
542                             ;;
543                     esac
544                     ;;
545                 "HP-UX")
546                     JAVA_SHLIB="libjava.sl"
547                     proc="lib" # TODO : check if it is right or not ... seems not !
548                     ;;
549                 "IRIX")
550                     proc="lib32"
551                     ;;
552                 "SunOS")
553                     case $MODEL in
554                         "i86pc") # solaris x86
555                             proc="i386"
556                             ;;
557                 # check for the 64 bits syntax
558                         "sparc"|"sparc64")
559                             proc="sparc"
560                             ;;
561                         *)
562                             echo "Could not find the Java configuration for the model <${MODEL}>. Please contact us."
563                             ;;
564                     esac
565                     ;;
566
567                 *win32* | *WIN32* | *CYGWIN_NT*)
568                     proc="win32"
569                     JAVA_SHLIB="jvm.dll"
570                     ;;
571                 *darwin* | *Darwin*) # MacOS X
572                     set_macosx_java_vm
573                     ;;
574                 *FreeBSD*)
575                     proc=$MODEL
576                     ;;
577                 *)
578                     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/"
579                     echo "Fallback on the model <${MODEL}> found by uname -m"
580                     proc=$MODEL
581                     ;;
582             esac
583         fi # JAVA_HOME provided or found
584     fi # IS_SCILAB_BINARY
585
586 # Check if the lib exists or not
587     LIBJAVA="$JRE_HOME/lib/$proc/$JAVA_SHLIB"
588     if test ! -f $LIBJAVA; then
589         if test $SCIVERBOSE -ne 0; then
590             echo "Cannot find $LIBJAVA"
591         fi
592     else
593         CLASSPATH="${CLASSPATH:+:$CLASSPATH}$SCI/modules/core/jar/org.scilab.modules.core.jar"
594         # @TODO This is the default path of the official sun JVM.
595         # It is different for other implementation of the JVM....
596         LD_LIBRARY_PATH="$JRE_HOME/lib/$proc/:$JRE_HOME/lib/$proc/server/:$JRE_HOME/lib/$proc/native_threads/${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
597     fi
598
599 ####### END OF JAVA ENV DETECTION/SETTING ######
600 }
601
602 detect_scilab_path
603 if test $SCIVERBOSE -ne 0; then
604     echo "IS_SCILAB_BINARY : $IS_SCILAB_BINARY"
605 fi
606
607
608 # If we are calling scilab-cli, no need to detect java.
609 if test $DISABLE_JAVA_DETECTION -ne 1; then
610     detect_java_vm
611 fi
612
613 if test $IS_SCILAB_BINARY -eq 1; then
614
615     if test ! -d "$SCIBINARYBASE/thirdparty/tcl8.5"; then
616         # New packaging path (similar to Windows one)
617         TCL_LIBRARY="$SCIBINARYBASE/share/scilab/modules/tclsci/tcl/tcl8.5"
618         TK_LIBRARY="$SCIBINARYBASE/share/scilab/modules/tclsci/tcl/tk8.5"
619     else
620         # Old packaging path
621         TCL_LIBRARY="$SCIBINARYBASE/thirdparty/tcl8.5"
622         TK_LIBRARY="$SCIBINARYBASE/thirdparty/tk8.5"
623     fi
624     LD_LIBRARY_PATH=$SCIBINARYBASE/lib/scilab:$SCIBINARYBASE/lib/thirdparty${LD_LIBRARY_PATH+:$LD_LIBRARY_PATH}
625     DOCBOOK_ROOT="$SCI/../../thirdparty/docbook"
626     PATH="$PATH:$SCI/modules/scicos/"
627
628     export DOCBOOK_ROOT
629     export PATH
630     export LD_LIBRARY_PATH
631     export TCL_LIBRARY
632     export TK_LIBRARY
633
634     case $OS in
635         *darwin* | *Darwin*)
636             DYLD_LIBRARY_PATH=$SCIBINARYBASE/lib/scilab:$SCIBINARYBASE/lib/thirdparty${DYLD_LIBRARY_PATH+:$DYLD_LIBRARY_PATH}
637             export DYLD_LIBRARY_PATH
638             PATH="/sw/bin:/sw64/bin:$PATH"
639             export PATH
640             ;;
641     esac
642
643 else
644     PATH="$SCI:$SCI/bin:$PATH"
645 fi
646
647
648 # See http://bugzilla.scilab.org/show_bug.cgi?id=3486
649 # Some Java stuff raises spurious SIGSEGV. The problem is that when bug-buddy
650 # is enabled, it catches the signal and terminate Scilab. We have to
651 # desactivate bug-buddy.
652 # See also https://bugzilla.novell.com/show_bug.cgi?id=331618
653 # and: http://bugzilla.gnome.org/show_bug.cgi?id=479929
654 GTK_MODULES=$(echo $GTK_MODULES | sed s/gnomebreakpad//g)
655 export GTK_MODULES
656
657 # libEGL may be partially supported by the closed-source NVIDIA driver.
658 # Until they release an EGL driver, we force the egl_glx driver.
659 # http://bugzilla.scilab.org/show_bug.cgi?id=12940
660 if test -x /usr/bin/glxinfo; then
661     NVIDIA_GLX_VENDOR=$(/usr/bin/glxinfo |grep "NVIDIA Corporation")
662     if test ! -z "$NVIDIA_GLX_VENDOR"; then
663         EGL_DRIVER=egl_glx
664         export EGL_DRIVER
665     fi
666 fi
667
668 if test $SCIVERBOSE -ne 0; then
669     echo "SCI : $SCI"
670     echo "SCIBIN : $SCIBIN"
671     echo "PATH : $PATH"
672     echo "CLASSPATH : $CLASSPATH"
673     echo "EGL_DRIVER : $EGL_DRIVER"
674 fi
675
676 # Returns to the original path
677 cd "$LOCALOLDPWD"
678
679 #if test "$DISPLAY" = ""; then
680 #  DISPLAY="unix:0.0"
681 #fi
682 #export DISPLAY
683
684
685 detect_macosx_version()
686 {
687     macosxVersion=`sw_vers | grep '^ProductVersion:' | grep -o '[0-9]*\.[0-9]*\.[0-9]*'`
688     if test "${macosxVersion}" = ""; then
689       macosxVersion=`sw_vers | grep '^ProductVersion:' | grep -o '[0-9]*\.[0-9]*'`
690     fi
691     macosxMajorVersion=`echo $macosxVersion | cut -d . -f 1`
692     macosxMinorVersion=`echo $macosxVersion | cut -d . -f 2`
693     macosxBuildVersion=`echo $macosxVersion | cut -d . -f 3`
694
695     if test $SCIVERBOSE -ne 0; then
696         echo "Found MacOSX Version: $macosxVersion"
697     fi
698
699 }
700
701 set_macox_specific_path()
702 {
703
704     PATH_TO_SPECIFIC_10_6=$SCIBINARYBASE/lib/thirdparty/10.6/
705     PATH_TO_SPECIFIC_10_5=$SCIBINARYBASE/lib/thirdparty/10.5/
706
707     case $macosxMajorVersion in
708         10)
709             case $macosxMinorVersion in
710                 6)
711                     # the iconv lib fails under 10.7, just declare it for 10.5 & 10.6
712                     LD_LIBRARY_PATH=$PATH_TO_SPECIFIC_10_6${LD_LIBRARY_PATH+:$LD_LIBRARY_PATH}
713                     DYLD_LIBRARY_PATH=$PATH_TO_SPECIFIC_10_6${DYLD_LIBRARY_PATH+:$DYLD_LIBRARY_PATH}
714                     ;;
715                  5)
716                     # the iconv lib fails under 10.7, just declare it for 10.5 & 10.6
717                     LD_LIBRARY_PATH=$PATH_TO_SPECIFIC_10_6${LD_LIBRARY_PATH+:$LD_LIBRARY_PATH}
718                     DYLD_LIBRARY_PATH=$PATH_TO_SPECIFIC_10_6${DYLD_LIBRARY_PATH+:$DYLD_LIBRARY_PATH}
719                     LD_LIBRARY_PATH=$PATH_TO_SPECIFIC_10_5${LD_LIBRARY_PATH+:$LD_LIBRARY_PATH}
720                     DYLD_LIBRARY_PATH=$PATH_TO_SPECIFIC_10_5${DYLD_LIBRARY_PATH+:$DYLD_LIBRARY_PATH}
721                     ;;
722             esac
723             ;;
724     esac
725
726 }
727
728 #
729 # Scilab will not work on some Mac OSX version
730 # Check version number and ask user if he wants to go on.
731 #
732 check_macosx_version()
733 {
734
735     case $macosxMajorVersion in
736         10)
737             case $macosxMinorVersion in
738                 7|8|9)
739                    # We force to install JRE on Lion
740                    /usr/libexec/java_home --request > /dev/null
741                    ;;
742                 6)
743
744                     if test $macosxBuildVersion -le 4; then
745                         # Version <= 10.6.4
746                         osascript $BINPATH/checkmacosx.applescript $macosxVersion "10.6.5 (Snow Leopard) or newer system" || exit 128
747                     fi
748                     ;;
749                  5)
750                      if test $macosxBuildVersion -le 7; then
751                          # Version <= 10.5.8
752                          osascript $BINPATH/checkmacosx.applescript $macosxVersion "10.5.8 (Leopard) or newer system" || exit 128
753                      fi
754                      # Check if the default java is not 1.5 (magic)
755                      VERSION=$(/usr/libexec/java_home -v 1.5|grep 1.5.0)
756                      if test "$VERSION"; then
757                          open /Applications/Utilities/Java\ Preferences.app/ &
758                          osascript $BINPATH/checkmacosx.applescript $macosxVersion "Java 6 or newer. Please disable any version of Java 1.5 in the Java Preferences menu. An other workaround is to rename /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Libraries/libjava.jnilib to libjava.jnilib_" || exit 128
759                      fi
760
761                      ;;
762                 *)
763                     osascript $BINPATH/checkmacosx.applescript $macosxVersion "10.6.5 (Snow Leopard) or newer system" || exit 128
764                     ;;
765             esac
766             ;;
767         *)
768             osascript $BINPATH/checkmacosx.applescript $macosxVersion "10.6.5 (Snow Leopard) or newer system" || exit 128
769             ;;
770     esac
771 }
772
773 # . is used by the dynamic link. The build lib are copied into the PWD
774 SCILIB=$SCI/bin:$SCI/lib/scilab/:$SCI/lib64/scilab/:.
775 if test -d $SCI/lib/thirdparty; then
776     SCILIB=$SCI/lib/thirdparty:$SCILIB;
777 fi
778 LD_LIBRARY_PATH=$SCILIB${LD_LIBRARY_PATH+:$LD_LIBRARY_PATH}
779
780 case $OS in
781     *darwin* | *Darwin*) # MacOS X
782         # When using some packaging tools like fink which are storing the info in /sw/lib
783         LD_LIBRARY_PATH="/sw/lib/${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
784     # Export the path to the Scilab lib when Scilab has been install ...
785     # to a Mac os x specific variable used by the linker before LD_LIBRARY_PATH
786         DYLD_LIBRARY_PATH=$SCI/../../lib/scilab/${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}:
787         # Crappy workaround for the dynamic load of sundials under Mac OS X
788         # in the source tree version. This does not occur in the binary
789         # thanks to the previous declaration on ../../lib/scilab
790         # See bug #4949
791         if test -d "$SCI/modules/scicos_blocks/.libs/"; then
792             DYLD_LIBRARY_PATH=$SCI/modules/scicos_blocks/.libs/${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}
793         fi
794         if test -d "$SCI/modules/scicos/.libs/"; then
795             DYLD_LIBRARY_PATH=$SCI/modules/scicos/.libs/${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}
796         fi
797         export DYLD_LIBRARY_PATH
798
799         # Now, check that I can run Scilab on this version of Mac OS X and
800         # display a standard window
801         BINPATH=$(dirname $0)
802         # Do not perform the check with Scilab is started in CLI mode
803
804         detect_macosx_version
805         set_macox_specific_path
806
807         if test "$SCILAB_MODE" = "gui"; then
808             check_macosx_version
809         fi
810
811         # When started as an Application, the default path was "/"
812         # It is not really useful. Changing to HOME.
813         # See bugs 8339 and 10575 for rational
814         if test "$(pwd)" == "/"; then
815             cd $HOME
816         fi
817
818         ;;
819     *)
820 esac
821
822
823 if test $SCIVERBOSE -ne 0; then
824     echo "LD_LIBRARY_PATH : $LD_LIBRARY_PATH"
825     if test ! -z "$DYLD_LIBRARY_PATH"; then
826         echo "DYLD_LIBRARY_PATH: $DYLD_LIBRARY_PATH"
827     fi
828 fi
829 export LD_LIBRARY_PATH
830 export PATH
831
832 # Scilab does not support the LANGUAGE variable.
833 # Unset to avoid some weird issue. CF bug #10032
834 unset LANGUAGE
835
836 if test $IS_SCILAB_BINARY -ne 1; then
837 # We are not using the Scilab binary, find out where docbook is.
838     find_docbook_path
839 fi
840
841 # Check if SELINUX is enable. If it is the case, disable it for Scilab
842 check_and_disable_selinux
843
844 do_scinotes()
845 {
846     INDENT=""
847     if test $# -gt 0; then
848     # scinotes is called. We process the arguments
849     ARGS="["
850
851     for SCIARG in "$@"; do
852         if test "$SCIARG" = "-indent"; then
853             INDENT="['indent','trailing','quote']"
854         else
855             ARGS="$ARGS '$SCIARG', "
856         fi
857     done
858     ARGS="$ARGS]"
859     fi
860
861     if test -n "$INDENT"; then
862     # Call scinotes with the arguments
863         if test $SCIVERBOSE -ne 0; then
864             echo "Will start scinotes with: $SCILABBIN -nb -nw -e scinotes($ARGS, $INDENT);exit()"
865         fi
866         "$SCILABBIN" -nb -nw -e "scinotes($ARGS, $INDENT);exit()"
867     else
868         if test $SCIVERBOSE -ne 0; then
869             echo "Will start scinotes with: $SCILABBIN -e scinotes($ARGS)"
870         fi
871
872     # Call scinotes with no argument
873         "$SCILABBIN" -e "scinotes($ARGS)"
874         exit $?
875     fi
876 }
877
878 do_xcos()
879 {
880     SIMULATE=0
881     if test $# -gt 0; then
882     # xcos is called. We process the arguments
883         ARGS="["
884         for SCIARG in "$@"; do
885             if test "$SCIARG" = "-simulate"; then
886                 if test $# -ne 2; then
887                     echo "Wrong syntax: When -simulate is used, only one file must be provided."
888                     exit 43
889                 fi
890                 SIMULATE=1
891             else
892                 ARGS="$ARGS '$SCIARG', "
893             fi
894         done
895         ARGS="$ARGS ]"
896     fi
897
898     if test $SIMULATE -eq 1; then
899         if test $SCIVERBOSE -ne 0; then
900             echo "Will start Xcos with: $SCILABBIN -e 'importXcosDiagram($ARGS);xcos_simulate(scs_m, 4)'"
901         fi
902
903     # Call xcos with the arguments to simulate
904         "$SCILABBIN" -e "importXcosDiagram($ARGS);xcos_simulate(scs_m, 4)"
905     else
906         if test $SCIVERBOSE -ne 0; then
907             echo "Will start Xcos with: $SCILABBIN -e xcos($ARGS)"
908         fi
909
910     # Call xcos with the arguments
911         "$SCILABBIN" -e "xcos($ARGS)"
912         exit $?
913     fi
914
915 }
916
917 do_scilex()
918 {
919     if test "$SCILAB_MODE" = "xcos"; then
920         do_xcos "$@"
921     else
922         if test "$SCILAB_MODE" = "scinotes"; then
923             do_scinotes "$@"
924         else
925             "$SCILABBIN" "$@"
926             exit $?
927         fi
928     fi
929 }
930
931 do_help()
932 {
933     if test "$SCILAB_MODE" = "xcos"; then
934         echo "Start Xcos, the hybrid simulator"
935         echo "Usage:"
936         echo "xcos [ file1.xcos, [ file2.xcos ]]"
937         echo     " "
938         echo     "  Possible arguments are:"
939         echo     "  -simulate : Start the simulation. Only one file will be accepted."
940         exit
941     fi
942     if test "$SCILAB_MODE" = "scinotes"; then
943         echo "Start Scinotes, the Scilab text editor"
944         echo "Usage:"
945         echo     "scinotes [ file1.sci, [ file2.sce ]]"
946         echo     " "
947         echo     "  Possible arguments are:"
948         echo     "  -indent : format (indent, trailing spaces, quote mismatch) the files"
949         exit
950     fi
951
952     echo "Usage:"
953     echo     "scilab <arguments>"
954     echo     "scilab-cli <arguments>"
955     echo     "scilab-adv-cli <arguments>"
956     echo     " "
957     echo     "  Possible arguments are:"
958     echo     "  -display Display: for use under Xwindow systems to set a specific X server display."
959     echo     "  -d Display      : equivalent to -display Display."
960     echo     "  -e Instruction  : execute the scilab instruction given in Instruction argument."
961     echo     "                    -e and -f arguments are mutually exclusive."
962     echo     "  -f File         : execute the scilab script given in File argument."
963     echo     "                    -e and -f arguments are mutually exclusive."
964     echo     "  -l Lang         : set the current language. Lang can be equal to fr or en."
965     echo     "  -mem N          : set the initial stacksize, for use with -ns argument."
966     echo     "  -nb             : do not display Scilab loading on start."
967     echo     "  -ns             : do not execute scilab.start startup file. This argument will disable many features in Scilab (Only use if you know what you are doing)."
968     echo     "  -nouserstartup  : do not execute the user startup files SCIHOME/.scilab or SCIHOME/scilab.ini."
969     echo     "  -noatomsautoload: do not load ATOMS installed module."
970     echo     "  -nw             : start Scilab without dedicated Scilab Window."
971     echo     "  -nwni           : start Scilab without the GUI, graphic and help features (batch mode). This argument disables the need of Java."
972     echo     "  -nogui          : See -nwni"
973     echo     "  -nocolor        : Remove the color in the cli and adv-cli modes"
974     echo     "  -args           : accept all extra arguments and make them available through sciargs"
975     echo     "  -version        : print product version and exit."
976     echo     "  -h/--help       : display help about this command."
977     echo     "  --texmacs       : reserved for TeXMacs."
978     echo     " "
979
980     echo     "Developer arguments:"
981     echo     "  -debug          : Start Scilab under gdb (Unix/linux only)."
982     echo     "                    define the variable SCILAB_GDB_OPT to add custom arguments to gdb."
983     echo     "  -debug-kdbg     : Start Scilab under kdbg (Unix/linux only)."
984     echo     "  -profiling      : Start Scilab under valgrind (Unix/linux only)."
985     echo     "                    define the variable SCILAB_VALGRIND_OPT to add custom arguments to"
986     echo     "                    valgrind (and override the existing valgrind arguments)."
987     echo     "  -profiling-visu : Start Scilab under callgrind (Unix/linux only)."
988     echo     "                    define the variable SCILAB_VALGRIND_OPT to add custom arguments to"
989     echo     "                    callgrind (and override the existing callgrind arguments)."
990     echo     "  -disable-exception-catching : Disable Scilab exception catching system."
991     echo     " "
992     echo     "  All these arguments can be retrieved by the Scilab function sciargs."
993     echo     " "
994
995     echo     "  Several environment variables can be declared:"
996     echo     "  SCIVERBOSE               Provides debugging information of the startup"
997     echo     "  JAVA_HOME                Declares which Java Virtual Machine to use"
998     echo     "  SCI_DISABLE_TK           Disable Tk (but not Tcl) features"
999     echo     "  SCI_JAVA_ENABLE_HEADLESS Enable Java Headless VM (ie without GUI features)"
1000     echo     "  SCI_DISABLE_EXCEPTION_CATCHING Disable the catch by Scilab of exception (segfault, ...)"
1001
1002     exit
1003 }
1004
1005 MORE_OPT=""
1006 if test "$SCILAB_MODE" = "nw"; then
1007     MORE_OPT="-nw"
1008 fi
1009
1010 # calling Scilab with no argument or special cases of calling Scilab
1011 rest="no"
1012 case $# in
1013     0) # No arg, run Scilab
1014         do_scilex $MORE_OPT
1015         ;;
1016     *)
1017         case $1 in
1018             *)
1019                 rest="yes"
1020                 ;;
1021         esac
1022         ;;
1023 esac
1024
1025 # really calling Scilab with arguments
1026
1027 if test "$rest" = "yes"; then
1028     debug=
1029     debug_kdbg=
1030     profiling=
1031     profiling_visu=
1032     prevarg=
1033     for sciarg in "$@"
1034     do
1035
1036     # If the previous argument needs an argument, skip current one.
1037         if test -n "$prevarg"; then
1038             prevarg=
1039             continue
1040         fi
1041
1042         case $sciarg in
1043             -nogui|-version|-ns|-nb|-nouserstartup|-noatomsautoload|-nocolor|--texmacs)
1044                 ;;
1045             -nw)
1046                 if test "$SCILAB_MODE" = "nwni"; then
1047                     echo "Cannot use scilab-cli with option -nw"
1048                     exit 5
1049                 fi
1050                 ;;
1051             -nwni)
1052                 if test "$SCILAB_MODE" = "nw"; then
1053                     echo "Cannot use scilab-adv-cli with option -nwni"
1054                     exit 5
1055                 fi
1056                 ;;
1057             -psn_*)
1058             # Under Mac OS X, .app is adding the arg -psn_0_xxxx
1059             # (psn = ProcessSerialNumber). It is not used (but could be in the future)
1060                 ;;
1061             -display|-f|-l|-e|-d|-mem)
1062                 prevarg=1
1063                 ;;
1064             -args) # Accept extra arguments
1065                 extraarg=1
1066                 ;;
1067             -debug)
1068                 DEBUG="-debug"
1069                 ;;
1070             -debug-kdbg)
1071                 DEBUG_KDBG="-debug-kdbg"
1072                 ;;
1073             -profiling)
1074                 PROFILING="-profiling"
1075                 ;;
1076             -profiling-visu)
1077                 PROFILING_VISU="-profiling-visu"
1078                 ;;
1079             -disable-exception-catching)
1080                 SCI_DISABLE_EXCEPTION_CATCHING=1
1081                 export SCI_DISABLE_EXCEPTION_CATCHING
1082                 ;;
1083             -h|--help)
1084                 do_help
1085                 ;;
1086             *)
1087                 foundUnknownArg=1
1088                 wrongArg=$sciarg
1089                 # Do nothing. Gives unknown args to Scilab binaries if -args is provided
1090                 ;;
1091         esac
1092     done
1093
1094
1095 # If the argument -a is not provided (extraarg) and we found unknown args
1096 # fail and provide help
1097     if test -z "$extraarg" -a -n "$foundUnknownArg"; then
1098         echo "Unknown argument: $wrongArg"
1099         echo ""
1100         do_help
1101     fi
1102
1103     if test -n "$DEBUG"; then
1104         start_debug "$@" $MORE_OPT
1105     else
1106         if test -n "$DEBUG_KDBG"; then
1107             start_debug_kdbg "$@" $MORE_OPT
1108         else
1109             if test -n "$PROFILING"; then
1110                 start_profiling "$@" $MORE_OPT
1111             else
1112                 if test -n "$PROFILING_VISU"; then
1113                     start_profiling_visu "$@" $MORE_OPT
1114                 else
1115                     do_scilex "$@" $MORE_OPT
1116                 fi # not profiling visu
1117             fi # not profiling
1118         fi # not debug kdbg
1119     fi # not debug
1120 fi # if rest