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