(define-module (scripts compile)
#:use-module ((system base compile) #:select (compile-file))
#:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-13)
#:use-module (srfi srfi-37)
#:export (compile))
\f
+(define (fail . messages)
+ (format (current-error-port)
+ (string-concatenate `("error: " ,@messages "~%")))
+ (exit 1))
+
(define %options
;; Specifications of the command-line options.
(list (option '(#\h "help") #f #f
(let ((load-path (assoc-ref result 'load-path)))
(alist-cons 'load-path (cons arg load-path)
result))))
+ (option '(#\o "output") #t #f
+ (lambda (opt name arg result)
+ (if (assoc-ref result 'output-file)
+ (fail "`-o' option cannot be specified more than once")
+ (alist-cons 'output-file arg result))))
+
(option '(#\O "optimize") #f #f
(lambda (opt name arg result)
(alist-cons 'optimize? #t result)))
(translate-only? (assoc-ref options 'translate-only?))
(compile-only? (assoc-ref options 'compile-only?))
(input-files (assoc-ref options 'input-files))
+ (output-file (assoc-ref options 'output-file))
(load-path (assoc-ref options 'load-path)))
(if (or help? (null? input-files))
(begin
-h, --help print this help message
-L, --load-path=DIR add DIR to the front of the module load path
+ -o, --output=OFILE write output to OFILE
+
-O, --optimize turn on optimizations
-e, --expand-only only go through the code expansion stage
-t, --translate-only stop after the translation to GHIL
(if expand-only? '(#:e) '())
(if translate-only? '(#:t) '())
(if compile-only? '(#:c) '()))))
- (for-each (lambda (file)
- (apply compile-file file compile-opts))
- input-files))))
+ (if output-file
+ (if (and (not (null? input-files))
+ (null? (cdr input-files)))
+ (compile-file (car input-files) output-file)
+ (fail "`-o' option can only be specified "
+ "when compiling a single file"))
+ (for-each (lambda (file)
+ (apply compile-file file compile-opts))
+ input-files)))))
;;; Local Variables:
;;; coding: latin-1