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} -l $0 -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.
, 51 Franklin Street
, Fifth Floor
,
23 ;; Boston
, MA
02110-1301 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
44 ;; - in a `defmacro-public' form
46 ;; The module name is inferred from the
`define-module' form. If either the
47 ;; module name or the exports list cannot be determined, no autoload entry is
48 ;; generated for that file.
51 ;; --target MODULE-NAME -- Use MODULE-NAME instead of `(guile-user
)'.
52 ;; Note that some shells may require you to
53 ;; quote the argument to handle parentheses
56 ;; Usage examples from Scheme code as a module:
57 ;; (use-modules (scripts generate-autoload))
58 ;; (generate-autoload "generate-autoload")
59 ;; (generate-autoload "--target" "(my module)" "generate-autoload")
60 ;; (apply generate-autoload "--target" "(my module)" '("foo" "bar" "baz"))
64 (define-module
(scripts generate-autoload
)
65 :export (generate-autoload
))
67 (define
(autoload-info
file)
68 (let ((p
(open-input-file
file)))
69 (let loop
((form
(read p
)) (module-name
#f) (exports '()))
70 (if (eof-object? form
)
73 (list module-name exports
)) ; ret
74 (cond
((and
(list? form
)
76 (eq?
'define-module (car form)))
79 (cond ((member ':export form
)
81 (append
(cadr val
) exports
)))
85 (memq
(car form
) '(export export-syntax)))
88 (append (cdr form) exports)))
91 (eq? 'define-public
(car form
))
93 (symbol?
(caadr form
)))
96 (cons
(caadr form
) exports
)))
99 (eq?
'define-public (car form))
100 (symbol? (cadr form)))
103 (cons (cadr form) exports)))
106 (eq? 'defmacro-public
(car form
))
107 (symbol?
(cadr form
)))
110 (cons
(cadr form
) exports
)))
111 (else (loop
(read p
) module-name exports
)))))))
113 (define
(generate-autoload . args
)
114 (let* ((module-count
0)
116 (target-override
(cond
((member
"--target" args
) => cadr
)
118 (files
(if target-override
(cddr args
) (cdr args
))))
119 (display
";;; do not edit --- generated ")
120 (display
(strftime
"%Y-%m-%d %H:%M:%S" (localtime
(current-time
))))
122 (display
"(define-module ")
123 (display
(or target-override
"(guile-user)"))
124 (for-each
(lambda
(file)
125 (cond
((autoload-info
file)
128 (apply
(lambda
(module-name exports
)
129 (set! module-count
(1+ module-count
))
130 (set! syms-count
(+ (length exports
)
133 (list
"\n :autoload "
140 (for-each display
(list
" ;;; "
141 syms-count
" symbols in "
142 module-count
" modules\n"))))
144 (define main generate-autoload
)
146 ;;; generate-autoload ends here