2 # aside from this initial boilerplate, this is actually -*- scheme -*- code
3 main
='(module-ref (resolve-module '\''(scripts generate-autoload)) '\'main
')'
4 exec ${GUILE-guile} -c "(apply $main (cdr (command-line)))" "$@"
6 ;;; generate-autoload
--- Display define-module form with autoload info
8 ;; Copyright
(C
) 2001 Free Software Foundation
, Inc.
10 ;; This program is free software
; you can redistribute it and
/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation
; either version
2, or
13 ;; (at your option
) any later version.
15 ;; This program is distributed
in the hope that it will be useful
,
16 ;; but WITHOUT ANY WARRANTY
; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License
for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this software
; see the
file COPYING. If not
, write to
22 ;; the Free Software Foundation
, Inc.
, 59 Temple Place
, Suite
330,
23 ;; Boston
, MA
02111-1307 USA
25 ;;; Author
: Thien-Thi Nguyen
29 ;; Usage
: generate-autoload
[OPTIONS
] FILE1 FILE2 ...
31 ;; The autoload form is displayed to standard output
:
33 ;; (define-module
(guile-user
)
34 ;; :autoload
(ZAR FOO
) (FOO-1 FOO-2 ...
)
37 ;; :autoload
(ZAR BAR
) (BAR-1 BAR-2 ...
))
39 ;; For each
file, a symbol triggers an autoload
if it is found
in one
40 ;; of these situations
:
41 ;; - in the
`:export' clause of a `define-module
' form;
42 ;; - in a top-level `export' or
`export-syntax' form;
43 ;; - in a `define-public
' form.
45 ;; The module name is inferred from the `define-module' form. If either the
46 ;; module name or the exports list cannot be determined
, no autoload entry is
47 ;; generated
for that
file.
50 ;; --target MODULE-NAME
-- Use MODULE-NAME instead of
`(guile-user)'.
51 ;; Note that some shells may require you to
52 ;; quote the argument to handle parentheses
55 ;; Usage examples from Scheme code as a module:
56 ;; (use-modules (scripts generate-autoload))
57 ;; (generate-autoload "generate-autoload")
58 ;; (generate-autoload "--target" "(my module)" "generate-autoload")
59 ;; (apply generate-autoload "--target" "(my module)" '("foo" "bar" "baz"))
63 (define-module (scripts generate-autoload)
64 :export (generate-autoload))
66 (define (autoload-info file)
67 (let ((p (open-input-file file)))
68 (let loop ((form (read p)) (module-name #f) (exports '()))
69 (if (eof-object? form)
72 (list module-name exports)) ; ret
73 (cond ((and (list? form)
75 (eq? 'define-module (car form)))
78 (cond ((member ':export form)
80 (append (cadr val) exports)))
84 (memq (car form) '(export export-syntax)))
87 (append (cdr form) exports)))
90 (eq? 'define-public (car form))
92 (symbol? (caadr form)))
95 (cons (caadr form) exports)))
98 (eq? 'define-public (car form))
99 (symbol? (cadr form)))
102 (cons (cadr form) exports)))
103 (else (loop (read p) module-name exports)))))))
105 (define (generate-autoload . args)
106 (let* ((module-count 0)
108 (target-override (cond ((member "--target" args) => cadr)
110 (files (if target-override (cddr args) (cdr args))))
111 (display ";;; do not edit --- generated ")
112 (display (strftime "%Y-%m-%d %H:%M:%S" (localtime (current-time))))
114 (display "(define-module ")
115 (display (or target-override "(guile-user)"))
116 (for-each (lambda (file)
117 (cond ((autoload-info file)
120 (apply (lambda (module-name exports)
121 (set! module-count (1+ module-count))
122 (set! syms-count (+ (length exports)
125 (list "\n :autoload "
132 (for-each display (list " ;;; "
133 syms-count " symbols in "
134 module-count " modules\n"))))
136 (define main generate-autoload)
138 ;;; generate-autoload ends here