@@@ work in progress
[runlisp] / runlisp.1
CommitLineData
e29834b8
MW
1.\" -*-nroff-*-
2.\"
3.\" Manual for `runlisp'
4.\"
5.\" (c) 2020 Mark Wooding
6.\"
7.
8.\"----- Licensing notice ---------------------------------------------------
9.\"
10.\" This file is part of Runlisp, a tool for invoking Common Lisp scripts.
11.\"
12.\" Runlisp is free software: you can redistribute it and/or modify it
13.\" under the terms of the GNU General Public License as published by the
14.\" Free Software Foundation; either version 3 of the License, or (at your
15.\" option) any later version.
16.\"
17.\" Runlisp is distributed in the hope that it will be useful, but WITHOUT
18.\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19.\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20.\" for more details.
21.\"
22.\" You should have received a copy of the GNU General Public License
23.\" along with Runlisp. If not, see <https://www.gnu.org/licenses/>.
24.
25.ie t \{\
26. ds o \(bu
27. if \n(.g \{\
28. fam P
29. ev an-1
30. fam P
31. ev
32. \}
33.\}
34.el \{\
35. ds o o
36.\}
37.
38.de hP
39.IP
40\h'-\w'\fB\\$1\ \fP'u'\fB\\$1\ \fP\c
41..
42.
43.\"--------------------------------------------------------------------------
44.TH runlisp 1 "2 August 2020" "Mark Wooding"
45.SH NAME
46runlisp \- run Common Lisp programs as scripts
47.
48.\"--------------------------------------------------------------------------
49.SH SYNOPSIS
50.
51.B runlisp
52.RB [ \-CDEnqv ]
53.RB [ \-I
54.IR imagedir ]
55.RB [ \-L
56.IB sys , sys , \fR...]
57.RB [ \-P
58.IB sys , sys , \fR...]
59.br
60\h'8n'
61.RB [ \-e
62.IR form ]
63.RB [ \-l
64.IR file ]
65.RB [ \-p
66.IR form ]
67.RB [ \-\- ]
68.RI [ script ]
69.RI [ arguments
70\&...]
71.
72.\"--------------------------------------------------------------------------
73.SH DESCRIPTION
74.
75The
76.B runlisp
77program has two main functions.
78.hP 1.
79It can be used in a script's
80.RB ` #! '
81line to run a Common Lisp script.
82.hP 2.
83It can be used in build scripts
84to invoke a Common Lisp system,
85e.g., to build a standalone program.
86.
87.SS "Supported Common Lisp implementations"
88The following Lisp implementations are currently supported.
89.TP
90.B "abcl"
91Armed Bear Common Lisp.
92.TP
93.B "ccl"
94Clozure Common Lisp.
95.TP
96.B "clisp"
97GNU CLisp.
98.TP
99.B "cmucl"
100Carnegie\(enMellon University Common Lisp.
101.TP
102.B "ecl"
103Embeddable Common Lisp.
104.TP
105.B "sbcl"
106Steel Bank Common Lisp.
107.PP
108The
109.B runlisp
110program expects, by default,
111to be able to run a Lisp system
112as a program with the same name,
113found by searching as directed by the
114.B PATH
115environment variable.
116This can be overridden by setting an environment variable,
117with the same name but in
118.IR "upper case" ,
119to the actual name \(en
120either a bare filename to be searched for on the
121.BR PATH ,
122or a pathname containing a
123.RB ` / ',
124relative to the working directory or absolute,
125to the program.
126Note that the entire variable value is used as the program name:
127it's not possible to provide custom arguments to a Lisp system
128using this mechanism.
129If you want to do that,
130you must write a shell script to do the necessary work,
131and point the environment variable
132(or the
133.BR PATH )
134at your script.
135.
136.SS "Options"
137Options are read from the command line, as usual,
138but also from a number of other sources;
139these are, in order:
140.hP \*o
141If a
142.I script
143is named,
144and the script's second line contains a
145.RB ` @RUNLISP: '
146marker,
147then text following the marker is parsed as options.
148.hP \*o
149If files named
150.B ~/.runlisprc
151and/or
152.B ~/.config/runlisprc
153exist,
154then their contents are parsed as options.
155.hP \*o
156If an environment variable
157.B RUNLISP_OPTIONS
158is defined,
159then its contents is parsed as options.
160.PP
161A simple quoting and escaping system is implemented
162to allow spaces and other special characters
163to be included in argument words
164in the script, configuration files, and environment variable.
165The details of all of this are given in the section
166.B Operation
167below.
168.
169.PP
170The options accepted are as follows.
171.
172.TP
173.B "\-\-help"
174Write a synopsis of
175.BR runlisp 's
176command-line syntax
177and a description of the command-line options
178to standard output
179and immediately exit with status 0.
180.
181.TP
182.B "\-\-version"
183Write
184.BR runlisp 's
185version number
186to standard output
187and immediately exit with status 0.
188.
189.TP
190.B "\-C"
191Clear the list of preferred Lisp implementations.
192.
193.TP
194.B "\-D"
195Don't check for a custom Lisp image.
196Usually,
197.B runlisp
198tries to start Lisp systems using a custom image,
199so that they'll start more quickly;
200the
201.RB ` \-D '
202option forces the use of the default `vanilla' image
203provided with the system.
204There's not usually any good reason to prefer the vanilla image,
205except for performance comparisons, or debugging
206.B runlisp
207itself.
208.
209.TP
210.B "\-E"
211Don't read embedded options from the
212second line of the
213.I script
214file.
215This has no effect in eval mode.
216.
217.TP
218.BI "\-I " imagedir
219Look in
220.I imagedir
221for custom Lisp images.
222This option overrides the default image directory,
223which is set at compile time.
224.
225.TP
226.BI "\-L " sys , sys ,\fR...
227Use one of the named Lisp systems.
228Each
229.I sys
230must name a supported Lisp system.
231This option may be given more than once:
232the effect is the same as a single option
233listing all of the systems named, in the same order.
234If a system is named more than once,
235a warning is issued (at verbosity level 1 or higher),
236and all but the first occurrence is ignored.
237.
238.TP
239.BI "\-P " sys , sys ,\fR...
240Set the relative preference order of Lisp systems:
241systems listed earlier are more preferred.
242Each
243.I sys
244must name a supported Lisp system.
245This option may be given more than once:
246the effect is the same as a single option
247listing all of the systems named, in the same order.
248If a system is named more than once,
249a warning is issued (at verbosity level 1 or higher),
250and all but the first occurrence is ignored.
251Unmentioned systems are assigned lowest preference:
252if a
253.RB ` \-L '
254option is given,
255then this provides a default preference ordering;
256otherwise, an ordering hardcoded into the program is used.
257The first acceptable Lisp system,
258according to the preference order just described,
259which actually exists,
260is the one selected.
261.
262.TP
263.BI "\-e " expr
264Evaluate the expression(s)
265.I expr
266and discard the resulting values.
267This option causes
268.B runlisp
269to execute in
270.I eval
271mode.
272.
273.TP
274.BI "\-l " file
275Read and evaluate forms from the
276.IR file .
277This option causes
278.B runlisp
279to execute in
280.I eval
281mode.
282.
283.TP
284.B "\-n"
285Don't actually start the Lisp environment.
286This may be helpful for the curious,
287in conjunction with
288.RB ` \-v '
289to increase the verbosity.
290.
291.TP
292.BI "\-p " expr
293Evaluate the expression(s)
294.I expr
295and print the resulting value(s)
296to standard output
297(as if by
298.BR prin1 ).
299If a form produces multiple values,
300they are printed on a single line,
301separated by a single space character;
302if a form produces no values at all,
303then nothing is printed \(en not even a newline character.
304This option causes
305.B runlisp
306to execute in
307.I eval
308mode.
309.
310.TP
311.B "\-q"
312Don't print warning messages.
313This option may be repeated:
314each use reduces verbosity by one step,
315counteracting one
316.RB ` \-v '
317option.
318The default verbosity level is 1,
319which prints only warning measages.
320.
321.TP
322.B "\-v"
323Print informational or debugging messages.
324This option may be repeated:
325each use increases verbosity by one step,
326counteracting one
327.RB ` \-q '
328option.
329The default verbosity level is 1,
330which prints only warning measages.
331Higher verbosity levels print informational and debugging messages.
332.
333.PP
334The
335.RB ` \-e ',
336.RB ` \-l ',
337and
338.RB ` \-p '
339options may only be given on the command-line itself,
340not following a
341.RB `@ RUNLISP: '
342marker in a script,
343in a configuration file,
344or in the
345.B RUNLISP_OPTIONS
346environment variable.
347These options may be given multiple times:
348they will be processed in the order given.
349If any of these options is given, then no
350.I script
351name will be parsed;
352instead, use
353.RB ` \-l '
354to load code from files.
355The
356.IR arguments ,
357if any,
358are still made available to the evaluated forms and loaded files.
359.
360.SS "Operation"
361The
362.B runlisp
363program behaves as follows.
364.PP
365The first thing it does is parse its command line.
366Options must precede positional arguments,
367though the boundary may be marked explicitly using
368.RB ` \-\- '
369if desired.
370If the command line contains any of
371.RB ` \-e ',
372.RB ` \-l ',
373or
374.RB ` \-p ',
375then
376.B runlisp
377treats all of its positional arguments as
378.I arguments
379to provide to the given forms and files,
380and runs in
381.I eval
382mode;
383otherwise, the first positional argument becomes the
384.I script
385name, the remaining ones become
386.IR arguments ,
387and
388.B runlisp
389runs in
390.I script
391mode.
392.PP
393In
394.I script
395mode,
396.B runlisp
397reads the second line of the script file,
398and checks to see if it contains the string
399.RB ` @RUNLISP: '.
400If so, then the following text is parsed
401for
402.IR "embedded options" ,
403as follows.
404The text is split into words
405separated by sequences of whitespace characters.
406Whitespace,
407and other special characters,
408can be included in a word by
409.I quoting
410or
411.IR escaping .
412Text between single quotes
413.BR ' ... '
414is included literally, without any further interpretation;
415text between double quotes
416.BR """" ... """"
417is treated literally,
418except that escaping can still be used
419to escape (e.g.) double quotes and the escape character itself.
420Outside of single quotes, a backslash
421.RB ` \e '
422causes the following character to be included in a word
423regardless of its usual meaning.
424(None of this allows a newline character
425to be included in a word:
426this is simply not possible.)
427A word which is
428.RB ` \-\- '
429before processing quoting and escaping
430marks the end of embedded options.
431As a concession to Emacs users,
432if the sequence
433.RB ` \-*\- '
434appears at the start of a word
435before processing quoting and escaping,
436then everything up to and including the next occurrence of
437.RB ` \-*\- '
438is ignored.
439The resulting list of words
440is processed as if it held further command-line options.
441However,
442.B runlisp
443is now committed to
444.I script
445mode, so
446.RB ` \-e ',
447.RB ` \-l ',
448and
449.RB ` \-p '
450options may not appear in a script file's embedded options list.
451(This feature allows scripts to provide options even if they use
452.BR env (1)
453to find
454.B runlisp
455on the
456.BR PATH ,
457or to provide more than one option,
458since many operating systems pass the text following
459the interpreter name on a
460.RB ` #! '
461line as a single argument, without further splitting it at spaces.)
462.PP
463If a file named
464.B .runlisprc
465exists in the user's home directory,
466then this file is read to discover more options.
467(If the variable
468.B HOME
469is set in the environment,
470then its value is assumed to name the user's home directory;
471otherwise, the home directory is determined by looking up
472the process's real uid in the password database.)
473Lines consisting entirely of whitespace,
474and lines whose first whitespace character is either
475.RB ` # '
476or
477.RB ` ; '
478are ignored in this file.
479Other lines are split into words,
480and processed as additional command-line options,
481as described for embedded options above,
482except that:
483a
484.RB ` \-\- '
485marker does not terminate word splitting; and
486Emacs-style
487.RB ` \-*\- ... \-*\- '
488local variable lists are not ignored.
489Each line is processed separately,
490so an option and its argument must be written on the same line.
491By this point
492.B runlisp
493will have committed to
494.I script
495or
496.I eval
497mode,
498so
499.RB ` \-e ',
500.RB ` \-l ',
501and
502.RB ` \-p '
503options may not appear in a configuration file.
504.PP
505If a file
506.B runlisprc
507exists in the user's
508.I "configuration home"
509directory,
510then it is processed as for
511.B .runlisprc
512above.
513If a variable
514.B XDG_CONFIG_HOME
515is set in the environment,
516then its value is assumed to name the configuration home;
517otherwise, the configuration home is the directory
518.B .config
519in the user's home directory, as determined above.
520.PP
521If the variable
522.B RUNLISP_OPTIONS
523is set in the environment,
524then its value is split into words
525and processed as additional command-line options,
526as for a line of a configuration file as described above.
527.PP
528The list of
529.I "acceptable Lisp implementations"
530is determined.
531If any
532.RB ` \-L '
533options have been issued,
534then the list of acceptable implementations
535consists of all of the implementations mentioned in
536.RB ` -L '
537options
538in any of the places
539.B runlisp
540looked for options,
541in the order of their first occurrence.
542(If an implementation is named more than once,
543then
544.B runlisp
545prints a warning to stderr
546and ignores all but the first occurrence.)
547If no
548.RB ` \-L '
549option is given, then
550.B runlisp
551uses a default list,
552which consists of all of the supported Lisp implementations
553in an hardcoded order which reflects
554the author's arbitrary preferences.
555.PP
556The list of
557.I "preferred Lisp implementations"
558is determined.
559If any
560.RB ` \-P '
561options have been issued
562.I "since the last"
563.IB ` \-C '
564.IR "option" ,
565then the list of preferred implementations
566consists of all of the implementations mentioned in
567.RB ` \-P '
568options after the last occurrence of
569.RB ` \-C ',
570in the order of their first occurrences.
571(If an implementation is named more than once,
572then
573.B runlisp
574prints a warning to stderr
575and ignores all but the first occurrence.)
576If no
577.RB ` \-P '
578option is given,
579or a
580.RB ` \-C '
581option appears after all of the
582.RB ` \-P '
583options,
584then the list of preferred implementations is empty.
585.PP
586Acceptable Lisp implementations are tried in turn.
587First, the preferred implementations
588which are also listed as acceptable implementations
589are tried, in the order in which they appear
590in the preferred implementations list;
591then, the remaining acceptable implementations are tried
592in the order in which they appear
593in the acceptable implementations list.
594To
595.I try
596a Lisp implementation means to construct a command line
597(whose effect will be described below)
598and pass it to the
599.BR execvp (3)
600function.
601If that succeeds, the Lisp implementation runs;
602if it fails with
603.B ENOENT
604then other Lisp systems are tried;
605if it fails with some other error, then
606.B runlisp
607reports an error message to stderr
608and exits unsuccessfully
609(with code 127).
610If the
611.RB ` \-n '
612option was given, then
613.B runlisp
614just simulates the behaviour of
615.BR execvp (3),
616printing messages to stderr
617if the verbosity level is sufficiently high,
618and exits.
619.PP
620In
621.I script
622mode,
623the script is invoked.
624In
625.I eval
626mode,
627the instructions given in
628.RB ` \-e ',
629.RB ` \-l ',
630and
631.RB ` \-p '
632options are carried out,
633in the order in which the appeared in the command line.
634The details of the environment
635in which Lisp code is executed
636are described next.
637.
638.SS "Script environment"
639Code in scripts and forms invoked by
640.B runlisp
641may assume the following facts about their environment.
642.hP \*o
643The keyword
644.B :runlisp-script
645is added to the
646.B *features*
647list if
648.B runlisp
649is running in
650.I script
651mode.
652.hP \*o
653Most Lisp systems support a user initialization file
654which they load before entering the REPL;
655some also have a system initialization file.
656The
657.B runlisp
658program arranges
659.I not
660to read these files,
661so that the Lisp environment is reasonably predictable,
662and to avoid slowing down script startup
663with things which are convenient for use in an interactive session,
664but can't be relied upon by a script anyway.
665.hP \*o
666The Unix standard input, standard output, and standard error files
667are available through the Lisp
668.BR *standard-input* ,
669.BR *standard-output* ,
670and
671.BR *error-output*
672streams, respectively.
673.hP \*o
674Both
675.B *compile-verbose*
676and
677.B *load-verbose*
678are set to nil.
679On CMU\ CL,
680.B ext:*require-verbose*
681is also nil.
682Alas, this is insufficient to muffle noise while loading add-on systems
683on some implementations.
684.hP \*o
685If an error is signalled, and not caught by user code,
686then the process will print a message to stderr
687and exit with a nonzero status.
688The reported message may be a long, ugly backtrace,
689or a terse error report.
690If no error is signalled but not caught,
691then the process will exit with status 0.
692.hP \*o
693The initial package is
694.BR COMMON-LISP-USER ,
695which has no symbols `present' (i.e., imported or interned).
696.hP \*o
697The
698.B asdf
699and
700.B uiop
701systems are already loaded.
702Further systems can be loaded using
703.B asdf:load-system
704as usual.
705The script name
706(which is only meaningful if
707.B runlisp
708is in
709.I script
710mode, obviously)
711and arguments are available through the
712.B uiop:argv0
713function and
714.B uiop:*command-line-arguments*
715variable, respectively.
716.
717.\"--------------------------------------------------------------------------
718.
719.SH "BUGS"
720.hP \*o
721Loading ASDF systems is irritatingly noisy
722with some Lisp implementations.
723Suggestions for how to improve this are welcome.
724.hP \*o
725More Lisp implementations should be supported.
726I've supported the ones I have installed.
727I'm not willing to put a great deal of effort into supporting
728non-free Lisp implementations;
729but help supporting free Lisps is much appreciated.
730.hP \*o
731The protocol for passing the script name through to
732.B uiop
733(specifically, through the
734.B __CL_ARGV0
735environment variable)
736is terribly fragile,
737but supporting
738.B uiop
739is obviously a better approach than introducing a
740.BR runlisp -specific
741interface to the same information.
742I don't know how to fix this:
743suggestions are welcome.
744.
745.SH "SEE ALSO"
746.BR dump-runlisp-image (1).
747.
748.SH "AUTHOR"
749Mark Wooding, <mdw@distorted.org.uk>
750.
751.\"----- That's all, folks --------------------------------------------------