blob: 9040f860ae1a7cce28162401f814b6546bede3b4 [file] [log] [blame]
John Snow6f6652e2023-05-10 23:54:29 -04001sphinx_build = find_program(fs.parent(python.full_path()) / 'sphinx-build',
John Snow1b1be8d2023-02-20 20:24:55 -05002 required: get_option('docs'))
Yonggang Luoe3667662020-10-16 06:06:25 +08003
4# Check if tools are available to build documentation.
5build_docs = false
6if sphinx_build.found()
Daniel P. Berrangé2e880192021-08-12 11:24:27 +01007 SPHINX_ARGS = ['env', 'CONFDIR=' + qemu_confdir, sphinx_build, '-q']
Yonggang Luoe3667662020-10-16 06:06:25 +08008 # If we're making warnings fatal, apply this to Sphinx runs as well
9 if get_option('werror')
Peter Maydell36420662023-03-14 11:44:31 +000010 SPHINX_ARGS += [ '-W', '-Dkerneldoc_werror=1' ]
Yonggang Luoe3667662020-10-16 06:06:25 +080011 endif
12
Fabiano Rosased8d9512023-05-03 17:39:46 -030013 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
Yonggang Luoe3667662020-10-16 06:06:25 +080025 # 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.
Paolo Bonzinib20a7ee2021-12-17 09:52:03 +010028 run_command('mkdir', ['-p', tmpdir / 'sphinx'], check: true)
29 run_command('touch', [tmpdir / 'sphinx/index.rst'], check: true)
Yonggang Luoe3667662020-10-16 06:06:25 +080030 sphinx_build_test_out = run_command(SPHINX_ARGS + [
31 '-c', meson.current_source_dir(),
32 '-b', 'html', tmpdir / 'sphinx',
Paolo Bonzinib20a7ee2021-12-17 09:52:03 +010033 tmpdir / 'sphinx/out'], check: false)
Yonggang Luoe3667662020-10-16 06:06:25 +080034 build_docs = (sphinx_build_test_out.returncode() == 0)
35
36 if not build_docs
Marc-André Lureau73e6aec2021-03-23 15:53:28 +040037 warning('@0@: @1@'.format(sphinx_build.full_path(), sphinx_build_test_out.stderr()))
Yonggang Luoe3667662020-10-16 06:06:25 +080038 if get_option('docs').enabled()
Marc-André Lureau73e6aec2021-03-23 15:53:28 +040039 error('Install a Python 3 version of python-sphinx and the readthedoc theme')
Yonggang Luoe3667662020-10-16 06:06:25 +080040 endif
41 endif
42endif
43
Paolo Bonzinif8aa24e2020-08-05 15:49:10 +020044if build_docs
Paolo Bonzinib0b43232022-04-20 17:33:54 +020045 SPHINX_ARGS += ['-Dversion=' + meson.project_version(), '-Drelease=' + get_option('pkgversion')]
Yonggang Luoe3667662020-10-16 06:06:25 +080046
Paolo Bonzinif8aa24e2020-08-05 15:49:10 +020047 man_pages = {
Stefan Reitere0f7fc52021-01-28 15:58:01 +010048 'qemu-ga.8': (have_ga ? 'man8' : ''),
49 'qemu-ga-ref.7': (have_ga ? 'man7' : ''),
Peter Maydell4ac2ee12020-09-25 17:23:04 +010050 'qemu-qmp-ref.7': 'man7',
Stefan Hajnoczi23c02ac2020-12-09 10:38:00 +000051 'qemu-storage-daemon-qmp-ref.7': (have_tools ? 'man7' : ''),
Paolo Bonzinif8aa24e2020-08-05 15:49:10 +020052 'qemu-img.1': (have_tools ? 'man1' : ''),
53 'qemu-nbd.8': (have_tools ? 'man8' : ''),
Peter Maydell773ee3f2020-11-12 14:40:40 +000054 'qemu-pr-helper.8': (have_tools ? 'man8' : ''),
Peter Maydellfa56cf72021-01-08 16:14:15 +000055 'qemu-storage-daemon.1': (have_tools ? 'man1' : ''),
Paolo Bonzini9c29b742021-10-07 15:08:14 +020056 'qemu-trace-stap.1': (stap.found() ? 'man1' : ''),
Paolo Bonzinif8aa24e2020-08-05 15:49:10 +020057 'virtfs-proxy-helper.1': (have_virtfs_proxy_helper ? 'man1' : ''),
Paolo Bonzinif8aa24e2020-08-05 15:49:10 +020058 'qemu.1': 'man1',
59 'qemu-block-drivers.7': 'man7',
60 'qemu-cpu-models.7': 'man7'
Paolo Bonzinif8aa24e2020-08-05 15:49:10 +020061 }
62
63 sphinxdocs = []
64 sphinxmans = []
Paolo Bonzinibac35bf2020-08-11 09:07:04 +020065
Peter Maydellb93f4fb2021-01-15 15:44:49 +000066 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',
Paolo Bonzinif8aa24e2020-08-05 15:49:10 +020071 build_by_default: build_docs,
Peter Maydellb93f4fb2021-01-15 15:44:49 +000072 output: 'docs.stamp',
73 input: files('conf.py'),
74 depfile: 'docs.d',
Paolo Bonzinibac35bf2020-08-11 09:07:04 +020075 command: [SPHINX_ARGS, '-Ddepfile=@DEPFILE@',
76 '-Ddepfile_stamp=@OUTPUT0@',
77 '-b', 'html', '-d', private_dir,
78 input_dir, output_dir])
Peter Maydellb93f4fb2021-01-15 15:44:49 +000079 sphinxdocs += this_manual
80 install_subdir(output_dir, install_dir: qemu_docdir, strip_directory: true)
Paolo Bonzinif8aa24e2020-08-05 15:49:10 +020081
Peter Maydellb93f4fb2021-01-15 15:44:49 +000082 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
Paolo Bonzinif8aa24e2020-08-05 15:49:10 +020087 endforeach
Peter Maydellb93f4fb2021-01-15 15:44:49 +000088
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
Paolo Bonzinif8aa24e2020-08-05 15:49:10 +020098 alias_target('sphinxdocs', sphinxdocs)
Peter Maydell4ac2ee12020-09-25 17:23:04 +010099 alias_target('html', sphinxdocs)
Paolo Bonzinif8aa24e2020-08-05 15:49:10 +0200100 alias_target('man', sphinxmans)
101endif