runlisp.c: Undefine local option-parsing macros at the end of the block.
[runlisp] / runlisp.1.in
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..
eea3b0c7 42.ds .. \&.\|.\|.
e29834b8
MW
43.
44.\"--------------------------------------------------------------------------
45.TH runlisp 1 "2 August 2020" "Mark Wooding"
46.SH NAME
47runlisp \- run Common Lisp programs as scripts
48.
49.\"--------------------------------------------------------------------------
50.SH SYNOPSIS
51.
52.B runlisp
10427eb2
MW
53.RI [ options ]
54.RB [ \-\- ]
55.I script
56.RI [ arguments
eea3b0c7 57\*(..]
e29834b8 58.br
10427eb2
MW
59.B runlisp
60.RI [ options ]
e29834b8 61.RB [ \-e
ee78edd0 62.IR form ]
e29834b8
MW
63.RB [ \-l
64.IR file ]
65.RB [ \-p
ee78edd0 66.IR form ]
e29834b8 67.RB [ \-\- ]
e29834b8 68.RI [ arguments
eea3b0c7 69\*(..]
10427eb2
MW
70.PP
71where
72.I options
73is
74.br
8ed4c352 75 \c
10427eb2
MW
76.RB [ \-CDEnqv ]
77.RB [ +DEn ]
78.RB [ \-L
eea3b0c7 79.IB sys , sys , \fR\*(..]
8ed4c352
MW
80.if !t \{\
81.br
82 \c
83.\}
10427eb2
MW
84.RB [ \-c
85.IR conf ]
86.RB [ \-o
87.RI [ sect \c
88.BR : ] \c
89.IB var = \c
90.IR value ]
e29834b8
MW
91.
92.\"--------------------------------------------------------------------------
93.SH DESCRIPTION
94.
95The
96.B runlisp
97program has two main functions.
98.hP 1.
99It can be used in a script's
100.RB ` #! '
101line to run a Common Lisp script.
102.hP 2.
103It can be used in build scripts
104to invoke a Common Lisp system,
105e.g., to build a standalone program.
106.
e29834b8
MW
107.SS "Options"
108Options are read from the command line, as usual,
10427eb2
MW
109but also (by default) from the script's second line,
110following a
e29834b8 111.RB ` @RUNLISP: '
10427eb2 112marker: see
e29834b8 113.B Operation
10427eb2 114below for the details.
e29834b8
MW
115.
116.PP
117The options accepted are as follows.
118.
119.TP
10427eb2 120.BR "\-h" ", " "\-\-help"
e29834b8 121Write a synopsis of
10427eb2 122.BR query-runlisp-config 's
e29834b8
MW
123command-line syntax
124and a description of the command-line options
125to standard output
126and immediately exit with status 0.
127.
128.TP
10427eb2 129.BR "\-V" ", " "\-\-version"
e29834b8 130Write
10427eb2 131.BR query-runlisp-config 's
e29834b8
MW
132version number
133to standard output
134and immediately exit with status 0.
135.
136.TP
10427eb2 137.BR "\-D" ", " "\-\-vanilla-image"
e29834b8
MW
138Don't check for a custom Lisp image.
139Usually,
140.B runlisp
141tries to start Lisp systems using a custom image,
142so that they'll start more quickly;
143the
144.RB ` \-D '
145option forces the use of the default `vanilla' image
146provided with the system.
147There's not usually any good reason to prefer the vanilla image,
148except for performance comparisons, or debugging
149.B runlisp
150itself.
10427eb2
MW
151Negate with
152.B +D
153or
154.BR \-\-no-vanilla-image .
e29834b8
MW
155.
156.TP
10427eb2 157.BR "\-E" ", " "\-\-command-line-only"
e29834b8
MW
158Don't read embedded options from the
159second line of the
160.I script
161file.
10427eb2
MW
162Negate with
163.B +E
164or
165.BR \-\-no-command-line-only .
e29834b8 166This has no effect in eval mode.
e29834b8
MW
167which is set at compile time.
168.
169.TP
eea3b0c7 170.BI "\-L" "\fR, " "\-\-accept-lisp=" sys , sys ,\fR\*(..
e29834b8
MW
171Use one of the named Lisp systems.
172Each
173.I sys
10427eb2
MW
174must name a supported Lisp system;
175the names are separated by a comma
176.RB ` , '
177and/or one or more whitespace characters.
e29834b8
MW
178This option may be given more than once:
179the effect is the same as a single option
180listing all of the systems named, in the same order.
181If a system is named more than once,
182a warning is issued (at verbosity level 1 or higher),
183and all but the first occurrence is ignored.
184.
185.TP
10427eb2
MW
186.BI "\-c" "\fR, " "\-\-config-file=" conf
187Read configuration from
188.IR conf .
189If
190.I conf
191is a directory, then all of the files within
192whose names end with
193.RB ` .conf ',
194are loaded, in ascending lexicographical order;
195otherwise,
196.I conf
197is opened as a file.
af677646 198All of the files are expected to be as described in
10427eb2 199.BR runlisp.conf (5).
e29834b8
MW
200.
201.TP
10427eb2 202.BI "\-e" "\fR, " "\-\-evaluate-expression=" expr
e29834b8
MW
203Evaluate the expression(s)
204.I expr
205and discard the resulting values.
206This option causes
207.B runlisp
208to execute in
209.I eval
210mode.
211.
212.TP
10427eb2 213.BI "\-l" "\fR, " "\-\-load-file=" file
e29834b8
MW
214Read and evaluate forms from the
215.IR file .
216This option causes
217.B runlisp
218to execute in
219.I eval
220mode.
221.
222.TP
bf52b6ca 223.BR "\-n" ", " "\-\-dry-run"
e29834b8
MW
224Don't actually start the Lisp environment.
225This may be helpful for the curious,
226in conjunction with
227.RB ` \-v '
228to increase the verbosity.
10427eb2
MW
229Negate with
230.B +n
231or
232.BR "\-\-no-dry-run" .
e29834b8
MW
233.
234.TP
497e5a4a
MW
235.BI "\-o" "\fR, " "\-\-set-option=\fR[" sect :\fR] var = value
236Assign
237.I value
238to the variable
239.I var
240in configuration section
241.IR sect ,
242or
243.B @CONFIG
244if no section is specified.
245The value is unexpandable,
246and overrides any similarly named setting
247from the configuration file(s).
248.
249.TP
10427eb2 250.BI "\-p" "\fR, " "\-\-print-expressin=" expr
e29834b8
MW
251Evaluate the expression(s)
252.I expr
253and print the resulting value(s)
254to standard output
255(as if by
256.BR prin1 ).
257If a form produces multiple values,
258they are printed on a single line,
259separated by a single space character;
260if a form produces no values at all,
261then nothing is printed \(en not even a newline character.
262This option causes
263.B runlisp
264to execute in
265.I eval
266mode.
267.
268.TP
10427eb2 269.BR "\-q" ", " "\-\-quiet"
e29834b8
MW
270Don't print warning messages.
271This option may be repeated:
272each use reduces verbosity by one step,
273counteracting one
274.RB ` \-v '
275option.
276The default verbosity level is 1,
277which prints only warning measages.
278.
279.TP
10427eb2 280.BR "\-v" ", " "\-\-verbose"
e29834b8
MW
281Print informational or debugging messages.
282This option may be repeated:
283each use increases verbosity by one step,
284counteracting one
285.RB ` \-q '
286option.
287The default verbosity level is 1,
288which prints only warning measages.
289Higher verbosity levels print informational and debugging messages.
290.
291.PP
292The
293.RB ` \-e ',
294.RB ` \-l ',
295and
296.RB ` \-p '
297options may only be given on the command-line itself,
298not following a
299.RB `@ RUNLISP: '
10427eb2 300marker in a script.
e29834b8
MW
301These options may be given multiple times:
302they will be processed in the order given.
303If any of these options is given, then no
304.I script
305name will be parsed;
306instead, use
307.RB ` \-l '
308to load code from files.
309The
310.IR arguments ,
10427eb2 311ppif any,
e29834b8
MW
312are still made available to the evaluated forms and loaded files.
313.
314.SS "Operation"
315The
316.B runlisp
317program behaves as follows.
10427eb2
MW
318.
319.hP 1.
e29834b8
MW
320The first thing it does is parse its command line.
321Options must precede positional arguments,
322though the boundary may be marked explicitly using
323.RB ` \-\- '
324if desired.
325If the command line contains any of
326.RB ` \-e ',
327.RB ` \-l ',
328or
329.RB ` \-p ',
330then
331.B runlisp
332treats all of its positional arguments as
333.I arguments
334to provide to the given forms and files,
335and runs in
336.I eval
337mode;
338otherwise, the first positional argument becomes the
339.I script
340name, the remaining ones become
341.IR arguments ,
342and
343.B runlisp
344runs in
345.I script
346mode.
10427eb2 347.hP 2.
e29834b8
MW
348In
349.I script
350mode,
351.B runlisp
352reads the second line of the script file,
353and checks to see if it contains the string
354.RB ` @RUNLISP: '.
355If so, then the following text is parsed
356for
357.IR "embedded options" ,
358as follows.
10427eb2
MW
359.RS
360.PP
e29834b8
MW
361The text is split into words
362separated by sequences of whitespace characters.
363Whitespace,
364and other special characters,
365can be included in a word by
366.I quoting
367or
368.IR escaping .
369Text between single quotes
eea3b0c7 370.BR ' \*(.. '
e29834b8
MW
371is included literally, without any further interpretation;
372text between double quotes
eea3b0c7 373.BR """" \*(.. """"
e29834b8
MW
374is treated literally,
375except that escaping can still be used
376to escape (e.g.) double quotes and the escape character itself.
377Outside of single quotes, a backslash
378.RB ` \e '
379causes the following character to be included in a word
380regardless of its usual meaning.
381(None of this allows a newline character
382to be included in a word:
383this is simply not possible.)
384A word which is
385.RB ` \-\- '
386before processing quoting and escaping
387marks the end of embedded options.
388As a concession to Emacs users,
389if the sequence
390.RB ` \-*\- '
391appears at the start of a word
392before processing quoting and escaping,
393then everything up to and including the next occurrence of
394.RB ` \-*\- '
395is ignored.
10427eb2 396.PP
e29834b8
MW
397The resulting list of words
398is processed as if it held further command-line options.
10427eb2
MW
399Currently, only
400.RB ` \-D '
401and
402.RB ` \-L '
403options are permitted in embedded option lists:
404.RB ` \-h '
405and
406.RB ` \-v '
407are clearly only useful in interactive use;
408setting
409.RB ` \-q '
410or
411.RB ` \-v '
412would just be annoying;
413setting
414.RB ` \-c '
415or
416.RB ` \-o '
417would override the user's command-line settings;
418it's clearly too late to set
419.RB ` \-E ';
420and
e29834b8
MW
421.B runlisp
422is now committed to
423.I script
10427eb2 424mode, so it's too late for
e29834b8
MW
425.RB ` \-e ',
426.RB ` \-l ',
427and
428.RB ` \-p '
10427eb2
MW
429too.
430.PP
e29834b8
MW
431(This feature allows scripts to provide options even if they use
432.BR env (1)
433to find
434.B runlisp
435on the
436.BR PATH ,
437or to provide more than one option,
438since many operating systems pass the text following
439the interpreter name on a
440.RB ` #! '
441line as a single argument, without further splitting it at spaces.)
10427eb2
MW
442.RE
443.
444.hP 3.
445If no
446.RB ` \-c '
447options were given,
448then the default configuration files are read:
449the system configuration from
450.B @etcdir@/runlisp.conf
e29834b8 451and
10427eb2
MW
452.BR @etcdir@/runlisp.d/*.conf ,
453and the user configuration from
454.B ~/.runlisp.conf
455and/or
456.BR ~/.config/runlisp.conf :
457see
458.RB runlisp.conf (5)
459for the details.
460.
461.hP 4.
e29834b8
MW
462The list of
463.I "acceptable Lisp implementations"
464is determined.
465If any
466.RB ` \-L '
10427eb2 467options have been found,
e29834b8
MW
468then the list of acceptable implementations
469consists of all of the implementations mentioned in
bf52b6ca 470.RB ` \-L '
e29834b8
MW
471options
472in any of the places
473.B runlisp
474looked for options,
475in the order of their first occurrence.
476(If an implementation is named more than once,
477then
478.B runlisp
479prints a warning to stderr
480and ignores all but the first occurrence.)
481If no
482.RB ` \-L '
483option is given, then
484.B runlisp
485uses a default list,
10427eb2
MW
486which consists of all of the Lisp implementations
487defined in its configuration,
488in the order in which they were defined.
489.
490.hP 5.
e29834b8
MW
491The list of
492.I "preferred Lisp implementations"
493is determined.
10427eb2
MW
494If the environment variable
495.B RUNLISP_PREFER
496is set,
497then its value should be a list of names of Lisp implementations
498separated by a comma and/or one or more whitespace characters.
499Otherwise, if there is a setting for the variable
500.B prefer
501in the
502.B @CONFIG
503configuration section,
504then its (expanded) value should be a list of Lisp implementations,
505in the same way.
506Otherwise, the list of preferred implementations is empty.
507.
508.hP 6.
509If
e29834b8 510.B runlisp
10427eb2
MW
511is running in
512.I eval
513mode, then a new command line is built,
514which invokes an internal script,
515instructing it to evaluate and print the requested expressions,
516and load the requested files.
517.
518.hP 7.
e29834b8
MW
519Acceptable Lisp implementations are tried in turn.
520First, the preferred implementations
521which are also listed as acceptable implementations
522are tried, in the order in which they appear
523in the preferred implementations list;
524then, the remaining acceptable implementations are tried
525in the order in which they appear
526in the acceptable implementations list.
10427eb2
MW
527.RS
528.PP
529A Lisp implementation is defined by a configuration section
530which defines a variable
531.BR run-script .
532The name of the configuration section
533is the name of the Lisp implementation,
534as used in the acceptable and preferred lists described above.
535.hP (a)
536The variable
537.B image-file
538is looked up in the configuration section.
539If a value is found, then
540.B runlisp
541looks up and expands
542.BR image-path ,
543and checks to see if a file exists with the resulting name.
544If so, it sets the variable
545.B @image
546to
547.B t
548in the configuration section.
549.hP (b)
550The variable
551.B run-script
552is expanded and word-split.
553The
554.I script
555(an internal script, in
556.I eval
557mode)
558and
559.IR argument s
560are appended, and
561the entire list is passed to the
e29834b8
MW
562.BR execvp (3)
563function.
564If that succeeds, the Lisp implementation runs;
565if it fails with
566.B ENOENT
567then other Lisp systems are tried;
568if it fails with some other error, then
569.B runlisp
570reports an error message to stderr
571and exits unsuccessfully
572(with code 127).
573If the
574.RB ` \-n '
575option was given, then
576.B runlisp
577just simulates the behaviour of
578.BR execvp (3),
579printing messages to stderr
580if the verbosity level is sufficiently high,
581and exits.
e29834b8
MW
582.
583.SS "Script environment"
10427eb2
MW
584Many Lisp implementations don't provide a satisfactory environment
585for scripts to run in.
586The actual task of invoking a Lisp implementation
587is left to configuration,
588but the basic configuration supplied with
e29834b8 589.B runlisp
10427eb2 590ensures the following facts about their environment.
e29834b8
MW
591.hP \*o
592The keyword
593.B :runlisp-script
594is added to the
595.B *features*
596list if
597.B runlisp
598is running in
599.I script
600mode.
601.hP \*o
602Most Lisp systems support a user initialization file
603which they load before entering the REPL;
604some also have a system initialization file.
605The
606.B runlisp
607program arranges
608.I not
609to read these files,
610so that the Lisp environment is reasonably predictable,
611and to avoid slowing down script startup
612with things which are convenient for use in an interactive session,
613but can't be relied upon by a script anyway.
614.hP \*o
615The Unix standard input, standard output, and standard error files
616are available through the Lisp
617.BR *standard-input* ,
618.BR *standard-output* ,
619and
620.BR *error-output*
621streams, respectively.
622.hP \*o
623Both
624.B *compile-verbose*
625and
626.B *load-verbose*
627are set to nil.
628On CMU\ CL,
629.B ext:*require-verbose*
630is also nil.
631Alas, this is insufficient to muffle noise while loading add-on systems
632on some implementations.
633.hP \*o
634If an error is signalled, and not caught by user code,
635then the process will print a message to stderr
636and exit with a nonzero status.
637The reported message may be a long, ugly backtrace,
638or a terse error report.
639If no error is signalled but not caught,
640then the process will exit with status 0.
641.hP \*o
642The initial package is
643.BR COMMON-LISP-USER ,
644which has no symbols `present' (i.e., imported or interned).
645.hP \*o
646The
647.B asdf
648and
649.B uiop
650systems are already loaded.
651Further systems can be loaded using
652.B asdf:load-system
653as usual.
654The script name
655(which is only meaningful if
656.B runlisp
657is in
658.I script
659mode, obviously)
660and arguments are available through the
661.B uiop:argv0
662function and
663.B uiop:*command-line-arguments*
664variable, respectively.
665.
666.\"--------------------------------------------------------------------------
667.
8996f767 668.SH BUGS
e29834b8
MW
669.hP \*o
670Loading ASDF systems is irritatingly noisy
671with some Lisp implementations.
672Suggestions for how to improve this are welcome.
673.hP \*o
674More Lisp implementations should be supported.
675I've supported the ones I have installed.
676I'm not willing to put a great deal of effort into supporting
677non-free Lisp implementations;
678but help supporting free Lisps is much appreciated.
679.hP \*o
680The protocol for passing the script name through to
681.B uiop
682(specifically, through the
683.B __CL_ARGV0
684environment variable)
685is terribly fragile,
686but supporting
687.B uiop
688is obviously a better approach than introducing a
689.BR runlisp -specific
690interface to the same information.
691I don't know how to fix this:
692suggestions are welcome.
693.
8996f767
MW
694.SH SEE ALSO
695.BR dump-runlisp-image (1),
696.BR query-runlisp-config (1),
697.BR runlisp.conf (5).
e29834b8 698.
8996f767 699.SH AUTHOR
e29834b8
MW
700Mark Wooding, <mdw@distorted.org.uk>
701.
702.\"----- That's all, folks --------------------------------------------------