summaryrefslogtreecommitdiff
path: root/freetype/builds/meson
diff options
context:
space:
mode:
Diffstat (limited to 'freetype/builds/meson')
-rw-r--r--freetype/builds/meson/extract_freetype_version.py107
-rw-r--r--freetype/builds/meson/extract_libtool_version.py105
-rw-r--r--freetype/builds/meson/generate_reference_docs.py79
-rw-r--r--freetype/builds/meson/parse_modules_cfg.py160
-rw-r--r--freetype/builds/meson/process_ftoption_h.py105
5 files changed, 556 insertions, 0 deletions
diff --git a/freetype/builds/meson/extract_freetype_version.py b/freetype/builds/meson/extract_freetype_version.py
new file mode 100644
index 000000000..15e87dbcc
--- /dev/null
+++ b/freetype/builds/meson/extract_freetype_version.py
@@ -0,0 +1,107 @@
+#!/usr/bin/env python
+"""Extract the FreeType version numbers from `<freetype/freetype.h>`.
+
+This script parses the header to extract the version number defined there.
+By default, the full dotted version number is printed, but `--major`,
+`--minor` or `--patch` can be used to only print one of these values
+instead.
+"""
+
+from __future__ import print_function
+
+import argparse
+import os
+import re
+import sys
+
+# Expected input:
+#
+# ...
+# #define FREETYPE_MAJOR 2
+# #define FREETYPE_MINOR 10
+# #define FREETYPE_PATCH 2
+# ...
+
+RE_MAJOR = re.compile(r"^ \#define \s+ FREETYPE_MAJOR \s+ (.*) $", re.X)
+RE_MINOR = re.compile(r"^ \#define \s+ FREETYPE_MINOR \s+ (.*) $", re.X)
+RE_PATCH = re.compile(r"^ \#define \s+ FREETYPE_PATCH \s+ (.*) $", re.X)
+
+
+def parse_freetype_header(header):
+ major = None
+ minor = None
+ patch = None
+
+ for line in header.splitlines():
+ line = line.rstrip()
+ m = RE_MAJOR.match(line)
+ if m:
+ assert major == None, "FREETYPE_MAJOR appears more than once!"
+ major = m.group(1)
+ continue
+
+ m = RE_MINOR.match(line)
+ if m:
+ assert minor == None, "FREETYPE_MINOR appears more than once!"
+ minor = m.group(1)
+ continue
+
+ m = RE_PATCH.match(line)
+ if m:
+ assert patch == None, "FREETYPE_PATCH appears more than once!"
+ patch = m.group(1)
+ continue
+
+ assert (
+ major and minor and patch
+ ), "This header is missing one of FREETYPE_MAJOR, FREETYPE_MINOR or FREETYPE_PATCH!"
+
+ return (major, minor, patch)
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+
+ group = parser.add_mutually_exclusive_group()
+ group.add_argument(
+ "--major",
+ action="store_true",
+ help="Only print the major version number.",
+ )
+ group.add_argument(
+ "--minor",
+ action="store_true",
+ help="Only print the minor version number.",
+ )
+ group.add_argument(
+ "--patch",
+ action="store_true",
+ help="Only print the patch version number.",
+ )
+
+ parser.add_argument(
+ "input",
+ metavar="FREETYPE_H",
+ help="The input freetype.h header to parse.",
+ )
+
+ args = parser.parse_args()
+ with open(args.input) as f:
+ header = f.read()
+
+ version = parse_freetype_header(header)
+
+ if args.major:
+ print(version[0])
+ elif args.minor:
+ print(version[1])
+ elif args.patch:
+ print(version[2])
+ else:
+ print("%s.%s.%s" % version)
+
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/freetype/builds/meson/extract_libtool_version.py b/freetype/builds/meson/extract_libtool_version.py
new file mode 100644
index 000000000..0569481b3
--- /dev/null
+++ b/freetype/builds/meson/extract_libtool_version.py
@@ -0,0 +1,105 @@
+#!/usr/bin/env python
+"""Extract the libtool version from `configure.raw`.
+
+This script parses the `configure.raw` file to extract the libtool version
+number. By default, the full dotted version number is printed, but
+`--major`, `--minor` or `--patch` can be used to only print one of these
+values instead.
+"""
+
+from __future__ import print_function
+
+import argparse
+import os
+import re
+import sys
+
+# Expected input:
+#
+# ...
+# version_info='23:2:17'
+# ...
+
+RE_VERSION_INFO = re.compile(r"^version_info='(\d+):(\d+):(\d+)'")
+
+
+def parse_configure_raw(header):
+ major = None
+ minor = None
+ patch = None
+
+ for line in header.splitlines():
+ line = line.rstrip()
+ m = RE_VERSION_INFO.match(line)
+ if m:
+ assert major == None, "version_info appears more than once!"
+ major = m.group(1)
+ minor = m.group(2)
+ patch = m.group(3)
+ continue
+
+ assert (
+ major and minor and patch
+ ), "This input file is missing a version_info definition!"
+
+ return (major, minor, patch)
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+
+ group = parser.add_mutually_exclusive_group()
+ group.add_argument(
+ "--major",
+ action="store_true",
+ help="Only print the major version number.",
+ )
+ group.add_argument(
+ "--minor",
+ action="store_true",
+ help="Only print the minor version number.",
+ )
+ group.add_argument(
+ "--patch",
+ action="store_true",
+ help="Only print the patch version number.",
+ )
+ group.add_argument(
+ "--soversion",
+ action="store_true",
+ help="Only print the libtool library suffix.",
+ )
+
+ parser.add_argument(
+ "input",
+ metavar="CONFIGURE_RAW",
+ help="The input configure.raw file to parse.",
+ )
+
+ args = parser.parse_args()
+ with open(args.input) as f:
+ raw_file = f.read()
+
+ version = parse_configure_raw(raw_file)
+
+ if args.major:
+ print(version[0])
+ elif args.minor:
+ print(version[1])
+ elif args.patch:
+ print(version[2])
+ elif args.soversion:
+ # Convert libtool version_info to the library suffix.
+ # (current,revision, age) -> (current - age, age, revision)
+ print(
+ "%d.%s.%s"
+ % (int(version[0]) - int(version[2]), version[2], version[1])
+ )
+ else:
+ print("%s.%s.%s" % version)
+
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/freetype/builds/meson/generate_reference_docs.py b/freetype/builds/meson/generate_reference_docs.py
new file mode 100644
index 000000000..219017c9d
--- /dev/null
+++ b/freetype/builds/meson/generate_reference_docs.py
@@ -0,0 +1,79 @@
+#!/usr/bin/env python
+"""Generate FreeType reference documentation."""
+
+from __future__ import print_function
+
+import argparse
+import glob
+import os
+import subprocess
+import sys
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+
+ parser.add_argument(
+ "--input-dir",
+ required=True,
+ help="Top-level FreeType source directory.",
+ )
+
+ parser.add_argument(
+ "--version", required=True, help='FreeType version (e.g. "2.x.y").'
+ )
+
+ parser.add_argument(
+ "--output-dir", required=True, help="Output directory."
+ )
+
+ args = parser.parse_args()
+
+ # Get the list of input files of interest.
+ include_dir = os.path.join(args.input_dir, "include")
+ include_config_dir = os.path.join(include_dir, "config")
+ include_cache_dir = os.path.join(include_dir, "cache")
+
+ all_headers = (
+ glob.glob(os.path.join(args.input_dir, "include", "freetype", "*.h"))
+ + glob.glob(
+ os.path.join(
+ args.input_dir, "include", "freetype", "config", "*.h"
+ )
+ )
+ + glob.glob(
+ os.path.join(
+ args.input_dir, "include", "freetype", "cache", "*.h"
+ )
+ )
+ )
+
+ if not os.path.exists(args.output_dir):
+ os.makedirs(args.output_dir)
+ else:
+ assert os.path.isdir(args.output_dir), (
+ "Not a directory: " + args.output_dir
+ )
+
+ cmds = [
+ sys.executable,
+ "-m",
+ "docwriter",
+ "--prefix=ft2",
+ "--title=FreeType-" + args.version,
+ "--site=reference",
+ "--output=" + args.output_dir,
+ ] + all_headers
+
+ print("Running docwriter...")
+ subprocess.check_call(cmds)
+
+ print("Building static site...")
+ subprocess.check_call(
+ [sys.executable, "-m", "mkdocs", "build"], cwd=args.output_dir
+ )
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/freetype/builds/meson/parse_modules_cfg.py b/freetype/builds/meson/parse_modules_cfg.py
new file mode 100644
index 000000000..e0f760561
--- /dev/null
+++ b/freetype/builds/meson/parse_modules_cfg.py
@@ -0,0 +1,160 @@
+#!/usr/bin/env python
+"""Parse modules.cfg and dump its output either as ftmodule.h or a list of
+base extensions.
+"""
+
+from __future__ import print_function
+
+import argparse
+import os
+import re
+import sys
+
+# Expected input:
+#
+# ...
+# FONT_MODULES += <name>
+# HINTING_MODULES += <name>
+# RASTER_MODULES += <name>
+# AUX_MODULES += <name>
+# BASE_EXTENSIONS += <name>
+# ...
+
+
+def parse_modules_cfg(input_file):
+
+ lists = {
+ "FONT_MODULES": [],
+ "HINTING_MODULES": [],
+ "RASTER_MODULES": [],
+ "AUX_MODULES": [],
+ "BASE_EXTENSIONS": [],
+ }
+
+ for line in input_file.splitlines():
+ line = line.rstrip()
+ # Ignore empty lines and those that start with a comment.
+ if not line or line[0] == "#":
+ continue
+
+ items = line.split()
+ assert len(items) == 3 and items[1] == "+=", (
+ "Unexpected input line [%s]" % line
+ )
+ assert items[0] in lists, (
+ "Unexpected configuration variable name " + items[0]
+ )
+
+ lists[items[0]].append(items[2])
+
+ return lists
+
+
+def generate_ftmodule(lists):
+ result = "/* This is a generated file. */\n"
+ for driver in lists["FONT_MODULES"]:
+ if driver == "sfnt": # Special case for the sfnt 'driver'.
+ result += "FT_USE_MODULE( FT_Module_Class, sfnt_module_class )\n"
+ continue
+
+ name = {
+ "truetype": "tt",
+ "type1": "t1",
+ "cid": "t1cid",
+ "type42": "t42",
+ "winfonts": "winfnt",
+ }.get(driver, driver)
+ result += (
+ "FT_USE_MODULE( FT_Driver_ClassRec, %s_driver_class )\n" % name
+ )
+
+ for module in lists["HINTING_MODULES"]:
+ result += (
+ "FT_USE_MODULE( FT_Module_Class, %s_module_class )\n" % module
+ )
+
+ for module in lists["RASTER_MODULES"]:
+ name = {
+ "raster": "ft_raster1",
+ "smooth": "ft_smooth",
+ }.get(module)
+ result += (
+ "FT_USE_MODULE( FT_Renderer_Class, %s_renderer_class )\n" % name
+ )
+
+ for module in lists["AUX_MODULES"]:
+ if module in ("psaux", "psnames", "otvalid", "gxvalid"):
+ result += (
+ "FT_USE_MODULE( FT_Module_Class, %s_module_class )\n" % module
+ )
+
+ result += "/* EOF */\n"
+ return result
+
+
+def generate_main_modules(lists):
+ return "\n".join(
+ lists["FONT_MODULES"]
+ + lists["HINTING_MODULES"]
+ + lists["RASTER_MODULES"]
+ )
+
+
+def generate_aux_modules(lists):
+ return "\n".join(lists["AUX_MODULES"])
+
+
+def generate_base_extensions(lists):
+ return "\n".join(lists["BASE_EXTENSIONS"])
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+
+ parser.add_argument(
+ "--format",
+ required=True,
+ choices=(
+ "ftmodule.h",
+ "main-modules",
+ "aux-modules",
+ "base-extensions-list",
+ ),
+ help="Select output format.",
+ )
+
+ parser.add_argument(
+ "input",
+ metavar="CONFIGURE_RAW",
+ help="The input configure.raw file to parse.",
+ )
+
+ parser.add_argument("--output", help="Output file (default is stdout).")
+
+ args = parser.parse_args()
+ with open(args.input) as f:
+ input_data = f.read()
+
+ lists = parse_modules_cfg(input_data)
+
+ if args.format == "ftmodule.h":
+ result = generate_ftmodule(lists)
+ elif args.format == "main-modules":
+ result = generate_main_modules(lists)
+ elif args.format == "aux-modules":
+ result = generate_aux_modules(lists)
+ elif args.format == "base-extensions-list":
+ result = generate_base_extensions(lists)
+ else:
+ assert False, "Invalid output format!"
+
+ if args.output:
+ with open(args.output, "w") as f:
+ f.write(result)
+ else:
+ print(result)
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/freetype/builds/meson/process_ftoption_h.py b/freetype/builds/meson/process_ftoption_h.py
new file mode 100644
index 000000000..b5f80c314
--- /dev/null
+++ b/freetype/builds/meson/process_ftoption_h.py
@@ -0,0 +1,105 @@
+#!/usr/bin/python
+"""Toggle settings in `ftoption.h` file based on command-line arguments.
+
+This script takes an `ftoption.h` file as input and rewrites
+`#define`/`#undef` lines in it based on `--enable=CONFIG_VARNAME` or
+`--disable=CONFIG_VARNAME` arguments passed to it, where `CONFIG_VARNAME` is
+configuration variable name, such as `FT_CONFIG_OPTION_USE_LZW`, that may
+appear in the file.
+
+Note that if one of `CONFIG_VARNAME` is not found in the input file, this
+script exits with an error message listing the missing variable names.
+"""
+
+import argparse
+import os
+import re
+import sys
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+
+ parser.add_argument(
+ "input", metavar="FTOPTION_H", help="Path to input ftoption.h file."
+ )
+
+ parser.add_argument("--output", help="Output to file instead of stdout.")
+
+ parser.add_argument(
+ "--enable",
+ action="append",
+ default=[],
+ help="Enable a given build option (e.g. FT_CONFIG_OPTION_USE_LZW).",
+ )
+
+ parser.add_argument(
+ "--disable",
+ action="append",
+ default=[],
+ help="Disable a given build option.",
+ )
+
+ args = parser.parse_args()
+
+ common_options = set(args.enable) & set(args.disable)
+ if common_options:
+ parser.error(
+ "Options cannot be both enabled and disabled: %s"
+ % sorted(common_options)
+ )
+ return 1
+
+ with open(args.input) as f:
+ input_file = f.read()
+
+ options_seen = set()
+
+ new_lines = []
+ for line in input_file.splitlines():
+ # Expected formats:
+ # #define <CONFIG_VAR>
+ # /* #define <CONFIG_VAR> */
+ # #undef <CONFIG_VAR>
+ line = line.rstrip()
+ if line.startswith("/* #define ") and line.endswith(" */"):
+ option_name = line[11:-3].strip()
+ option_enabled = False
+ elif line.startswith("#define "):
+ option_name = line[8:].strip()
+ option_enabled = True
+ elif line.startswith("#undef "):
+ option_name = line[7:].strip()
+ option_enabled = False
+ else:
+ new_lines.append(line)
+ continue
+
+ options_seen.add(option_name)
+ if option_enabled and option_name in args.disable:
+ line = "#undef " + option_name
+ elif not option_enabled and option_name in args.enable:
+ line = "#define " + option_name
+ new_lines.append(line)
+
+ result = "\n".join(new_lines)
+
+ # Sanity check that all command-line options were actually processed.
+ cmdline_options = set(args.enable) | set(args.disable)
+ assert cmdline_options.issubset(
+ options_seen
+ ), "Could not find options in input file: " + ", ".join(
+ sorted(cmdline_options - options_seen)
+ )
+
+ if args.output:
+ with open(args.output, "w") as f:
+ f.write(result)
+ else:
+ print(result)
+
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())