~fitzsim/cl-starter-script

adf4681b30da88a772acef5ddc2eaf12be6cdc7c — Thomas Fitzsimmons 1 year, 4 months ago 6deae62 main
Add section header comments
1 files changed, 15 insertions(+), 4 deletions(-)

M start.lisp
M start.lisp => start.lisp +15 -4
@@ 6,16 6,20 @@ type ecl   >/dev/null 2>&1 && exec ecl   --shell  "$0" "$@"
echo "Install one of (sbcl clisp ecl)."; exit 1
Copyright 2021-2022 Thomas Fitzsimmons
SPDX-License-Identifier: Apache-2.0 |#

;; Scripting boilerplate.
(cl:in-package #:cl-user) ; for systems that assume :cl is :use'd at load time
(setf *compile-verbose* nil *compile-print* nil *load-verbose* nil) ; silence
(setf *compile-verbose* nil *compile-print* nil *load-verbose* nil ; silence
      *load-pathname* (truename *load-pathname*)) ; for :here
(defconstant *program-name* (pathname-name *load-truename*))
(defconstant *program-package* (string-upcase *program-name*))
(require "asdf") (setf *load-pathname* (truename *load-pathname*)) ; for :here
(defconstant *program-package* (string-upcase *program-name*)) (require "asdf")
(let ((dot '(:source-registry :ignore-inherited-configuration (:tree :here))))
  (asdf:initialize-source-registry dot)) ; use Git submodules
(with-output-to-string (*standard-output*) ; suppress warnings
  (asdf:load-systems :unix-opts :with-user-abort))
(eval `(defpackage ,*program-package*)) (eval `(in-package ,*program-package*))

;; Command-line options.
(opts:define-opts
  (:name :help :description "print this help text" :short #\h :long "help")
  (:name :verbose :description "verbose output" :short #\v :long "verbose")


@@ 23,7 27,9 @@ SPDX-License-Identifier: Apache-2.0 |#
   :arg-parser #'cl:parse-integer :meta-var "LEVEL")
  (:name :output :description "output to FILE" :short #\o :long "output"
   :arg-parser #'cl:identity :meta-var "FILE"))
(cl:defun main () "Entry point for the script."

;; Main function.
(cl:defun main () "Main function for script, and binary's entry-point."
  (cl:let ((name (uiop:argv0)))
    (cl:multiple-value-bind (options arguments) (opts:get-opts)
      (cl:cond


@@ 40,14 46,19 @@ SPDX-License-Identifier: Apache-2.0 |#
              (cl:dolist (option options) (cl:print option)) (cl:terpri)
              (cl:format cl:t "Remainder:~22T~A~%" arguments))))
    (cl:when name (uiop:quit))))

;; Compilation logic.
(cl:let ((name (uiop:argv0)) (out cl-user::*program-name*)
         (package cl-user::*program-package*))
  (cl:when (cl:and name (cl:equal (cl:file-namestring name) "compile.lisp"))
    (cl:setf uiop:*image-entry-point* (cl:intern "MAIN" package))
    (uiop:dump-image out :executable cl:t) ; not supported on ECL.
    (uiop:quit)))

;; Shell script logic.
(cl:when (uiop:argv0) (cl:handler-case (with-user-abort:with-user-abort (main))
                        (with-user-abort:user-abort () (uiop:quit 1))))

;;; Local Variables:
;;; mode: Lisp
;;; syntax: ANSI-Common-Lisp