1 ;;; generate-autoload --- Display define-module form with autoload info
3 ;; Copyright (C) 2001, 2006, 2011 Free Software Foundation, Inc.
5 ;; This program is free software; you can redistribute it and/or
6 ;; modify it under the terms of the GNU Lesser General Public License
7 ;; as published by the Free Software Foundation; either version 3, or
8 ;; (at your option) any later version.
10 ;; This program is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ;; Lesser General Public License for more details.
15 ;; You should have received a copy of the GNU Lesser General Public
16 ;; License along with this software; see the file COPYING.LESSER. If
17 ;; not, write to the Free Software Foundation, Inc., 51 Franklin
18 ;; Street, Fifth Floor, Boston, MA 02110-1301 USA
20 ;;; Author: Thien-Thi Nguyen
24 ;; Usage: generate-autoload [OPTIONS] FILE1 FILE2 ...
26 ;; The autoload form is displayed to standard output:
28 ;; (define-module (guile-user)
29 ;; :autoload (ZAR FOO) (FOO-1 FOO-2 ...)
32 ;; :autoload (ZAR BAR) (BAR-1 BAR-2 ...))
34 ;; For each file, a symbol triggers an autoload if it is found in one
35 ;; of these situations:
36 ;; - in the `:export' clause of a `define-module' form
37 ;; - in a top-level `export' or `export-syntax' form
38 ;; - in a `define-public' form
39 ;; - in a `defmacro-public' form
41 ;; The module name is inferred from the `define-module' form. If either the
42 ;; module name or the exports list cannot be determined, no autoload entry is
43 ;; generated for that file.
46 ;; --target MODULE-NAME -- Use MODULE-NAME instead of `(guile-user)'.
47 ;; Note that some shells may require you to
48 ;; quote the argument to handle parentheses
51 ;; Usage examples from Scheme code as a module:
52 ;; (use-modules (scripts generate-autoload))
53 ;; (generate-autoload "generate-autoload")
54 ;; (generate-autoload "--target" "(my module)" "generate-autoload")
55 ;; (apply generate-autoload "--target" "(my module)" '("foo" "bar" "baz"))
59 (define-module (scripts generate-autoload)
60 :export (generate-autoload))
62 (define %include-in-guild-list #f)
63 (define %summary "Generate #:autoload clauses for a module.")
65 (define (autoload-info file)
66 (let ((p (open-input-file file)))
67 (let loop ((form (read p)) (module-name #f) (exports '()))
68 (if (eof-object? form)
71 (list module-name exports)) ; ret
72 (cond ((and (list? form)
74 (eq? 'define-module (car form)))
77 (cond ((member ':export form)
79 (append (cadr val) exports)))
83 (memq (car form) '(export export-syntax)))
86 (append (cdr form) exports)))
89 (eq? 'define-public (car form))
91 (symbol? (caadr form)))
94 (cons (caadr form) exports)))
97 (eq? 'define-public (car form))
98 (symbol? (cadr form)))
101 (cons (cadr form) exports)))
104 (eq? 'defmacro-public (car form))
105 (symbol? (cadr form)))
108 (cons (cadr form) exports)))
109 (else (loop (read p) module-name exports)))))))
111 (define (generate-autoload . args)
112 (let* ((module-count 0)
114 (target-override (cond ((member "--target" args) => cadr)
116 (files (if target-override (cddr args) (cdr args))))
117 (display ";;; do not edit --- generated ")
118 (display (strftime "%Y-%m-%d %H:%M:%S" (localtime (current-time))))
120 (display "(define-module ")
121 (display (or target-override "(guile-user)"))
122 (for-each (lambda (file)
123 (cond ((autoload-info file)
126 (apply (lambda (module-name exports)
127 (set! module-count (1+ module-count))
128 (set! syms-count (+ (length exports)
131 (list "\n :autoload "
138 (for-each display (list " ;;; "
139 syms-count " symbols in "
140 module-count " modules\n"))))
142 (define main generate-autoload)
144 ;;; generate-autoload ends here