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