blob: 68fa2cc745180a1b233934c9f2c9fd01e8f77032 [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7# Helper class to pull in the right gtk-doc dependencies and configure
8# gtk-doc to enable or disable documentation building (which requries the
9# use of usermode qemu).
10
11# This variable is set to True if api-documentation is in
12# DISTRO_FEATURES and qemu-usermode is in MACHINE_FEATURES, and False otherwise.
13#
14# It should be used in recipes to determine whether gtk-doc based documentation should be built,
15# so that qemu use can be avoided when necessary.
16GTKDOC_ENABLED:class-native = "False"
17GTKDOC_ENABLED ?= "${@bb.utils.contains('DISTRO_FEATURES', 'api-documentation', \
18 bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'True', 'False', d), 'False', d)}"
19
20# meson: default option name to enable/disable gtk-doc. This matches most
21# project's configuration. In doubts - check meson_options.txt in project's
22# source path.
23GTKDOC_MESON_OPTION ?= 'docs'
24GTKDOC_MESON_ENABLE_FLAG ?= 'true'
25GTKDOC_MESON_DISABLE_FLAG ?= 'false'
26
27# Auto enable/disable based on GTKDOC_ENABLED
28EXTRA_OECONF:prepend:class-target = "${@bb.utils.contains('GTKDOC_ENABLED', 'True', '--enable-gtk-doc --enable-gtk-doc-html --disable-gtk-doc-pdf', \
29 '--disable-gtk-doc', d)} "
30EXTRA_OEMESON:prepend:class-target = "-D${GTKDOC_MESON_OPTION}=${@bb.utils.contains('GTKDOC_ENABLED', 'True', '${GTKDOC_MESON_ENABLE_FLAG}', '${GTKDOC_MESON_DISABLE_FLAG}', d)} "
31
32# When building native recipes, disable gtkdoc, as it is not necessary,
33# pulls in additional dependencies, and makes build times longer
34EXTRA_OECONF:prepend:class-native = "--disable-gtk-doc "
35EXTRA_OECONF:prepend:class-nativesdk = "--disable-gtk-doc "
36EXTRA_OEMESON:prepend:class-native = "-D${GTKDOC_MESON_OPTION}=${GTKDOC_MESON_DISABLE_FLAG} "
37EXTRA_OEMESON:prepend:class-nativesdk = "-D${GTKDOC_MESON_OPTION}=${GTKDOC_MESON_DISABLE_FLAG} "
38
39# Even though gtkdoc is disabled on -native, gtk-doc package is still
40# needed for m4 macros.
41DEPENDS:append = " gtk-doc-native"
42
43# The documentation directory, where the infrastructure will be copied.
44# gtkdocize has a default of "." so to handle out-of-tree builds set this to $S.
45GTKDOC_DOCDIR ?= "${S}"
46
47export STAGING_DIR_HOST
48
49inherit python3native pkgconfig qemu
50DEPENDS:append = "${@' qemu-native' if d.getVar('GTKDOC_ENABLED') == 'True' else ''}"
51
52do_configure:prepend () {
53 # Need to use ||true as this is only needed if configure.ac both exists
54 # and uses GTK_DOC_CHECK.
55 gtkdocize --srcdir ${S} --docdir ${GTKDOC_DOCDIR} || true
56}
57
58do_compile:prepend:class-target () {
59 if [ ${GTKDOC_ENABLED} = True ]; then
60 # Write out a qemu wrapper that will be given to gtkdoc-scangobj so that it
61 # can run target helper binaries through that.
62 qemu_binary="${@qemu_wrapper_cmdline(d, '$STAGING_DIR_HOST', ['\\$GIR_EXTRA_LIBS_PATH','$STAGING_DIR_HOST/${libdir}','$STAGING_DIR_HOST/${base_libdir}'])}"
63 cat > ${B}/gtkdoc-qemuwrapper << EOF
64#!/bin/sh
65# Use a modules directory which doesn't exist so we don't load random things
66# which may then get deleted (or their dependencies) and potentially segfault
67export GIO_MODULE_DIR=${STAGING_LIBDIR}/gio/modules-dummy
68
69GIR_EXTRA_LIBS_PATH=\`find ${B} -name *.so -printf "%h\n"|sort|uniq| tr '\n' ':'\`\$GIR_EXTRA_LIBS_PATH
70GIR_EXTRA_LIBS_PATH=\`find ${B} -name .libs| tr '\n' ':'\`\$GIR_EXTRA_LIBS_PATH
71
72# meson sets this wrongly (only to libs in build-dir), qemu_wrapper_cmdline() and GIR_EXTRA_LIBS_PATH take care of it properly
73unset LD_LIBRARY_PATH
74
75if [ -d ".libs" ]; then
76 $qemu_binary ".libs/\$@"
77else
78 $qemu_binary "\$@"
79fi
80
81if [ \$? -ne 0 ]; then
82 echo "If the above error message is about missing .so libraries, then setting up GIR_EXTRA_LIBS_PATH in the recipe should help."
83 echo "(typically like this: GIR_EXTRA_LIBS_PATH=\"$""{B}/something/.libs\" )"
84 exit 1
85fi
86EOF
87 chmod +x ${B}/gtkdoc-qemuwrapper
88 fi
89}