xref: /openbmc/qemu/docs/meson.build (revision 7d87775f)
1sphinx_build = find_program(fs.parent(python.full_path()) / 'sphinx-build',
2                            required: get_option('docs'))
3
4# Check if tools are available to build documentation.
5build_docs = false
6if sphinx_build.found()
7  SPHINX_ARGS = ['env', 'CONFDIR=' + qemu_confdir, sphinx_build, '-q']
8  # If we're making warnings fatal, apply this to Sphinx runs as well
9  if get_option('werror')
10    SPHINX_ARGS += [ '-W', '-Dkerneldoc_werror=1' ]
11  endif
12
13  sphinx_version = run_command(SPHINX_ARGS + ['--version'],
14                               check: true).stdout().split()[1]
15  if sphinx_version.version_compare('>=1.7.0')
16    SPHINX_ARGS += ['-j', 'auto']
17  else
18    nproc = find_program('nproc')
19    if nproc.found()
20      jobs = run_command(nproc, check: true).stdout()
21      SPHINX_ARGS += ['-j', jobs]
22    endif
23  endif
24
25  # This is a bit awkward but works: create a trivial document and
26  # try to run it with our configuration file (which enforces a
27  # version requirement). This will fail if sphinx-build is too old.
28  run_command('mkdir', ['-p', tmpdir / 'sphinx'], check: true)
29  run_command('touch', [tmpdir / 'sphinx/index.rst'], check: true)
30  sphinx_build_test_out = run_command(SPHINX_ARGS + [
31    '-c', meson.current_source_dir(),
32    '-b', 'html', tmpdir / 'sphinx',
33    tmpdir / 'sphinx/out'], check: false)
34  build_docs = (sphinx_build_test_out.returncode() == 0)
35
36  if not build_docs
37    warning('@0@: @1@'.format(sphinx_build.full_path(), sphinx_build_test_out.stderr()))
38    if get_option('docs').enabled()
39      error('Install a Python 3 version of python-sphinx and the readthedoc theme')
40    endif
41  endif
42endif
43
44if build_docs
45  SPHINX_ARGS += ['-Dversion=' + meson.project_version(), '-Drelease=' + get_option('pkgversion')]
46
47  man_pages = {
48        'qemu-ga.8': (have_ga ? 'man8' : ''),
49        'qemu-ga-ref.7': (have_ga ? 'man7' : ''),
50        'qemu-qmp-ref.7': 'man7',
51        'qemu-storage-daemon-qmp-ref.7': (have_tools ? 'man7' : ''),
52        'qemu-img.1': (have_tools ? 'man1' : ''),
53        'qemu-nbd.8': (have_tools ? 'man8' : ''),
54        'qemu-pr-helper.8': (have_tools ? 'man8' : ''),
55        'qemu-storage-daemon.1': (have_tools ? 'man1' : ''),
56        'qemu-trace-stap.1': (stap.found() ? 'man1' : ''),
57        'qemu.1': 'man1',
58        'qemu-block-drivers.7': 'man7',
59        'qemu-cpu-models.7': 'man7'
60  }
61
62  sphinxdocs = []
63  sphinxmans = []
64
65  private_dir = meson.current_build_dir() / 'manual.p'
66  output_dir = meson.current_build_dir() / 'manual'
67  input_dir = meson.current_source_dir()
68
69  this_manual = custom_target('QEMU manual',
70                build_by_default: build_docs,
71                output: 'docs.stamp',
72                input: files('conf.py'),
73                depfile: 'docs.d',
74                command: [SPHINX_ARGS, '-Ddepfile=@DEPFILE@',
75                          '-Ddepfile_stamp=@OUTPUT0@',
76                          '-b', 'html', '-d', private_dir,
77                          input_dir, output_dir])
78  sphinxdocs += this_manual
79  install_subdir(output_dir, install_dir: qemu_docdir, strip_directory: true)
80
81  these_man_pages = []
82  install_dirs = []
83  foreach page, section : man_pages
84    these_man_pages += page
85    install_dirs += section == '' ? false : get_option('mandir') / section
86  endforeach
87
88  sphinxmans += custom_target('QEMU man pages',
89                              build_by_default: build_docs,
90                              output: these_man_pages,
91                              input: this_manual,
92                              install: build_docs,
93                              install_dir: install_dirs,
94                              command: [SPHINX_ARGS, '-b', 'man', '-d', private_dir,
95                                        input_dir, meson.current_build_dir()])
96
97  alias_target('sphinxdocs', sphinxdocs)
98  alias_target('html', sphinxdocs)
99  alias_target('man', sphinxmans)
100endif
101
102test('QAPI firmware.json regression tests', qapi_gen,
103     args: ['-o', meson.current_build_dir() / 'qapi',
104            meson.current_source_dir() / 'interop/firmware.json'],
105     suite: ['qapi-schema', 'qapi-interop'])
106