blob: 546cd0476f3d6c87062f00908af03f687e8e5098 [file] [log] [blame]
Andrew Geissler595f6302022-01-24 19:11:47 +00001inherit python3native meson-routines qemu
Brad Bishop316dfdd2018-06-25 12:45:53 -04002
Patrick Williams213cb262021-08-07 19:21:33 -05003DEPENDS:append = " meson-native ninja-native"
Brad Bishop316dfdd2018-06-25 12:45:53 -04004
Andrew Geissler595f6302022-01-24 19:11:47 +00005EXEWRAPPER_ENABLED:class-native = "False"
6EXEWRAPPER_ENABLED:class-nativesdk = "False"
7EXEWRAPPER_ENABLED ?= "${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'True', 'False', d)}"
8DEPENDS:append = "${@' qemu-native' if d.getVar('EXEWRAPPER_ENABLED') == 'True' else ''}"
9
Brad Bishop316dfdd2018-06-25 12:45:53 -040010# As Meson enforces out-of-tree builds we can just use cleandirs
11B = "${WORKDIR}/build"
12do_configure[cleandirs] = "${B}"
13
14# Where the meson.build build configuration is
15MESON_SOURCEPATH = "${S}"
16
17def noprefix(var, d):
18 return d.getVar(var).replace(d.getVar('prefix') + '/', '', 1)
19
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050020MESON_BUILDTYPE ?= "${@oe.utils.vartrue('DEBUG_BUILD', 'debug', 'plain', d)}"
21MESON_BUILDTYPE[vardeps] += "DEBUG_BUILD"
Brad Bishop316dfdd2018-06-25 12:45:53 -040022MESONOPTS = " --prefix ${prefix} \
Andrew Geissler82c905d2020-04-13 13:39:40 -050023 --buildtype ${MESON_BUILDTYPE} \
Brad Bishop316dfdd2018-06-25 12:45:53 -040024 --bindir ${@noprefix('bindir', d)} \
25 --sbindir ${@noprefix('sbindir', d)} \
26 --datadir ${@noprefix('datadir', d)} \
27 --libdir ${@noprefix('libdir', d)} \
28 --libexecdir ${@noprefix('libexecdir', d)} \
29 --includedir ${@noprefix('includedir', d)} \
30 --mandir ${@noprefix('mandir', d)} \
31 --infodir ${@noprefix('infodir', d)} \
32 --sysconfdir ${sysconfdir} \
33 --localstatedir ${localstatedir} \
Andrew Geissler82c905d2020-04-13 13:39:40 -050034 --sharedstatedir ${sharedstatedir} \
Andrew Geissler95ac1b82021-03-31 14:34:31 -050035 --wrap-mode nodownload \
36 --native-file ${WORKDIR}/meson.native"
Brad Bishop316dfdd2018-06-25 12:45:53 -040037
Patrick Williams213cb262021-08-07 19:21:33 -050038EXTRA_OEMESON:append = " ${PACKAGECONFIG_CONFARGS}"
Brad Bishop316dfdd2018-06-25 12:45:53 -040039
40MESON_CROSS_FILE = ""
Patrick Williams213cb262021-08-07 19:21:33 -050041MESON_CROSS_FILE:class-target = "--cross-file ${WORKDIR}/meson.cross"
42MESON_CROSS_FILE:class-nativesdk = "--cross-file ${WORKDIR}/meson.cross"
Brad Bishop316dfdd2018-06-25 12:45:53 -040043
Andrew Geissler595f6302022-01-24 19:11:47 +000044# Needed to set up qemu wrapper below
45export STAGING_DIR_HOST
46
47def rust_tool(d, target_var):
48 rustc = d.getVar('RUSTC')
49 if not rustc:
50 return ""
51 cmd = [rustc, "--target", d.getVar(target_var)] + d.getVar("RUSTFLAGS").split()
52 return "rust = %s" % repr(cmd)
53
Brad Bishop316dfdd2018-06-25 12:45:53 -040054addtask write_config before do_configure
Andrew Geissler595f6302022-01-24 19:11:47 +000055do_write_config[vardeps] += "CC CXX LD AR NM STRIP READELF CFLAGS CXXFLAGS LDFLAGS RUSTC RUSTFLAGS"
Brad Bishop316dfdd2018-06-25 12:45:53 -040056do_write_config() {
57 # This needs to be Py to split the args into single-element lists
58 cat >${WORKDIR}/meson.cross <<EOF
59[binaries]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080060c = ${@meson_array('CC', d)}
61cpp = ${@meson_array('CXX', d)}
Andrew Geissler78b72792022-06-14 06:47:25 -050062cython = 'cython3'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080063ar = ${@meson_array('AR', d)}
64nm = ${@meson_array('NM', d)}
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080065strip = ${@meson_array('STRIP', d)}
66readelf = ${@meson_array('READELF', d)}
Andrew Geissler595f6302022-01-24 19:11:47 +000067objcopy = ${@meson_array('OBJCOPY', d)}
Brad Bishop316dfdd2018-06-25 12:45:53 -040068pkgconfig = 'pkg-config'
Brad Bishop08902b02019-08-20 09:16:51 -040069llvm-config = 'llvm-config${LLVMVERSION}'
Andrew Geissler635e0e42020-08-21 15:58:33 -050070cups-config = 'cups-config'
Andrew Geissler90fd73c2021-03-05 15:25:55 -060071g-ir-scanner = '${STAGING_BINDIR}/g-ir-scanner-wrapper'
72g-ir-compiler = '${STAGING_BINDIR}/g-ir-compiler-wrapper'
Andrew Geissler595f6302022-01-24 19:11:47 +000073${@rust_tool(d, "HOST_SYS")}
74${@"exe_wrapper = '${WORKDIR}/meson-qemuwrapper'" if d.getVar('EXEWRAPPER_ENABLED') == 'True' else ""}
Brad Bishop316dfdd2018-06-25 12:45:53 -040075
Andrew Geissler95ac1b82021-03-31 14:34:31 -050076[built-in options]
Brad Bishop96ff1982019-08-19 13:50:42 -040077c_args = ${@meson_array('CFLAGS', d)}
78c_link_args = ${@meson_array('LDFLAGS', d)}
79cpp_args = ${@meson_array('CXXFLAGS', d)}
80cpp_link_args = ${@meson_array('LDFLAGS', d)}
Andrew Geissler95ac1b82021-03-31 14:34:31 -050081
82[properties]
83needs_exe_wrapper = true
Brad Bishop316dfdd2018-06-25 12:45:53 -040084
85[host_machine]
Andrew Geissler82c905d2020-04-13 13:39:40 -050086system = '${@meson_operating_system('HOST_OS', d)}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080087cpu_family = '${@meson_cpu_family('HOST_ARCH', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -040088cpu = '${HOST_ARCH}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080089endian = '${@meson_endian('HOST', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -040090
91[target_machine]
Andrew Geissler82c905d2020-04-13 13:39:40 -050092system = '${@meson_operating_system('TARGET_OS', d)}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080093cpu_family = '${@meson_cpu_family('TARGET_ARCH', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -040094cpu = '${TARGET_ARCH}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080095endian = '${@meson_endian('TARGET', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -040096EOF
Andrew Geissler95ac1b82021-03-31 14:34:31 -050097
98 cat >${WORKDIR}/meson.native <<EOF
99[binaries]
100c = ${@meson_array('BUILD_CC', d)}
101cpp = ${@meson_array('BUILD_CXX', d)}
Andrew Geissler78b72792022-06-14 06:47:25 -0500102cython = 'cython3'
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500103ar = ${@meson_array('BUILD_AR', d)}
104nm = ${@meson_array('BUILD_NM', d)}
105strip = ${@meson_array('BUILD_STRIP', d)}
106readelf = ${@meson_array('BUILD_READELF', d)}
Andrew Geissler595f6302022-01-24 19:11:47 +0000107objcopy = ${@meson_array('BUILD_OBJCOPY', d)}
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500108pkgconfig = 'pkg-config-native'
Andrew Geissler595f6302022-01-24 19:11:47 +0000109${@rust_tool(d, "BUILD_SYS")}
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500110
111[built-in options]
112c_args = ${@meson_array('BUILD_CFLAGS', d)}
113c_link_args = ${@meson_array('BUILD_LDFLAGS', d)}
114cpp_args = ${@meson_array('BUILD_CXXFLAGS', d)}
115cpp_link_args = ${@meson_array('BUILD_LDFLAGS', d)}
116EOF
Brad Bishop316dfdd2018-06-25 12:45:53 -0400117}
118
Andrew Geissler595f6302022-01-24 19:11:47 +0000119do_write_config:append:class-target() {
120 # Write out a qemu wrapper that will be used as exe_wrapper so that meson
121 # can run target helper binaries through that.
122 qemu_binary="${@qemu_wrapper_cmdline(d, '$STAGING_DIR_HOST', ['$STAGING_DIR_HOST/${libdir}','$STAGING_DIR_HOST/${base_libdir}'])}"
123 cat > ${WORKDIR}/meson-qemuwrapper << EOF
124#!/bin/sh
125# Use a modules directory which doesn't exist so we don't load random things
126# which may then get deleted (or their dependencies) and potentially segfault
127export GIO_MODULE_DIR=${STAGING_LIBDIR}/gio/modules-dummy
128
129# meson sets this wrongly (only to libs in build-dir), qemu_wrapper_cmdline() and GIR_EXTRA_LIBS_PATH take care of it properly
130unset LD_LIBRARY_PATH
131
132$qemu_binary "\$@"
133EOF
134 chmod +x ${WORKDIR}/meson-qemuwrapper
135}
136
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500137# Tell externalsrc that changes to this file require a reconfigure
Brad Bishop316dfdd2018-06-25 12:45:53 -0400138CONFIGURE_FILES = "meson.build"
139
140meson_do_configure() {
Andrew Geissler82c905d2020-04-13 13:39:40 -0500141 # Meson requires this to be 'bfd, 'lld' or 'gold' from 0.53 onwards
142 # https://github.com/mesonbuild/meson/commit/ef9aeb188ea2bc7353e59916c18901cde90fa2b3
143 unset LD
144
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800145 # Work around "Meson fails if /tmp is mounted with noexec #2972"
146 mkdir -p "${B}/meson-private/tmp"
147 export TMPDIR="${B}/meson-private/tmp"
148 bbnote Executing meson ${EXTRA_OEMESON}...
Brad Bishop316dfdd2018-06-25 12:45:53 -0400149 if ! meson ${MESONOPTS} "${MESON_SOURCEPATH}" "${B}" ${MESON_CROSS_FILE} ${EXTRA_OEMESON}; then
Brad Bishop316dfdd2018-06-25 12:45:53 -0400150 bbfatal_log meson failed
151 fi
152}
153
Andrew Geissler82c905d2020-04-13 13:39:40 -0500154python meson_do_qa_configure() {
155 import re
156 warn_re = re.compile(r"^WARNING: Cross property (.+) is using default value (.+)$", re.MULTILINE)
Andrew Geisslerc182c622020-05-15 14:13:32 -0500157 with open(d.expand("${B}/meson-logs/meson-log.txt")) as logfile:
158 log = logfile.read()
Andrew Geissler82c905d2020-04-13 13:39:40 -0500159 for (prop, value) in warn_re.findall(log):
160 bb.warn("Meson cross property %s used without explicit assignment, defaulting to %s" % (prop, value))
161}
162do_configure[postfuncs] += "meson_do_qa_configure"
163
Brad Bishop316dfdd2018-06-25 12:45:53 -0400164do_compile[progress] = "outof:^\[(\d+)/(\d+)\]\s+"
165meson_do_compile() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800166 ninja -v ${PARALLEL_MAKE}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400167}
168
169meson_do_install() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800170 DESTDIR='${D}' ninja -v ${PARALLEL_MAKEINST} install
Brad Bishop316dfdd2018-06-25 12:45:53 -0400171}
172
173EXPORT_FUNCTIONS do_configure do_compile do_install