#! /bin/sh -e
-#| -*-lisp-*-
-exec sbcl --script "$0" "$0" "$@"
-|#
+":"; exec sbcl --script "$0" "$@" # -*-lisp-*-
(require 'sb-executable)
(let* ((args (cdr *posix-argv*))
- (prog (pop args))
+ (prog (pathname-name *load-pathname*))
(cmd (pop args)))
- (cond
- ((string= cmd "build")
- (let ((rc 0))
- (dolist (file args)
- (unless (compile-file file :verbose nil :print nil)
- (setf rc 1)))
- (quit :unix-status rc)))
- ((string= cmd "link")
- (let ((out (pop args)))
- (sb-executable:make-executable out args)))
- (t
- (format *error-output* "~A: unknown command `~A'~%" prog cmd)
- (quit :unix-status 1))))
+ (labels ((moan (message &rest arguments)
+ (format *error-output* "~A: ~?~%" prog message arguments))
+ (die (message &rest arguments)
+ (apply #'moan message arguments)
+ (exit :code 1)))
+ (cond
+ ((not cmd)
+ (format *error-output*
+ "Usage: ~A build SOURCE SOURCE ...~%~
+ ~0~ ~:*~A link OUTPUT FASL FASL ...~%"
+ prog)
+ (exit :code 1))
+ ((string= cmd "build")
+ (let ((rc 0))
+ (dolist (file args)
+ (unless (handler-case (compile-file file :verbose nil :print nil)
+ (error (cond)
+ (moan "failed to compile `~A':~%~8T~A" file cond)))
+ (setf rc 1)))
+ (exit :code rc)))
+ ((string= cmd "link")
+ (let ((out (pop args)))
+ (handler-case (sb-executable:make-executable out args)
+ (error (cond)
+ (die "failed to make executable:~%~8T~A" cond)))))
+ (t
+ (die "unknown command `~A'" cmd)))))