summaryrefslogtreecommitdiff
path: root/chromium/third_party/dav1d/generate_source.py
blob: 9ab5e00b83a7932e0648c3a56383ae7fe5746f96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/python
#
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Creates a GN include file for building dav1d from source."""

__author__ = "dalecurtis@chromium.org (Dale Curtis)"

import datetime
import glob

COPYRIGHT = """# Copyright %d The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# NOTE: this file is autogenerated by dav1d/generate_sources.py - DO NOT EDIT.

""" % (
    datetime.datetime.now().year)

# .c files which don't need -DBIT_DEPTH specified for each compilation.
DAV1D_ENTRY_POINT_SOURCES = [
    "libdav1d/src/lib.c",
    "libdav1d/src/thread_task.c",
    "libdav1d/src/thread_task.h",
]


def WriteArray(fd, var_name, array, filter_list=[], last_entry=False):
  if len(array) == 0:
    fd.write("var_name = []\n")
    return

  fd.write("%s = [\n" % var_name)
  for item in sorted(array):
    if item not in filter_list:
      fd.write("  \"%s\",\n" % item)
  fd.write("]\n")
  if not last_entry:
    fd.write("\n")


def WriteGn(fd):
  fd.write(COPYRIGHT)
  WriteArray(fd, "x86_asm_sources", glob.glob("libdav1d/src/x86/*.asm"))
  WriteArray(fd, "x86_template_sources", glob.glob("libdav1d/src/x86/*_tmpl.c"))

  # TODO(dalecurtis): May want to exclude "util.S" here.
  WriteArray(fd, "arm32_asm_sources", glob.glob("libdav1d/src/arm/32/*.S"))
  WriteArray(fd, "arm64_asm_sources", glob.glob("libdav1d/src/arm/64/*.S"))
  WriteArray(fd, "arm_template_sources", glob.glob("libdav1d/src/arm/*_tmpl.c"))

  template_sources = glob.glob("libdav1d/src/*_tmpl.c")
  WriteArray(fd, "template_sources", template_sources)

  # Generate list of sources which need to be compiled multiple times with the
  # correct -DBIT_DEPTH=8|10 option specified each time.
  WriteArray(fd, "c_sources", glob.glob("libdav1d/src/*.[c|h]"),
             DAV1D_ENTRY_POINT_SOURCES + template_sources)

  WriteArray(
      fd, "entry_point_sources", DAV1D_ENTRY_POINT_SOURCES, last_entry=True)


def main():
  with open("dav1d_generated.gni", "w") as fd:
    WriteGn(fd)


if __name__ == "__main__":
  main()