From 87d97adb5499ffa0546eec9035c64ac2e380e0e6 Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Fri, 3 Oct 2025 21:08:09 +0200 Subject: [PATCH] meson: build docs with meson Introduce a custom target `docs` and a build configuration option `docs` to build the sphinx documentation --- Makefile | 7 ------- README.md | 4 ++-- meson.build | 16 ++++++++++++++++ meson.options | 3 +++ 4 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 meson.options diff --git a/Makefile b/Makefile index 19b8260..6c88031 100644 --- a/Makefile +++ b/Makefile @@ -29,13 +29,6 @@ clean: distclean: clean rm -rf dist MANIFEST -SPHINXOPTS += -D version=$(VERSION) -D release=$(VERSION) -sphinx-%: install - mkdir $(BUILD_DIR) && cd $(BUILD_DIR) && $(PYTHON) -m sphinx -b $* $(SPHINXOPTS) ../docs $* - @echo Output has been generated in $(BUILD_DIR)/$* - -doc: sphinx-html - check: build install ($(PYTHON) -m pytest src/systemd/test docs $(TESTFLAGS)) diff --git a/README.md b/README.md index d2edcce..6049c8a 100644 --- a/README.md +++ b/README.md @@ -185,9 +185,9 @@ Online documentation can be found at [freedesktop.org](https://www.freedesktop.o To build it locally run: - make sphinx-html + ninja -C build docs -Or use any other builder, see `man sphinx-build` for a list. The compiled docs will be e.g. in `docs/html`. +Or use any other builder, see `man sphinx-build` for a list. The compiled docs will be e.g. in `build/html`. Viewing Output ============== diff --git a/meson.build b/meson.build index 2e4c8cb..a247823 100644 --- a/meson.build +++ b/meson.build @@ -40,3 +40,19 @@ test( ) alias_target('update-constants', update_constants) + +# Docs +sphinx_build = find_program('sphinx-build', disabler: true, required: get_option('docs')) +sphinx_args = ['-Dversion=' + meson.project_version(), '-Drelease=' + meson.project_version()] + +input_dir = meson.current_source_dir() / 'docs' +output_dir = meson.current_build_dir() / 'html' +doc_target = custom_target('docs', + output: 'html', + input: files('docs/conf.py'), + command: [sphinx_build, '-b', 'html', sphinx_args, input_dir, output_dir], + env: { 'PYTHONPATH': meson.current_build_dir() / 'src' }, + build_by_default: get_option('docs'), + install: get_option('docs'), + install_dir: get_option('datadir') / 'doc' / meson.project_name() +) diff --git a/meson.options b/meson.options new file mode 100644 index 0000000..38dcb92 --- /dev/null +++ b/meson.options @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +option('docs', type : 'boolean', value : false)