For Clozure CL, define character names for the drawing characters which are currently...
[maxima.git] / lisp-utils / maxima-run-lisp
blobcc677f10b0e95171bb424e79941c316c28b2ce24
1 #! /bin/sh
2 # -----------------------------------------------------------------------------
3 # Title: A script to invoke the various CL implementations in a uniform way
4 # Created: 1999-01-16 16:41
5 # Author: Gilbert Baumann <unk6@rz.uni-karlsruhe.de>
6 # License: LGPL (See file GNU-LGPL for details)
7 # -----------------------------------------------------------------------------
8 # (c) copyright 1999 by Gilbert Baumann, Sam Steingold, Bruno Haible
9 # $Id: maxima-run-lisp,v 1.7 2003-03-05 01:36:25 rtoy Exp $
10 # $Source: /home/lbutler/maxima/sandbox/cvs/maxima/maxima/lisp-utils/maxima-run-lisp,v $
12 # Prior to invocation the LISPTYPE environment variable must been set to
13 # one of these:
15 # clisp uses ${CLISP} if set, else "clisp"
16 # cmucl uses ${CMUCL} if set, else "lisp"
17 # acl43 uses ${ACL43} if set, else "cl"
18 # acl5 uses ${ACL5} if set, else "cl"
19 # acl6 uses $(ACL6) if set, else "alisp
20 # gcl uses ${GCL} if set, else "gcl"
21 # sbcl uses ${SBCL} if set, else "sbcl"
22 # openmcl uses ${OPENMCL} if set, else "openmcl"
24 usage(){
25 cat <<\EOF
26 Usage:
27 run-lisp [clause ...] [argument ...]
28 clause ::= -i file ; load file `file'
29 | -c file ; compile file `file'
30 | -x form ; execute form `form'
31 | -I image ; use image file `image'
32 | -d image ; dump to image `image'
33 | -f initfun ; set init function of dumped image to `initfun'
34 | --extra-args=args ; add 'args' to lisp command line
35 | --safety n ; set safety level for compilation
36 | --speed n ; set speed level for compilation
38 Note: Lisp specific extensions (e.g. .dxl on ACL or .mem for CLISP)
39 are not to be included into the image argument
41 Anything else is stuffed into the Lisp variable 'argv', which is
42 available in the lexical environment forms given to -x are
43 evaluated in.
45 run-lisp [--extra-args=args] -run image [-i file]
46 interactively run 'image'
47 (user:run) will be called upon start up.
49 Makefile support
51 run-lisp -faslext
52 echo the fasload file extension to stdout.
53 This is useful for Makefile; you could then say e.g.
54 FAS:=$(shell $(TOP)/bin/run-lisp -faslext)
56 run-lisp -dumpext
57 echo the memory image extension _with_ dot.
58 usage: (like above)
59 DUMP:=$(shell $(TOP)/bin/run-lisp -dumpext)
61 run-lisp -cat [fasl-file ...]
62 Cat all the given fasl files together.
64 EXAMPLE
66 $ run-lisp -x "(print argv)" foo bar baz "Hallo Welt" foo\"bar
67 ("foo" "bar" "baz" "Hallo Welt" "foo\"bar")
69 EOF
70 exit 0;
73 fail(){
74 echo "$0: $*" 1>&2
75 exit 1
78 case "$1" in
79 --extra-args=*)
80 extra_args=`echo $1 | sed 's/--extra-args=//'`
81 shift 1
85 esac
87 case "$1" in
88 "--help" | "-h" | "-?" )
89 usage
91 "-cat" )
92 shift
93 case "$LISPTYPE" in
94 clisp | cmucl | acl43 | acl[56] )
95 cat "$@"
97 * )
98 fail "Sorry, option -cat not supported for LISPTYPE=${LISPTYPE}."
100 esac
102 "-faslext" )
103 shift
104 case "$LISPTYPE" in
105 clisp )
106 # This is (pathname-type (car (system::*compiled-file-types*))).
107 echo 'fas'
109 cmucl )
110 # This can be found via
111 # (c:backend-fasl-file-type c:*target-backend*),
112 # but for speed we look at the uname first.
113 case `uname -m 2>/dev/null` in
114 i[3-6]86 )
115 echo 'x86f'
118 # Call .
119 ${CMUCL-lisp} -noinit \
120 -eval "(progn \
121 (write-string (c:backend-fasl-file-type c:*target-backend*))
122 (terpri)
123 (ext:quit 0))"
125 esac
127 acl43 | acl[56] )
128 echo 'fasl'
130 gcl )
131 echo 'o' # but also 'data' on same platforms
133 sbcl )
134 echo 'fasl' # How about other platforms?
136 openmcl )
137 case `uname -s` in
138 Darwin ) # Darwin
139 echo 'dfsl'
141 * ) # Linux PPC
142 echo 'pfsl'
144 esac
147 # Since make does not stop when the exit status is 1, we simply
148 # echo LISPTYPE_NOT_SET here.
149 echo LISPTYPE_NOT_SET
150 fail "Sorry, option -faslext not supported for LISPTYPE=${LISPTYPE}."
152 esac
154 "-dumpext" )
155 shift 1
156 case "$LISPTYPE" in
157 clisp)
158 echo .mem
160 acl43)
161 echo ""
163 acl[56])
164 echo .dxl
166 cmucl)
167 echo .core
169 sbcl)
170 echo .core # This is just a guess
172 openmcl)
173 echo .image
176 # Since make does not stop when the exit status is 1, we simply
177 # echo LISPTYPE_NOT_SET here.
178 echo LISPTYPE_NOT_SET
179 fail "Sorry, option -dumpext not supported for LISPTYPE=${LISPTYPE}."
181 esac
183 "-run" )
184 # we special case on '-run' for now
185 shift 1
186 if [ x"$2" = x"-i" ]; then
187 load_file=$3
189 case "$LISPTYPE" in
190 clisp)
191 if [ -n "$load_file" ]; then
192 load_arg="-i $load_file"
194 ${CLISP-clisp} $extra_args $load_arg -M "$1".mem
196 cmucl )
197 if [ -n "$load_file" ]; then
198 load_arg="-load $load_file"
200 # jfa: fixme 04/24/02
201 # jfa: The -eval part of the following line is a big hack!
202 ${CMUCL-lisp} -eval "(user::run)" $extra_args $load_arg -core "$1".core
204 sbcl )
205 if [ -n "$load_file" ]; then
206 load_arg="--load $load_file"
208 # jfa: fixme 04/24/02
209 # jfa: The --eval part of the following line is a big hack!
210 ${SBCL-sbcl} --core "$1".core --eval "(user::run)" $extra_args $load_arg
212 acl43 )
213 if [ -n "$load_file" ]; then
214 load_arg="-i $load_file"
216 # Why "$1"? ACL4.3 dumps executables
217 "$1" $extra_args $load_arg -e '(unwind-protect (run) (excl:exit))'
219 acl5 )
220 if [ -n "$load_file" ]; then
221 load_arg="-i $load_file"
223 ${ACL5-cl} $extra_args $load_arg -I "$1".dxl -e '(unwind-protect (run) (excl:exit))'
225 acl6 )
226 if [ -n "$load_file" ]; then
227 load_arg="-i $load_file"
230 # I (RLT) am not sure the -e is quite right, but this
231 # allows us to get back to lisp when the user does
232 # to_lisp(), like the way CMUCL does it.
234 ${ACL6-alisp} $extra_args $load_arg -I "$1".dxl -e '(user::run)'
236 gcl )
237 if [ -n "$load_file" ]; then
238 load_arg="-load $load_file"
240 "$1" $extra_args $load_arg -eval '(run)'
242 openmcl )
243 if [ -n "$load_file" ]; then
244 load_arg="-l $load_file"
246 ${OPENMCL-openmcl} -I "$1.image" $load_arg
249 fail "Sorry, option -run not supported for LISPTYPE=${LISPTYPE}."
251 esac
254 # Multiple arguments.
255 unset image
256 todo="" # list of forms to execute
257 args="" # list of arguments (strings) to pass
258 while [ $# != 0 ]; do
259 case "$1" in
261 if [ $# = 1 ]; then
262 fail "missing argument for $1"
264 shift
265 backslashify='s,\(["\\]\),\\\1,g'
266 arg=`echo "$1" | sed -e "$backslashify"`
267 todo=$todo" (load \"${arg}\")"
268 shift
271 if [ $# = 1 ]; then
272 fail "missing argument for $1"
274 shift
275 todo=$todo" $1"
276 shift
279 if [ $# = 1 ]; then
280 fail "missing argument for $1"
282 shift
283 backslashify='s,\(["\\]\),\\\1,g'
284 arg=`echo "$1" | sed -e "$backslashify"`
285 # todo=$todo" (compile-file \"${arg}\" :print nil)"
286 # truename helps, when using Franz' emacs interface
287 todo=$todo" (compile-file (truename \"${arg}\") :print nil)"
288 shift
291 if [ $# = 1 ]; then
292 fail "missing argument for $1"
294 shift
295 image="$1"
296 shift
299 if [ $# = 1 ]; then
300 fail "missing argument for $1"
302 shift
303 initfun=$1
304 case "$LISPTYPE" in
305 clisp )
306 initfun_arg=":init-function #'$initfun"
308 cmucl )
309 initfun_arg=":init-function #'$initfun"
311 sbcl )
312 initfun_arg=":toplevel #'$initfun"
314 gcl )
315 todo=$todo" (setq si::*top-level-hook* #'$initfun)"
317 openmcl )
318 initfun_arg=":toplevel-function #'$initfun"
321 fail "Sorry, option -d not supported for LISPTYPE=${LISPTYPE}."
323 esac
324 shift
327 if [ $# = 1 ]; then
328 fail "missing argument for $1"
330 shift
331 backslashify='s,\(["\\]\),\\\1,g'
332 arg=`echo "$1" | sed -e "$backslashify"`
333 case "$LISPTYPE" in
334 clisp )
335 todo=$todo" (#+lisp=cl ext:saveinitmem #-lisp=cl lisp:saveinitmem \"${arg}.mem\" $initfun_arg)"
337 cmucl )
338 todo=$todo" (ext:save-lisp \"${arg}.core\" $initfun_arg)"
340 sbcl )
341 todo=$todo" (sb-ext:save-lisp-and-die \"${arg}.core\" $initfun_arg)"
343 acl43 )
344 todo=$todo" (excl:dumplisp :name \"${arg}\")"
346 acl[56] )
347 todo=$todo" (excl:dumplisp :name \"${arg}.dxl\")"
349 gcl )
350 todo=$todo" (si:save-system \"${arg}\")"
352 openmcl )
353 todo=$todo" (ccl:save-application \"${arg}.image\" $initfun_arg)"
356 fail "Sorry, option -d not supported for LISPTYPE=${LISPTYPE}."
358 esac
359 shift
361 --safety)
362 if [ $# = 1 ]; then
363 fail "missing argument for $1"
365 shift 1
366 todo=$todo" (proclaim (quote (optimize (safety "$1"))))"
367 shift 1
369 --speed)
370 if [ $# = 1 ]; then
371 fail "missing argument for $1"
373 shift 1
374 todo=$todo" (proclaim (quote (optimize (speed "$1"))))"
375 shift 1
378 backslashify='s,\(["\\]\),\\\1,g'
379 arg=`echo "$1" | sed -e "$backslashify"`
380 args=$args" \"${arg}\""
381 shift
383 esac
384 done
386 # done with collecting the arguments
388 if [ x"$LISPTYPE" = x"sbcl" ]; then
389 todo="(progn${todo}(sb-ext:quit))"
390 elif [ x"$LISPTYPE" = x"openmcl" ]; then
391 todo="(progn ${todo} (ccl::quit))"
392 else
393 todo="(progn${todo})"
395 args="(${args})"
396 todo="(let ((argv '$args)) (declare (ignorable argv)) $todo (values))"
398 case "$LISPTYPE" in
399 clisp )
400 todo="(progn (setq #+lisp=cl ext:*load-paths* #-lisp=cl lisp:*load-paths* '(#P\"\")) ${todo})"
401 test -z "$image" || image="-M ${image}.mem";
402 echo ${CLISP-clisp} -norc -q ${image} -x "$todo"
403 exec ${CLISP-clisp} $extra_args -norc -q ${image} -x "$todo"
405 cmucl )
406 # we have to convince CMUCL to return a proper exit status.
407 todo="(let (.res (.cond t))
408 (unwind-protect
409 (multiple-value-setq (.res .cond)
410 (ignore-errors (progn $todo
411 (fresh-line) (finish-output))))
412 (unix:unix-exit (if .cond 1 0))))"
413 test -z "$image" || image="-core ${image}.core";
414 exec ${CMUCL-lisp} $extra_args -noinit ${image} -eval "$todo"
416 acl43 )
417 exec echo "$todo" | ${image-${ACL43-cl}} $extra_args -batch
419 acl5 )
420 test -z "$image" || image="-I ${image}.dxl";
421 exec echo "$todo" | ${ACL5-cl} ${image+"-I ${image}.dxl"} $extra_args -batch
423 acl6 )
424 test -z "$image" || image="-I ${image}.dxl";
425 exec echo "$todo" | ${ACL6-alisp} ${image+"-I ${image}.dxl"} $extra_args -batch
427 gcl )
428 echo ${image-${GCL-gcl}} $extra_args -batch -eval "$todo"
429 ${image-${GCL-gcl}} $extra_args -batch -eval "$todo"
431 sbcl )
432 ${image-${SBCL-sbcl}} $extra_args --noinform --noprint --eval "$todo"
434 openmcl )
435 test -z "$image" || image="-I ${image}.image";
436 echo ${OPENMCL-openmcl} ${image} -e "${todo}" $extra_args
437 ${OPENMCL-openmcl} ${image} -e "${todo}" $extra_args
440 if [ -n "$LISPTYPE" ] ; then
441 fail "Sorry, LISPTYPE=${LISPTYPE} is not supported"
442 else
443 fail "LISPTYPE environment variable is not set"
446 esac
448 esac