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