mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-11 14:21:10 +02:00
Change "guile-tools compile" to use SRFI-37 to process options.
* scripts/compile (%options): Rewrite in SRFI-37 style. (parse-args): New procedure. (compile): Update to SRFI-37.
This commit is contained in:
parent
03d6cddc55
commit
2308dce1be
1 changed files with 50 additions and 17 deletions
|
@ -4,7 +4,7 @@ exec ${GUILE-guile} -e '(@ (scripts compile) compile)' -s $0 "$@"
|
||||||
!#
|
!#
|
||||||
;;; Compile --- Command-line Guile Scheme compiler
|
;;; Compile --- Command-line Guile Scheme compiler
|
||||||
|
|
||||||
;; Copyright 2005,2008 Free Software Foundation, Inc.
|
;; Copyright 2005,2008,2009 Free Software Foundation, Inc.
|
||||||
;;
|
;;
|
||||||
;; This program is free software; you can redistribute it and/or
|
;; This program is free software; you can redistribute it and/or
|
||||||
;; modify it under the terms of the GNU General Public License as
|
;; modify it under the terms of the GNU General Public License as
|
||||||
|
@ -21,7 +21,7 @@ exec ${GUILE-guile} -e '(@ (scripts compile) compile)' -s $0 "$@"
|
||||||
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
;; Boston, MA 02110-1301 USA
|
;; Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
;;; Author: Ludovic Courtès <ludovic.courtes@laas.fr>
|
;;; Author: Ludovic Courtès <ludo@gnu.org>
|
||||||
;;; Author: Andy Wingo <wingo@pobox.com>
|
;;; Author: Andy Wingo <wingo@pobox.com>
|
||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
|
@ -35,25 +35,54 @@ exec ${GUILE-guile} -e '(@ (scripts compile) compile)' -s $0 "$@"
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
(define-module (scripts compile)
|
(define-module (scripts compile)
|
||||||
#:use-module (system base compile)
|
#:use-module ((system base compile) #:select (compile-file))
|
||||||
#:use-module (ice-9 getopt-long)
|
#:use-module (srfi srfi-1)
|
||||||
|
#:use-module (srfi srfi-37)
|
||||||
#:export (compile))
|
#:export (compile))
|
||||||
|
|
||||||
|
|
||||||
(define %options
|
(define %options
|
||||||
'((help (single-char #\h) (value #f))
|
;; Specifications of the command-line options.
|
||||||
(optimize (single-char #\O) (value #f))
|
(list (option '(#\h "help") #f #f
|
||||||
(expand-only (single-char #\e) (value #f))
|
(lambda (opt name arg result)
|
||||||
(translate-only (single-char #\t) (value #f))
|
(alist-cons 'help? #t result)))
|
||||||
(compile-only (single-char #\c) (value #f))))
|
|
||||||
|
|
||||||
|
(option '(#\O "optimize") #f #f
|
||||||
|
(lambda (opt name arg result)
|
||||||
|
(alist-cons 'optimize? #t result)))
|
||||||
|
(option '(#\e "expand-only") #f #f
|
||||||
|
(lambda (opt name arg result)
|
||||||
|
(alist-cons 'expand-only? #t result)))
|
||||||
|
(option '(#\t "translate-only") #f #f
|
||||||
|
(lambda (opt name arg result)
|
||||||
|
(alist-cons 'translate-only? #t result)))
|
||||||
|
(option '(#\c "compile-only") #f #f
|
||||||
|
(lambda (opt name arg result)
|
||||||
|
(alist-cons 'compile-only? #t result)))))
|
||||||
|
|
||||||
|
(define (parse-args args)
|
||||||
|
"Parse argument list @var{args} and return an alist with all the relevant
|
||||||
|
options."
|
||||||
|
(args-fold args %options
|
||||||
|
(lambda (opt name arg result)
|
||||||
|
(format (current-error-port) "~A: unrecognized option" opt)
|
||||||
|
(exit 1))
|
||||||
|
(lambda (file result)
|
||||||
|
(let ((input-files (assoc-ref result 'input-files)))
|
||||||
|
(alist-cons 'input-files (cons file input-files)
|
||||||
|
result)))
|
||||||
|
'((input-files))))
|
||||||
|
|
||||||
|
|
||||||
(define (compile args)
|
(define (compile args)
|
||||||
(let* ((options (getopt-long args %options))
|
(let* ((options (parse-args (cdr args)))
|
||||||
(help? (option-ref options 'help #f))
|
(help? (assoc-ref options 'help?))
|
||||||
(optimize? (option-ref options 'optimize #f))
|
(optimize? (assoc-ref options 'optimize?))
|
||||||
(expand-only? (option-ref options 'expand-only #f))
|
(expand-only? (assoc-ref options 'expand-only?))
|
||||||
(translate-only? (option-ref options 'translate-only #f))
|
(translate-only? (assoc-ref options 'translate-only?))
|
||||||
(compile-only? (option-ref options 'compile-only #f)))
|
(compile-only? (assoc-ref options 'compile-only?))
|
||||||
(if help?
|
(input-files (assoc-ref options 'input-files)))
|
||||||
|
(if (or help? (null? input-files))
|
||||||
(begin
|
(begin
|
||||||
(format #t "Usage: compile [OPTION] FILE...
|
(format #t "Usage: compile [OPTION] FILE...
|
||||||
Compile each Guile Scheme source file FILE into a Guile object.
|
Compile each Guile Scheme source file FILE into a Guile object.
|
||||||
|
@ -73,4 +102,8 @@ Report bugs to <guile-user@gnu.org>.~%")
|
||||||
(if compile-only? '(#:c) '()))))
|
(if compile-only? '(#:c) '()))))
|
||||||
(for-each (lambda (file)
|
(for-each (lambda (file)
|
||||||
(apply compile-file file compile-opts))
|
(apply compile-file file compile-opts))
|
||||||
(option-ref options '() '())))))
|
input-files))))
|
||||||
|
|
||||||
|
;;; Local Variables:
|
||||||
|
;;; coding: latin-1
|
||||||
|
;;; End:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue