Sometimes it is necessary to give Meson configuration beyond what the
eclass currently writes to the .ini files. Multiple native and cross
files can be specified, and Meson will use them all. The only rule is
that you cannot repeat a section within the same file.

The given argument is used to form the filename for the .ini file. It is
important for the filename to be unique because timestamp changes will
trigger a reconfigure.

meson_append_file uses either --native-file or --cross-file depending on
whether we're cross-compiling (including multilib) or not.

Signed-off-by: James Le Cuirot <[email protected]>
---
 eclass/meson.eclass | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/eclass/meson.eclass b/eclass/meson.eclass
index d43eccaa5cc71..300f035a12931 100644
--- a/eclass/meson.eclass
+++ b/eclass/meson.eclass
@@ -77,7 +77,7 @@ BDEPEND=">=dev-build/meson-1.2.3
 # @DEFAULT_UNSET
 # @DESCRIPTION:
 # Optional meson arguments as Bash array; this should be defined before
-# calling meson_src_configure.
+# calling meson_src_configure, meson_append_file, or meson_append_native_file.
 
 # @VARIABLE: MYMESONARGS
 # @DEFAULT_UNSET
@@ -271,6 +271,33 @@ _meson_create_native_file() {
        echo "${fn}"
 }
 
+# @FUNCTION: meson_append_file
+# @USAGE: <name> < <data>
+# @DESCRIPTION:
+# Appends --native-file or --cross-file to emesonargs with the data given via
+# standard input. Assumes emesonargs has already been defined as an array.
+meson_append_file() {
+       local file=${T}/meson.${CHOST}.${ABI}.${1}.ini
+       cat > "${file}" || die
+
+       if tc-is-cross-compiler || [[ ${ABI} != "${DEFAULT_ABI}" ]]; then
+               emesonargs+=( --cross-file "${file}" )
+       else
+               emesonargs+=( --native-file "${file}" )
+       fi
+}
+
+# @FUNCTION: meson_append_native_file
+# @USAGE: <name> < <data>
+# @DESCRIPTION:
+# Appends --native-file (never --cross-file) to emesonargs with the data given
+# via standard input. Assumes emesonargs has already been defined as an array.
+meson_append_native_file() {
+       # Ensure the filename is unique by including the target tuple and ABI.
+       local name=${CHOST}.${ABI}.${1} CHOST=${CBUILD} ABI=${DEFAULT_ABI}
+       meson_append_file "${name}"
+}
+
 # @FUNCTION: meson_use
 # @USAGE: <USE flag> [option name]
 # @DESCRIPTION:
-- 
2.52.0


Reply via email to