Correct typo in Texinfo: cdf_tributions --> distributions
[maxima/cygwin.git] / src / maxima.in
blobce84356a622c66acd4a8619b5635389c65e63df7
1 #!@POSIX_SHELL@
2 # -*- Shell-script -*-
4 unixize () {
5     echo "$1" | sed -e 's%\\\\%/%g' | sed -e 's%^\([A-Za-z]\):%/\1%'
8 setup_vars() {
9   if [ -z "$MAXIMA_VERSION" ]; then
10     MAXIMA_VERSION="@VERSION@"
11   fi
12   prefix=`unixize "@prefix@"`
13   exec_prefix=`unixize "@exec_prefix@"`
14   PACKAGE=@PACKAGE@
15   top_srcdir=`unixize "@expanded_top_srcdir@"`
16   libdir=`unixize "@libdir@"`
17   if [ -n "$MAXIMA_LAYOUT_AUTOTOOLS" ]; then
18       layout_autotools="$MAXIMA_LAYOUT_AUTOTOOLS"
19   else
20       layout_autotools=@default_layout_autotools@
21   fi
22   if [ "$layout_autotools" = "true" ]; then
23       MAXIMA_DEFAULT_IMAGESDIR=$libdir/$PACKAGE/$MAXIMA_VERSION
24   else
25       MAXIMA_DEFAULT_IMAGESDIR=$top_srcdir/src
26   fi  
27   if [ -d "$MAXIMA_DEFAULT_IMAGESDIR" ]; then
28       MAXIMA_IMAGESDIR="$MAXIMA_DEFAULT_IMAGESDIR"
29   else
30       if [ "$layout_autotools" = "true" ]; then
31           MAXIMA_IMAGESDIR=`unixize "$MAXIMA_PREFIX"`/lib/$PACKAGE/$MAXIMA_VERSION
32       else
33           MAXIMA_IMAGESDIR=`unixize "$MAXIMA_PREFIX"`/src
34       fi  
35   fi
36   MAXIMA_DEFAULT_LISP=@DEFAULTLISP@
37   # If the the binary directory for the default lisp is not present,
38   # choose the first one we find.
39   if [ ! -d "$MAXIMA_IMAGESDIR/binary-$MAXIMA_DEFAULT_LISP" ]; then
40     MAXIMA_DEFAULT_LISP=`ls -1 $MAXIMA_IMAGESDIR 2>/dev/null | head -n 1 | sed 's/binary-//'`
41   fi
42   if [ -z "$MAXIMA_LISP" ]; then
43     MAXIMA_LISP=$MAXIMA_DEFAULT_LISP
44   fi
47 unsetup_vars () {
48   unset MAXIMA_IMAGESDIR
49   unset MAXIMA_LISP
52 process_userdir_argument() {
53     while [ -n "$1" ]; do
54         case $1 in 
55         --userdir ) MAXIMA_USERDIR=$2 ; shift;;
56         --userdir=* ) MAXIMA_USERDIR=`echo "$1" | sed 's/--userdir=//'` ;;
57         esac
58         shift
59     done
60 if [ -n "$MAXIMA_USERDIR" ]; then
61     export MAXIMA_USERDIR
65 # make a special check for --userdir argument, because it influences location
66 # of maximarc, which is sourced before  other command-line options are
67 # processed
68 process_userdir_argument "$@"
70 if [ -z "$MAXIMA_USERDIR" ]; then
71   maximarc_path="$HOME/.maxima/maximarc"
72 else
73   maximarc_path="`unixize \"$MAXIMA_USERDIR\"`/maximarc"
75 if [ -f "$maximarc_path" ]; then
76   . "$maximarc_path"
79 # For some reason TeXmacs sets MAXIMA_DIRECTORY to the empty string,
80 # which breaks maxima's internal path logic. This is a workaround.
81 if [ -z "$MAXIMA_DIRECTORY" ]; then
82   unset MAXIMA_DIRECTORY
85 # GCL in its default settings tends to run out of memory frequently quickly.
86 # For example 8 Gigabytes of RAM aren't enough to run the testbench when sbcl
87 # and clisp need <0,5 Gigabytes by default.
88 # The following lines make GCL's garbage collector more aggressive by default.
89 if [ -z "$GCL_GC_PAGE_THRESH" ]; then
90     export GCL_GC_PAGE_THRESH=0.2
91 fi;
92 if [ -z "$GCL_GC_ALLOC_MIN" ]; then
93     export GCL_GC_ALLOC_MIN=0.01
94 fi;
95 if [ -z "$GCL_GC_PAGE_MAX" ]; then
96     export GCL_GC_PAGE_MAX=0.05
97 fi;
100 # GCL also by default tells the garbage collector to limit the memory usage to
101 # allocate half of the physical RAM installed in the current machine.
102 # Which works fine in a single-user system and even takes in account the amount
103 # of memory the other gcl processes use but is too far in the multitasking versus
104 # speed tradeoff for us.
106 # See also:
107 # https://lists.gnu.org/archive/html/gcl-devel/2017-09/msg00000.html
108 if [ -z "$GCL_MEM_MULTIPLE" ]; then
109     export GCL_MEM_MULTIPLE=0.2
112 # process the command line arguments. This must be done in a function, because
113 # "shift" should only shift the function parameters, not the global parameters.
114 process_commandline_arguments() {
115     while [ -n "$1" ]; do
116         case $1 in
117             -l|--lisp ) MAXIMA_LISP=$2 ; shift;;
118             --lisp=*) MAXIMA_LISP=`echo "$1" | sed 's/--lisp=//'` ;;
119             -u|--use-version ) MAXIMA_VERSION=$2 ; shift;;
120             --use-version=*) MAXIMA_VERSION=`echo "$1" | sed 's/--use-version=//'` ;;
121             -X|--lisp-options) MAXIMA_LISP_OPTIONS="$2" ; shift ;;
122             --lisp-options=*) MAXIMA_LISP_OPTIONS=`echo "$1" | sed 's/--lisp-options=//'` ;;
123             --userdir ) : ; shift;; # noop; handled by process_userdir_argument
124             --userdir=*) : ;; # noop; handled by process_userdir_argument
125             -v|--verbose ) verbose=true;;
126             *) ;;
127         esac
128         shift
129     done
132 process_commandline_arguments "$@"
135 # Allow ccl as an alias of openmcl.
136 if [ "$MAXIMA_LISP" = "ccl" ]; then
137     MAXIMA_LISP=openmcl
141 setup_vars
143 if [ ! -d "$MAXIMA_IMAGESDIR" ]; then
144 # Have we been moved?
145   MAXIMA_PREFIX=`(cd "\`dirname "$0"\`" 1>/dev/null 2>/dev/null; dirname "\`pwd\`")`
146   export MAXIMA_PREFIX
147   unsetup_vars
148   setup_vars
149   if [ ! -d "$MAXIMA_IMAGESDIR" ]; then
150     echo "$0: unable to determine MAXIMA_PREFIX" 1>&2
151     exit 1
152   fi
155 # This step should only be necessary in order to be in sync with the windows
156 # version of maxima.
157 if [ -d "$MAXIMA_INITIAL_FOLDER" ]; then
158     cd "$MAXIMA_INITIAL_FOLDER"
161 maxima_image_base="$MAXIMA_IMAGESDIR/binary-$MAXIMA_LISP/maxima"
163 if [ "$verbose" = "true" ]; then
164     set -x
166 if [ "$MAXIMA_LISP" = "clisp" ]; then
167     if [ "$layout_autotools" = "true" ]; then
168       if [ -x "$MAXIMA_IMAGESDIR/binary-$MAXIMA_LISP/maxima" ]; then
169         exec "$MAXIMA_IMAGESDIR/binary-$MAXIMA_LISP/maxima" $MAXIMA_LISP_OPTIONS -q "" -- "$@"
170       else
171         exec "$MAXIMA_IMAGESDIR/binary-$MAXIMA_LISP/@CLISP_RUNTIME@" $MAXIMA_LISP_OPTIONS -q -M "$maxima_image_base.mem" "" -- "$@"
172       fi
173     else
174       if [ -x "$maxima_image_base" ]; then
175         exec "$maxima_image_base"  $MAXIMA_LISP_OPTIONS -q  "" -- "$@"
176       else
177         exec "@CLISP_NAME@" $MAXIMA_LISP_OPTIONS -q -M "$maxima_image_base.mem" "" -- "$@"
178       fi
179     fi
180 elif [ "$MAXIMA_LISP" = "cmucl" ]; then
181     # CMUCL can use either an executable image or a regular lisp core
182     # file.  Check for the executable image and run that if possible.
183     # Otherwise, fallback and use the lisp core file.
184     if [ "$layout_autotools" = "true" ]; then
185         if [ -x "$MAXIMA_IMAGESDIR/binary-$MAXIMA_LISP/maxima" ]; then
186             exec "$MAXIMA_IMAGESDIR/binary-$MAXIMA_LISP/maxima" $MAXIMA_LISP_OPTIONS -quiet -- "$@"
187         else
188             exec "$MAXIMA_IMAGESDIR/binary-$MAXIMA_LISP/@CMUCL_RUNTIME@" $MAXIMA_LISP_OPTIONS -quiet -core "$maxima_image_base.core" -eval '(cl-user::run)' -- "$@"
189         fi
190     else
191         if [ -x "$maxima_image_base" ]; then
192             exec "$maxima_image_base" $MAXIMA_LISP_OPTIONS -quiet -- "$@"
193         else
194             exec "@CMUCL_NAME@" $MAXIMA_LISP_OPTIONS -quiet -core "$maxima_image_base.core" -eval '(cl-user::run)' -- "$@"
195         fi
196     fi
197 elif [ "$MAXIMA_LISP" = "scl" ]; then
198     if [ "$layout_autotools" = "true" ]; then
199         exec "$MAXIMA_IMAGESDIR/binary-$MAXIMA_LISP/@SCL_RUNTIME@" $MAXIMA_LISP_OPTIONS -quiet -core "$maxima_image_base.core" -eval '(cl-user::run)' -- "$@"
200     else
201         exec "@SCL_NAME@" $MAXIMA_LISP_OPTIONS -quiet -core "$maxima_image_base.core" -eval '(cl-user::run)' -- "$@"
202     fi
203 elif [ "$MAXIMA_LISP" = "gcl" ]; then
204     exec "$maxima_image_base" -eval '(cl-user::run)' $MAXIMA_LISP_OPTIONS -f -- "$@"
205 elif [ "$MAXIMA_LISP" = "acl" ]; then
206 # FIXME: arguments need in a manner consistent with the way they are extracted
207 #        in the function get-application-args in command-line.lisp
208     exec "@ACL_NAME@" -I "$maxima_image_base.dxl" $MAXIMA_LISP_OPTIONS -e '(cl-user::run)' -- "$@"
209 elif [ "$MAXIMA_LISP" = "openmcl" ]; then
210 # OPENMCL can use either an executable image or a regular lisp core
211 # file.  Check for the executable image and run that if possible.
212 # Otherwise, fallback and use the lisp core file.
213 # FIXME: arguments need in a manner consistent with the way they are extracted
214 #        in the function get-application-args in command-line.lisp
215     if [ -x "$MAXIMA_IMAGESDIR/binary-$MAXIMA_LISP/maxima" ]; then
216       exec "$MAXIMA_IMAGESDIR/binary-$MAXIMA_LISP/maxima" $MAXIMA_LISP_OPTIONS -e '(cl-user::run)' -- "$@"
217     else
218       exec "@OPENMCL_NAME@" -I "$maxima_image_base.image" $MAXIMA_LISP_OPTIONS -e '(cl-user::run)' -- "$@"
219    fi
220 elif [ "$MAXIMA_LISP" = "ccl64" ]; then
221 # Ccl64 can use either an executable image or a regular lisp core
222 # file.  Check for the executable image and run that if possible.
223 # Otherwise, fallback and use the lisp core file.
224 # FIXME: arguments need in a manner consistent with the way they are extracted
225 #        in the function get-application-args in command-line.lisp
226     if [ -x "$MAXIMA_IMAGESDIR/binary-$MAXIMA_LISP/maxima" ]; then
227       exec "$MAXIMA_IMAGESDIR/binary-$MAXIMA_LISP/maxima" $MAXIMA_LISP_OPTIONS -e '(cl-user::run)' -- "$@"
228     else
229       exec "@CCL64_NAME@" -I "$maxima_image_base.image" $MAXIMA_LISP_OPTIONS -e '(cl-user::run)' -- "$@"
230    fi
232 elif [ "$MAXIMA_LISP" = "ecl" ]; then
233    exec "$maxima_image_base" --frame-stack 4096 --lisp-stack 65536 $MAXIMA_LISP_OPTIONS -- "$@"
235 elif [ "$MAXIMA_LISP" = "abcl" ]; then
236     export MAXIMA_LISP_OPTIONS
237     export MAXIMA_IMAGESDIR
238     $MAXIMA_IMAGESDIR/binary-abcl/maxima "$@"
239     
240 elif [ "$MAXIMA_LISP" = "sbcl" ]; then
241 # Use executable image if it exists.
242 # Since compiling lapack already needed >1200 Megabytes of RAM in August of 2015 
243 # one has to extend the amount of memory sbcl will be able to claim by using the
244 # switch --dynamic-space-size in order to do so.
245   if [ -x "$MAXIMA_IMAGESDIR/binary-$MAXIMA_LISP/maxima" ]; then
246     exec "$MAXIMA_IMAGESDIR/binary-$MAXIMA_LISP/maxima" --noinform $MAXIMA_LISP_OPTIONS --end-runtime-options --eval '(cl-user::run)' --end-toplevel-options "$@"
247   else
248     exec "@SBCL_NAME@" --core "$maxima_image_base.core" --noinform $MAXIMA_LISP_OPTIONS --end-runtime-options --eval '(cl-user::run)' --end-toplevel-options "$@"
249   fi
251 else
252     echo "$0: lisp=\"$MAXIMA_LISP\" not known. Use --list-avail to see possible options." >&2
253     exit 1