apple: Rename __gl_api to __ogl_framework_api
[mesa.git] / src / glx / apple / gen_api_library.tcl
1 package require Tcl 8.5
2
3 set license {
4 /*
5 Copyright (c) 2008, 2009 Apple Inc.
6
7 Permission is hereby granted, free of charge, to any person
8 obtaining a copy of this software and associated documentation files
9 (the "Software"), to deal in the Software without restriction,
10 including without limitation the rights to use, copy, modify, merge,
11 publish, distribute, sublicense, and/or sell copies of the Software,
12 and to permit persons to whom the Software is furnished to do so,
13 subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
22 HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 DEALINGS IN THE SOFTWARE.
26
27 Except as contained in this notice, the name(s) of the above
28 copyright holders shall not be used in advertising or otherwise to
29 promote the sale, use or other dealings in this Software without
30 prior written authorization.
31 */
32 }
33
34 set gl_license {
35 /*
36 ** License Applicability. Except to the extent portions of this file are
37 ** made subject to an alternative license as permitted in the SGI Free
38 ** Software License B, Version 1.1 (the "License"), the contents of this
39 ** file are subject only to the provisions of the License. You may not use
40 ** this file except in compliance with the License. You may obtain a copy
41 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
42 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
43 **
44 ** http://oss.sgi.com/projects/FreeB
45 **
46 ** Note that, as provided in the License, the Software is distributed on an
47 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
48 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
49 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
50 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
51 **
52 ** Original Code. The Original Code is: OpenGL Sample Implementation,
53 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
54 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
55 ** Copyright in any portions created by third parties is as indicated
56 ** elsewhere herein. All Rights Reserved.
57 **
58 ** Additional Notice Provisions: This software was created using the
59 ** OpenGL(R) version 1.2.1 Sample Implementation published by SGI, but has
60 ** not been independently verified as being compliant with the OpenGL(R)
61 ** version 1.2.1 Specification.
62 */
63 }
64
65 set init_code {
66 static void *glsym(void *handle, const char *name) {
67 void *sym = dlsym(handle, name);
68
69 if(NULL == sym) {
70 fprintf(stderr, "Error: symbol not found: '%s'. "
71 "Error information: %s\n",
72 name, dlerror());
73 abort();
74 }
75
76 return sym;
77 }
78
79 }
80
81 set dlopen_code {
82 #ifndef LIBGLNAME
83 #define LIBGLNAME "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"
84 #endif LIBGLNAME
85
86 (void)dlerror(); /*drain dlerror()*/
87
88 handle = dlopen(LIBGLNAME, RTLD_LAZY);
89
90 if(NULL == handle) {
91 fprintf(stderr, "error: unable to dlopen "
92 LIBGLNAME " :" "%s\n", dlerror());
93 abort();
94 }
95 }
96
97 set this_script [info script]
98
99 proc main {argc argv} {
100 if {2 != $argc} {
101 puts stderr "syntax is: [set ::this_script] serialized-array-file output.c"
102 return 1
103 }
104
105
106 set fd [open [lindex $argv 0] r]
107 array set api [read $fd]
108 close $fd
109
110 set fd [open [lindex $argv 1] w]
111
112 puts $fd "/* This file was automatically generated by [set ::this_script]. */"
113 puts $fd $::license
114
115 puts $fd {
116 #define GL_GLEXT_PROTOTYPES
117 #include <GL/gl.h>
118 #include <dlfcn.h>
119 #include "glxclient.h"
120 #include "apple_xgl_api.h"
121 #include "apple_glx_context.h"
122 }
123
124 puts $fd "struct apple_xgl_api __ogl_framework_api;"
125
126 set sorted [lsort -dictionary [array names api]]
127
128 set exclude [list DrawBuffer DrawBuffers DrawBuffersARB]
129
130 #These are special to glXMakeContextCurrent.
131 #See also: apple_xgl_api_read.c.
132 lappend exclude ReadPixels CopyPixels CopyColorTable
133
134 #This is excluded to work with surface updates.
135 lappend exclude Viewport
136
137 foreach f $sorted {
138 if {$f in $exclude} {
139 continue
140 }
141
142 set attr $api($f)
143
144 set pstr ""
145
146 foreach p [dict get $attr parameters] {
147 append pstr "[lindex $p 0] [lindex $p 1], "
148 }
149
150 set pstr [string trimright $pstr ", "]
151
152 if {![string length $pstr]} {
153 set pstr void
154 }
155
156 set callvars ""
157
158 foreach p [dict get $attr parameters] {
159 append callvars "[lindex $p end], "
160 }
161
162 set callvars [string trimright $callvars ", "]
163
164 set return ""
165 if {"void" ne [dict get $attr return]} {
166 set return "return "
167 }
168
169 if {[dict exists $attr noop]} {
170 if {"void" eq [dict get $attr return]} {
171 set body "/*noop*/"
172 } else {
173 set body "return 0; /*noop*/"
174 }
175 } elseif {[dict exists $attr alias_for]} {
176 set alias [dict get $attr alias_for]
177 set body "[set return] gl[set alias]([set callvars]);"
178 } else {
179 set body "[set return]__ogl_framework_api.[set f]([set callvars]);"
180 }
181
182 puts $fd "GLAPI [dict get $attr return] APIENTRY gl[set f]([set pstr]) \{\n\t$body\n\}"
183 }
184
185 puts $fd $::init_code
186
187 puts $fd "void apple_xgl_init_direct(void) \{"
188 puts $fd "\tvoid *handle;"
189
190 puts $fd $::dlopen_code
191
192 foreach f $sorted {
193 set attr $api($f)
194
195 puts $attr
196 puts $f
197
198 if {[dict exists $attr alias_for] || [dict exists $attr noop]} {
199 #Function f is an alias_for another, so we shouldn't try
200 #to load it.
201 continue
202 }
203
204 puts $fd "\t__ogl_framework_api.$f = glsym(handle, \"gl$f\");"
205 }
206
207 puts $fd "\}\n"
208 close $fd
209
210 return 0
211 }
212 exit [main $::argc $::argv]