meson.build 3.5 KB

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