generate_source.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/env python3
  2. #
  3. # Copyright 2019 The Chromium Authors. All rights reserved.
  4. # Use of this source code is governed by a BSD-style license that can be
  5. # found in the LICENSE file.
  6. """Creates a GN include file for building dav1d from source."""
  7. __author__ = "dalecurtis@chromium.org (Dale Curtis)"
  8. import datetime
  9. import glob
  10. import os
  11. _COPYRIGHT = """# Copyright %d The Chromium Authors. All rights reserved.
  12. # Use of this source code is governed by a BSD-style license that can be
  13. # found in the LICENSE file.
  14. # NOTE: this file is autogenerated by dav1d/generate_sources.py - DO NOT EDIT.
  15. """ % (
  16. datetime.datetime.now().year)
  17. # .c files which don't need -DBIT_DEPTH specified for each compilation.
  18. _DAV1D_ENTRY_POINT_SOURCES = [
  19. "libdav1d/src/lib.c",
  20. "libdav1d/src/thread_task.c",
  21. "libdav1d/src/thread_task.h",
  22. ]
  23. def _Glob(pattern):
  24. # Replace path separator. Needed when running on Windows.
  25. return [i.replace(os.sep, '/') for i in glob.glob(pattern)]
  26. def _WriteArray(fd, var_name, array, filter_list=[], last_entry=False):
  27. if len(array) == 0:
  28. fd.write("var_name = []\n")
  29. return
  30. fd.write("%s = [\n" % var_name)
  31. for item in sorted(array):
  32. if item not in filter_list:
  33. fd.write(" \"%s\",\n" % item)
  34. fd.write("]\n")
  35. if not last_entry:
  36. fd.write("\n")
  37. def _WriteGn(fd):
  38. fd.write(_COPYRIGHT)
  39. _WriteArray(fd, "x86_asm_sources", _Glob("libdav1d/src/x86/*.asm"),
  40. ["libdav1d/src/x86/filmgrain_common.asm"])
  41. _WriteArray(fd, "x86_template_sources", _Glob("libdav1d/src/x86/*_tmpl.c"))
  42. _WriteArray(
  43. fd, "arm32_asm_sources", _Glob("libdav1d/src/arm/32/*.S"),
  44. _Glob("libdav1d/src/arm/32/*_tmpl.S") + ["libdav1d/src/arm/32/util.S"])
  45. _WriteArray(
  46. fd, "arm64_asm_sources", _Glob("libdav1d/src/arm/64/*.S"),
  47. _Glob("libdav1d/src/arm/64/*_tmpl.S") + ["libdav1d/src/arm/64/util.S"])
  48. _WriteArray(fd, "arm_template_sources", _Glob("libdav1d/src/arm/*_tmpl.c"))
  49. _WriteArray(fd, "ppc64_template_sources", _Glob("libdav1d/src/ppc/*_tmpl.c"))
  50. template_sources = _Glob("libdav1d/src/*_tmpl.c")
  51. _WriteArray(fd, "template_sources", template_sources)
  52. # Generate list of sources which need to be compiled multiple times with the
  53. # correct -DBIT_DEPTH=8|10 option specified each time.
  54. _WriteArray(fd, "c_headers", _Glob("libdav1d/src/*.h"),
  55. _DAV1D_ENTRY_POINT_SOURCES + template_sources)
  56. _WriteArray(fd, "c_sources", _Glob("libdav1d/src/*.c"),
  57. _DAV1D_ENTRY_POINT_SOURCES + template_sources)
  58. _WriteArray(fd,
  59. "entry_point_sources",
  60. _DAV1D_ENTRY_POINT_SOURCES,
  61. last_entry=True)
  62. def main():
  63. with open("dav1d_generated.gni", "w") as fd:
  64. _WriteGn(fd)
  65. if __name__ == "__main__":
  66. main()