summaryrefslogtreecommitdiffstats
path: root/doc/meson.build
blob: a4b57860af96ab363e41ab6f18324639e8029a0d (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# Copyright (c) 2021, Dell Inc. or its subsidiaries.  All rights reserved.
# SPDX-License-Identifier: Apache-2.0
# See the LICENSE file for details.
#
# This file is part of NVMe STorage Appliance Services (nvme-stas).
#
# Authors: Martin Belanger <Martin.Belanger@dell.com>
#


if want_man or want_html or want_readthedocs
    docbklst = find_program('genlist-from-docbooks.py')
    dbus2doc = find_program('dbus-idl-to-docbooks.py')
    dbusgen  = find_program('gdbus-codegen', required: false) # Needed by dbus2doc
    if not dbusgen.found()
        error('gdbus-codegen missing: Install libglib2.0-dev (deb) / glib2-devel (rpm)')
    endif

    # Get the list of DocBook files to process. The result will
    # be saved to variable docbooks as a list of tuples as follows:
    # docbooks = [ ['file1', 'manvolnum-from-file1.xml', 'file1.xml'],
    #              ['file2', 'manvolnum-from-file2.xml', 'file2.xml'], ... ]
    docbooks = []
    rr = run_command(docbklst, check: true)
    output = rr.stdout().strip()
    if output != ''
        foreach item : output.split(';')
            items     = item.split(',')
            stem      = items[0]
            manvolnum = items[1]
            fname     = items[2]
            deps      = items[3]
            if deps == 'None'
                deps = []
            else
                deps = deps.split(':')
            endif
            docbooks += [ [stem, manvolnum, fname, deps] ]
        endforeach
    endif

    # Generate DocBooks from IDL queried directly from the D-Bus services.
    out_dir = conf.get('BUILD_DIR') / 'man-tmp'
    env = environment({'PYTHONPATH': PYTHONPATH})
    idls = [ 'stafd.idl', 'stacd.idl' ]
    foreach idl : idls
        rr = run_command(
            dbus2doc,
            '--idl', conf.get('BUILD_DIR') / 'staslib' / idl,
            '--output-directory', out_dir,
            '--tmp', meson.current_build_dir(),
            env: env,
            check: true)
        output = rr.stdout().strip()
        if output != ''
            foreach stem : output.split(';')
                docbooks += [ [stem, '5', out_dir / stem + '.xml', []] ]
            endforeach
        endif
    endforeach


    xsltproc = find_program('xsltproc')
    if xsltproc.found()
        manpage_style = 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'
        if run_command(xsltproc, '--nonet', manpage_style, check: false).returncode() != 0
            error('Docbook style sheet missing: Install docbook-xsl (deb) / docbook-style-xsl (rpm)')
        endif
    endif

    xslt_cmd = [
      xsltproc,
      '--nonet',
      '--xinclude',
      '--stringparam', 'man.output.quietly', '1',
      '--stringparam', 'funcsynopsis.style', 'ansi',
      '--stringparam', 'man.th.extra1.suppress', '1',
      '--stringparam', 'man.authors.section.enabled', '0',
      '--stringparam', 'man.copyright.section.enabled', '0',
      '--stringparam', 'nvme-stas.version', '@0@'.format(meson.project_version()),
      '-o', '@OUTPUT@',
    ]

    man_xsl  = files('man.xsl')
    html_xsl = files('html.xsl')


    html_files = [] # Will be used as input to readthedocs
    foreach tuple: docbooks
        stem = tuple[0]
        sect = tuple[1]
        file = files(tuple[2])
        deps = tuple[3]

        if want_man
            man = stem + '.' + sect
            custom_target(
                man,
                input: file,
                output: man,
                depend_files: deps,
                command: xslt_cmd + [man_xsl, '@INPUT@'],
                install: true,
                install_dir: mandir / ('man' + sect)
            )
        endif

        if want_html or want_readthedocs
            html = stem + '.html'
            html_file = custom_target(
                html,
                input: file,
                output: html,
                depend_files: deps,
                command: xslt_cmd + [html_xsl, '@INPUT@'],
                install: want_html,
                install_dir: docdir / 'html'
            )
            html_files += [ [stem, html_file ] ]
        endif
    endforeach
endif

if want_readthedocs
    subdir('readthedocs')
endif