xref: /openbmc/qemu/docs/meson.build (revision e57030e8)
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        'virtfs-proxy-helper.1': (have_virtfs_proxy_helper ? 'man1' : ''),
58        'qemu.1': 'man1',
59        'qemu-block-drivers.7': 'man7',
60        'qemu-cpu-models.7': 'man7'
61  }
62
63  sphinxdocs = []
64  sphinxmans = []
65
66  private_dir = meson.current_build_dir() / 'manual.p'
67  output_dir = meson.current_build_dir() / 'manual'
68  input_dir = meson.current_source_dir()
69
70  this_manual = custom_target('QEMU manual',
71                build_by_default: build_docs,
72                output: 'docs.stamp',
73                input: files('conf.py'),
74                depfile: 'docs.d',
75                command: [SPHINX_ARGS, '-Ddepfile=@DEPFILE@',
76                          '-Ddepfile_stamp=@OUTPUT0@',
77                          '-b', 'html', '-d', private_dir,
78                          input_dir, output_dir])
79  sphinxdocs += this_manual
80  install_subdir(output_dir, install_dir: qemu_docdir, strip_directory: true)
81
82  these_man_pages = []
83  install_dirs = []
84  foreach page, section : man_pages
85    these_man_pages += page
86    install_dirs += section == '' ? false : get_option('mandir') / section
87  endforeach
88
89  sphinxmans += custom_target('QEMU man pages',
90                              build_by_default: build_docs,
91                              output: these_man_pages,
92                              input: this_manual,
93                              install: build_docs,
94                              install_dir: install_dirs,
95                              command: [SPHINX_ARGS, '-b', 'man', '-d', private_dir,
96                                        input_dir, meson.current_build_dir()])
97
98  alias_target('sphinxdocs', sphinxdocs)
99  alias_target('html', sphinxdocs)
100  alias_target('man', sphinxmans)
101endif
102
103test('QAPI firmware.json regression tests', qapi_gen,
104     args: ['-o', meson.current_build_dir() / 'qapi',
105            meson.current_source_dir() / 'interop/firmware.json'],
106     suite: ['qapi-schema', 'qapi-interop'])
107