2008-08-27 17:17:30 -07:00
|
|
|
|
;;; Compile --- Command-line Guile Scheme compiler
|
|
|
|
|
|
|
2009-02-20 16:11:49 +01:00
|
|
|
|
;; Copyright 2005,2008,2009 Free Software Foundation, Inc.
|
2008-08-27 17:17:30 -07:00
|
|
|
|
;;
|
|
|
|
|
|
;; This program is free software; you can redistribute it and/or
|
2009-06-17 22:30:26 +01:00
|
|
|
|
;; modify it under the terms of the GNU Lesser General Public License
|
|
|
|
|
|
;; as published by the Free Software Foundation; either version 3, or
|
2008-08-27 17:17:30 -07:00
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2009-06-17 22:30:26 +01:00
|
|
|
|
;; Lesser General Public License for more details.
|
2008-08-27 17:17:30 -07:00
|
|
|
|
;;
|
2009-06-17 22:30:26 +01:00
|
|
|
|
;; You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
|
;; License along with this software; see the file COPYING.LESSER. If
|
|
|
|
|
|
;; not, write to the Free Software Foundation, Inc., 51 Franklin
|
|
|
|
|
|
;; Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2008-08-27 17:17:30 -07:00
|
|
|
|
|
2009-02-20 16:11:49 +01:00
|
|
|
|
;;; Author: Ludovic Court<72>s <ludo@gnu.org>
|
2008-08-27 17:17:30 -07:00
|
|
|
|
;;; Author: Andy Wingo <wingo@pobox.com>
|
|
|
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
|
|
;; Usage: compile [ARGS]
|
|
|
|
|
|
;;
|
2009-04-16 17:49:59 +02:00
|
|
|
|
;; A command-line interface to the Guile compiler.
|
2008-08-27 17:17:30 -07:00
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
|
|
|
|
(define-module (scripts compile)
|
2009-02-20 16:11:49 +01:00
|
|
|
|
#:use-module ((system base compile) #:select (compile-file))
|
2009-07-31 00:06:59 +02:00
|
|
|
|
#:use-module (system base message)
|
2009-02-20 16:11:49 +01:00
|
|
|
|
#:use-module (srfi srfi-1)
|
2009-02-21 00:36:29 +01:00
|
|
|
|
#:use-module (srfi srfi-13)
|
2009-02-20 16:11:49 +01:00
|
|
|
|
#:use-module (srfi srfi-37)
|
2009-07-31 00:06:59 +02:00
|
|
|
|
#:use-module (ice-9 format)
|
2008-09-09 07:13:14 +02:00
|
|
|
|
#:export (compile))
|
2008-08-27 17:17:30 -07:00
|
|
|
|
|
2009-02-20 16:11:49 +01:00
|
|
|
|
|
2009-02-21 00:36:29 +01:00
|
|
|
|
(define (fail . messages)
|
|
|
|
|
|
(format (current-error-port)
|
|
|
|
|
|
(string-concatenate `("error: " ,@messages "~%")))
|
|
|
|
|
|
(exit 1))
|
|
|
|
|
|
|
2008-08-27 17:17:30 -07:00
|
|
|
|
(define %options
|
2009-02-20 16:11:49 +01:00
|
|
|
|
;; Specifications of the command-line options.
|
|
|
|
|
|
(list (option '(#\h "help") #f #f
|
|
|
|
|
|
(lambda (opt name arg result)
|
|
|
|
|
|
(alist-cons 'help? #t result)))
|
2008-08-27 17:17:30 -07:00
|
|
|
|
|
2009-02-20 16:19:12 +01:00
|
|
|
|
(option '(#\L "load-path") #t #f
|
|
|
|
|
|
(lambda (opt name arg result)
|
|
|
|
|
|
(let ((load-path (assoc-ref result 'load-path)))
|
|
|
|
|
|
(alist-cons 'load-path (cons arg load-path)
|
|
|
|
|
|
result))))
|
2009-02-21 00:36:29 +01:00
|
|
|
|
(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))))
|
|
|
|
|
|
|
2009-07-31 00:06:59 +02:00
|
|
|
|
(option '(#\W "warn") #t #f
|
|
|
|
|
|
(lambda (opt name arg result)
|
|
|
|
|
|
(if (string=? arg "help")
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(show-warning-help)
|
|
|
|
|
|
(exit 0))
|
|
|
|
|
|
(let ((warnings (assoc-ref result 'warnings)))
|
|
|
|
|
|
(alist-cons 'warnings
|
|
|
|
|
|
(cons (string->symbol arg) warnings)
|
|
|
|
|
|
(alist-delete 'warnings result))))))
|
|
|
|
|
|
|
2009-02-20 16:11:49 +01:00
|
|
|
|
(option '(#\O "optimize") #f #f
|
|
|
|
|
|
(lambda (opt name arg result)
|
|
|
|
|
|
(alist-cons 'optimize? #t result)))
|
2009-04-16 17:49:59 +02:00
|
|
|
|
(option '(#\f "from") #t #f
|
2009-02-20 16:11:49 +01:00
|
|
|
|
(lambda (opt name arg result)
|
2009-04-16 17:49:59 +02:00
|
|
|
|
(if (assoc-ref result 'from)
|
|
|
|
|
|
(fail "`--from' option cannot be specified more than once")
|
|
|
|
|
|
(alist-cons 'from (string->symbol arg) result))))
|
|
|
|
|
|
(option '(#\t "to") #t #f
|
2009-02-20 16:11:49 +01:00
|
|
|
|
(lambda (opt name arg result)
|
2009-04-16 17:49:59 +02:00
|
|
|
|
(if (assoc-ref result 'to)
|
|
|
|
|
|
(fail "`--to' option cannot be specified more than once")
|
|
|
|
|
|
(alist-cons 'to (string->symbol arg) result))))))
|
2009-02-20 16:11:49 +01:00
|
|
|
|
|
|
|
|
|
|
(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)))
|
2009-02-20 16:19:12 +01:00
|
|
|
|
|
|
|
|
|
|
;; default option values
|
|
|
|
|
|
'((input-files)
|
2009-07-31 00:06:59 +02:00
|
|
|
|
(load-path)
|
|
|
|
|
|
(warnings unsupported-warning))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (show-warning-help)
|
|
|
|
|
|
(format #t "The available warning types are:~%~%")
|
|
|
|
|
|
(for-each (lambda (wt)
|
|
|
|
|
|
(format #t " ~22A ~A~%"
|
|
|
|
|
|
(format #f "`~A'" (warning-type-name wt))
|
|
|
|
|
|
(warning-type-description wt)))
|
|
|
|
|
|
%warning-types)
|
|
|
|
|
|
(format #t "~%"))
|
2009-02-20 16:11:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
2009-04-20 18:20:01 +02:00
|
|
|
|
(define (compile . args)
|
|
|
|
|
|
(let* ((options (parse-args args))
|
2009-02-20 16:11:49 +01:00
|
|
|
|
(help? (assoc-ref options 'help?))
|
2009-07-31 00:06:59 +02:00
|
|
|
|
(compile-opts (let ((o `(#:warnings
|
|
|
|
|
|
,(assoc-ref options 'warnings))))
|
|
|
|
|
|
(if (assoc-ref options 'optimize?)
|
|
|
|
|
|
(cons #:O o)
|
|
|
|
|
|
o)))
|
2009-04-16 17:49:59 +02:00
|
|
|
|
(from (or (assoc-ref options 'from) 'scheme))
|
|
|
|
|
|
(to (or (assoc-ref options 'to) 'objcode))
|
2009-02-20 16:19:12 +01:00
|
|
|
|
(input-files (assoc-ref options 'input-files))
|
2009-02-21 00:36:29 +01:00
|
|
|
|
(output-file (assoc-ref options 'output-file))
|
2009-02-20 16:19:12 +01:00
|
|
|
|
(load-path (assoc-ref options 'load-path)))
|
2009-02-20 16:11:49 +01:00
|
|
|
|
(if (or help? (null? input-files))
|
2008-08-27 17:17:30 -07:00
|
|
|
|
(begin
|
|
|
|
|
|
(format #t "Usage: compile [OPTION] FILE...
|
2009-04-16 17:49:59 +02:00
|
|
|
|
Compile each Guile source file FILE into a Guile object.
|
2008-08-27 17:17:30 -07:00
|
|
|
|
|
|
|
|
|
|
-h, --help print this help message
|
2009-02-20 16:19:12 +01:00
|
|
|
|
|
|
|
|
|
|
-L, --load-path=DIR add DIR to the front of the module load path
|
2009-02-21 00:36:29 +01:00
|
|
|
|
-o, --output=OFILE write output to OFILE
|
|
|
|
|
|
|
2009-07-31 00:06:59 +02:00
|
|
|
|
-W, --warn=WARNING emit warnings of type WARNING; use `--warn=help'
|
|
|
|
|
|
for a list of available warnings
|
|
|
|
|
|
|
2009-04-16 17:49:59 +02:00
|
|
|
|
-f, --from=LANG specify a source language other than `scheme'
|
|
|
|
|
|
-t, --to=LANG specify a target language other than `objcode'
|
2008-08-27 17:17:30 -07:00
|
|
|
|
|
2009-06-05 11:47:34 +02:00
|
|
|
|
Note that autocompilation will be turned off.
|
|
|
|
|
|
|
2008-08-27 17:17:30 -07:00
|
|
|
|
Report bugs to <guile-user@gnu.org>.~%")
|
|
|
|
|
|
(exit 0)))
|
|
|
|
|
|
|
2009-02-20 16:19:12 +01:00
|
|
|
|
(set! %load-path (append load-path %load-path))
|
2009-06-05 11:47:34 +02:00
|
|
|
|
(set! %load-should-autocompile #f)
|
2009-02-20 16:19:12 +01:00
|
|
|
|
|
2009-04-16 17:49:59 +02:00
|
|
|
|
(if (and output-file
|
|
|
|
|
|
(or (null? input-files)
|
|
|
|
|
|
(not (null? (cdr input-files)))))
|
|
|
|
|
|
(fail "`-o' option can only be specified "
|
|
|
|
|
|
"when compiling a single file"))
|
|
|
|
|
|
|
|
|
|
|
|
(for-each (lambda (file)
|
|
|
|
|
|
(format #t "wrote `~A'\n"
|
|
|
|
|
|
(compile-file file
|
|
|
|
|
|
#:output-file output-file
|
|
|
|
|
|
#:from from
|
|
|
|
|
|
#:to to
|
|
|
|
|
|
#:opts compile-opts)))
|
|
|
|
|
|
input-files)))
|
2009-02-20 16:11:49 +01:00
|
|
|
|
|
2009-04-17 11:19:42 +02:00
|
|
|
|
(define main compile)
|
|
|
|
|
|
|
2009-02-20 16:11:49 +01:00
|
|
|
|
;;; Local Variables:
|
|
|
|
|
|
;;; coding: latin-1
|
|
|
|
|
|
;;; End:
|