4 (use-modules (figl parse)
7 ((srfi srfi-1) #:select (append-map))
14 (print-disable 'escape-newlines)
16 (define (module-name->scm-name mod-name)
19 (string-append (string-join (map symbol->string mod-name) "/")
22 (define (module-name->texi-name mod-name)
24 (in-vicinity (abs-top-srcdir) "doc")
25 (string-append (string-join (map symbol->string (cdr mod-name)) "-")
28 (define (unique-copyrights defs)
29 (let lp ((in defs) (out '()))
32 (let ((copyright (gl-definition-copyright (car in))))
34 (if (member copyright out)
36 (cons copyright out)))))))
38 (define (write-scm mod-name defs port)
40 ;;; figl -*- mode: scheme; coding: utf-8 -*-
41 ;;; Copyright (C) 2013 Andy Wingo <wingo@pobox.com>
43 ;;; Figl is free software: you can redistribute it and/or modify it
44 ;;; under the terms of the GNU Lesser General Public License as
45 ;;; published by the Free Software Foundation, either version 3 of the
46 ;;; License, or (at your option) any later version.
48 ;;; Figl is distributed in the hope that it will be useful, but WITHOUT
49 ;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
50 ;;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
51 ;;; Public License for more details.
53 ;;; You should have received a copy of the GNU Lesser General Public
54 ;;; License along with this program. If not, see
55 ;;; <http://www.gnu.org/licenses/>.
57 ;;; Derived from upstream OpenGL documentation.
63 (for-each (lambda (line)
68 (string-trim-both (stexi->plain-text copyright))
70 (unique-copyrights defs))
73 ;;; Automatically generated; you probably don't want to edit this. To
74 ;;; update, run \"make update\" in the top-level build tree.
79 `(define-module ,mod-name
80 #:use-module (figl low-level support)
81 #:export ,(map (lambda (def)
82 (string->symbol (gl-definition-name def)))
89 `(define-gl-procedure ,(string->symbol (gl-definition-name def))
90 ,(gl-definition-name def)
91 ,(gl-definition-prototype def)
95 (gl-definition-documentation def)))
96 ',(gl-definition-documentation def))
101 (define (write-texi mod-name defs port)
105 (para "The functions from this section may be had by loading "
107 (example "(use-modules " ,(object->string mod-name) ")")
110 "This section of the manual was derived from the upstream "
111 "OpenGL documentation. Each function's documentation has "
112 "its own copyright statement; for full details, see the "
113 "upstream documentation. The copyright notices and licenses "
114 "present in this section are as follows.")
115 ,@(append-map cdr (unique-copyrights defs)))
118 `(defun (% (name ,(gl-definition-name def))
119 ;; FIXME: proper prototype.
120 ;; (gl-definition-prototype def)
122 ,@(cdr (gl-definition-documentation def))))
126 (define (write-bindings mod-name defs)
127 (call-with-output-file (module-name->scm-name mod-name)
129 (write-scm mod-name defs port)))
130 (call-with-output-file (module-name->texi-name mod-name)
132 (write-texi mod-name defs port))))
134 (define (partition-definitions version)
136 (lambda (def gl glu glx)
138 ((string-prefix? "glu" (gl-definition-name def))
139 (values gl (cons def glu) glx))
140 ((string-prefix? "glX" (gl-definition-name def))
141 (values gl glu (cons def glx)))
143 (values (cons def gl) glu glx))))
144 (parse-gl-definitions version)
149 (define* (main arg0 #:optional (version "2"))
151 (lambda () (partition-definitions version))
153 (write-bindings '(figl low-level gl) (reverse gl))
154 (write-bindings '(figl low-level glu) (reverse glu))
155 (write-bindings '(figl low-level glx) (reverse glx)))))
158 (apply main (command-line)))