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