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