2
# -*- coding: utf-8 -*-
4
# Copyright © 2012 B. Clausius <barcc@gmx.de>
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
from __future__ import print_function, division
24
from bcpath import path
26
srcdir = path('/usr/include/GL')
27
dstdir = path('pybiklib')
28
filenames = ['gl.h', #'glext.h'
30
dstfilename = dstdir / 'gl.pxd'
32
def convert_file(*psrc):
33
src = [(_psrc, _psrc.text()) for _psrc in psrc]
34
yield '\n\n# from {}:\n'.format(psrc[0])
35
yield "cdef extern from '{}/{}':".format(psrc[0].dirname.basename, psrc[0].basename)
36
for match in re.finditer(r'^\#define[ \t]+(\w+).*?$', src[0][1], re.MULTILINE | re.DOTALL):
37
if match.group(1).startswith('GL_'):
38
yield match.expand(r' enum: \1')
40
for psrc, tsrc in src:
41
yield '\n\n# from {}:\n'.format(psrc)
42
for match in re.finditer(r'^(typedef[\s\w]*);.*?$', tsrc, re.MULTILINE | re.DOTALL):
44
if mg1.find('_t') == -1 and not (mg1[-2:].isalpha() and mg1[-2:].isupper()):
45
yield match.expand(r'c\1')
47
for psrc, tsrc in src:
48
yield '\n\n# from {} with:\n'.format(psrc)
49
yield "cdef extern from '{}/{}':".format(psrc.dirname.basename, psrc.basename)
50
for match in re.finditer(r'^GLAPI([\s\w*]*?)G?L?APIENTRY([^(]*)\(([^)]*)\);(.*?)$', tsrc,
51
re.MULTILINE | re.DOTALL):
52
mg2s2 = match.group(2).strip()[-2:]
53
if mg2s2.isalpha() and mg2s2.isupper():
55
for mgf in (match.group(1).find, match.group(3).find):
56
if not mgf('GLsizeiptr') == mgf('GLintptr') == mgf('64') == mgf('GLsync') == -1:
59
if match.group(3).strip() == 'void':
60
template = r' cdef\1\2()\4'
62
template = r' cdef\1\2(\3)\4'
63
yield match.expand(template).replace('const ', '').replace(' in,', ' in_,').replace('/*', '#/*')
67
with open(pdst, 'w') as fdst:
68
print('# {}'.format(pdst), file=fdst)
69
print('# generated with {}'.format(sys.argv[0]), file=fdst)
70
psrc = srcdir / 'gl.h'
71
psrcext = srcdir / 'glext.h'
72
for token in convert_file(psrc, psrcext):
73
print(token, file=fdst)
76
if __name__ == '__main__':