generate.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env python
  2. # vim:fileencoding=utf-8
  3. # License: GPL v3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
  4. import os
  5. import re
  6. import shlex
  7. import shutil
  8. import subprocess
  9. cmdline = (
  10. 'glad --out-path {dest} --api gl:core=3.1 '
  11. ' --extensions GL_ARB_texture_storage,GL_ARB_copy_image,GL_ARB_multisample,GL_ARB_robustness,GL_ARB_instanced_arrays,GL_KHR_debug '
  12. 'c --header-only --debug'
  13. )
  14. def clean(x):
  15. if os.path.exists(x):
  16. shutil.rmtree(x)
  17. def regenerate():
  18. clean('out')
  19. subprocess.check_call(
  20. shlex.split(cmdline.format(dest='out'))
  21. )
  22. def strip_trailing_whitespace(c):
  23. return re.sub(r'\s+$', '', c, flags=re.MULTILINE) + '\n'
  24. def export():
  25. with open('out/include/glad/gl.h', 'r', encoding='utf-8') as source:
  26. data = source.read()
  27. data = strip_trailing_whitespace(data)
  28. with open('../kitty/gl-wrapper.h', 'w', encoding='utf-8') as dest:
  29. dest.write(data)
  30. if __name__ == '__main__':
  31. os.chdir(os.path.dirname(os.path.abspath(__file__)))
  32. regenerate()
  33. export()