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