1#!/usr/bin/env python
2#
3# Copyright (C) 2020-2021 by
4# David Turner, Robert Wilhelm, and Werner Lemberg.
5#
6# This file is part of the FreeType project, and may only be used, modified,
7# and distributed under the terms of the FreeType project license,
8# LICENSE.TXT.  By continuing to use, modify, or distribute this file you
9# indicate that you have read the license and understand and accept it
10# fully.
11
12"""Generate FreeType reference documentation."""
13
14from __future__ import print_function
15
16import argparse
17import glob
18import os
19import subprocess
20import sys
21
22
23def main():
24    parser = argparse.ArgumentParser(description=__doc__)
25
26    parser.add_argument(
27        "--input-dir",
28        required=True,
29        help="Top-level FreeType source directory.",
30    )
31
32    parser.add_argument(
33        "--version", required=True, help='FreeType version (e.g. "2.x.y").'
34    )
35
36    parser.add_argument(
37        "--output-dir", required=True, help="Output directory."
38    )
39
40    args = parser.parse_args()
41
42    # Get the list of input files of interest.
43    include_dir = os.path.join(args.input_dir, "include")
44    include_config_dir = os.path.join(include_dir, "config")
45    include_cache_dir = os.path.join(include_dir, "cache")
46
47    all_headers = (
48        glob.glob(os.path.join(args.input_dir, "include", "freetype", "*.h"))
49        + glob.glob(
50            os.path.join(
51                args.input_dir, "include", "freetype", "config", "*.h"
52            )
53        )
54        + glob.glob(
55            os.path.join(
56                args.input_dir, "include", "freetype", "cache", "*.h"
57            )
58        )
59    )
60
61    if not os.path.exists(args.output_dir):
62        os.makedirs(args.output_dir)
63    else:
64        assert os.path.isdir(args.output_dir), (
65            "Not a directory: " + args.output_dir
66        )
67
68    cmds = [
69        sys.executable,
70        "-m",
71        "docwriter",
72        "--prefix=ft2",
73        "--title=FreeType-" + args.version,
74        "--site=reference",
75        "--output=" + args.output_dir,
76    ] + all_headers
77
78    print("Running docwriter...")
79    subprocess.check_call(cmds)
80
81    print("Building static site...")
82    subprocess.check_call(
83        [sys.executable, "-m", "mkdocs", "build"], cwd=args.output_dir
84    )
85    return 0
86
87
88if __name__ == "__main__":
89    sys.exit(main())
90