blob: ff52d20e56e56078bfc784cb2bb8be209908937f [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001inherit siteinfo python3native
2
3DEPENDS_append = " meson-native ninja-native"
4
5# As Meson enforces out-of-tree builds we can just use cleandirs
6B = "${WORKDIR}/build"
7do_configure[cleandirs] = "${B}"
8
9# Where the meson.build build configuration is
10MESON_SOURCEPATH = "${S}"
11
12def noprefix(var, d):
13 return d.getVar(var).replace(d.getVar('prefix') + '/', '', 1)
14
15MESON_BUILDTYPE ?= "plain"
16MESONOPTS = " --prefix ${prefix} \
17 --buildtype ${MESON_BUILDTYPE} \
18 --bindir ${@noprefix('bindir', d)} \
19 --sbindir ${@noprefix('sbindir', d)} \
20 --datadir ${@noprefix('datadir', d)} \
21 --libdir ${@noprefix('libdir', d)} \
22 --libexecdir ${@noprefix('libexecdir', d)} \
23 --includedir ${@noprefix('includedir', d)} \
24 --mandir ${@noprefix('mandir', d)} \
25 --infodir ${@noprefix('infodir', d)} \
26 --sysconfdir ${sysconfdir} \
27 --localstatedir ${localstatedir} \
28 --sharedstatedir ${sharedstatedir} \
29 --wrap-mode nodownload"
30
31EXTRA_OEMESON_append = " ${PACKAGECONFIG_CONFARGS}"
32
33MESON_CROSS_FILE = ""
34MESON_CROSS_FILE_class-target = "--cross-file ${WORKDIR}/meson.cross"
35MESON_CROSS_FILE_class-nativesdk = "--cross-file ${WORKDIR}/meson.cross"
36
37def meson_array(var, d):
38 items = d.getVar(var).split()
39 return repr(items[0] if len(items) == 1 else items)
40
41# Map our ARCH values to what Meson expects:
42# http://mesonbuild.com/Reference-tables.html#cpu-families
43def meson_cpu_family(var, d):
44 import re
45 arch = d.getVar(var)
46 if arch == 'powerpc':
47 return 'ppc'
48 elif arch == 'powerpc64' or arch == 'powerpc64le':
49 return 'ppc64'
50 elif arch == 'armeb':
51 return 'arm'
52 elif arch == 'aarch64_be':
53 return 'aarch64'
54 elif arch == 'mipsel':
55 return 'mips'
56 elif arch == 'mips64el':
57 return 'mips64'
58 elif re.match(r"i[3-6]86", arch):
59 return "x86"
60 elif arch == "microblazeel":
61 return "microblaze"
62 else:
63 return arch
64
65# Map our OS values to what Meson expects:
66# https://mesonbuild.com/Reference-tables.html#operating-system-names
67def meson_operating_system(var, d):
68 os = d.getVar(var)
69 if "mingw" in os:
70 return "windows"
71 # avoid e.g 'linux-gnueabi'
72 elif "linux" in os:
73 return "linux"
74 else:
75 return os
76
77def meson_endian(prefix, d):
78 arch, os = d.getVar(prefix + "_ARCH"), d.getVar(prefix + "_OS")
79 sitedata = siteinfo_data_for_machine(arch, os, d)
80 if "endian-little" in sitedata:
81 return "little"
82 elif "endian-big" in sitedata:
83 return "big"
84 else:
85 bb.fatal("Cannot determine endianism for %s-%s" % (arch, os))
86
87addtask write_config before do_configure
88do_write_config[vardeps] += "CC CXX LD AR NM STRIP READELF CFLAGS CXXFLAGS LDFLAGS"
89do_write_config() {
90 # This needs to be Py to split the args into single-element lists
91 cat >${WORKDIR}/meson.cross <<EOF
92[binaries]
93c = ${@meson_array('CC', d)}
94cpp = ${@meson_array('CXX', d)}
95ar = ${@meson_array('AR', d)}
96nm = ${@meson_array('NM', d)}
97strip = ${@meson_array('STRIP', d)}
98readelf = ${@meson_array('READELF', d)}
99pkgconfig = 'pkg-config'
100llvm-config = 'llvm-config${LLVMVERSION}'
101
102[properties]
103needs_exe_wrapper = true
104c_args = ${@meson_array('CFLAGS', d)}
105c_link_args = ${@meson_array('LDFLAGS', d)}
106cpp_args = ${@meson_array('CXXFLAGS', d)}
107cpp_link_args = ${@meson_array('LDFLAGS', d)}
108gtkdoc_exe_wrapper = '${B}/gtkdoc-qemuwrapper'
109
110[host_machine]
111system = '${@meson_operating_system('HOST_OS', d)}'
112cpu_family = '${@meson_cpu_family('HOST_ARCH', d)}'
113cpu = '${HOST_ARCH}'
114endian = '${@meson_endian('HOST', d)}'
115
116[target_machine]
117system = '${@meson_operating_system('TARGET_OS', d)}'
118cpu_family = '${@meson_cpu_family('TARGET_ARCH', d)}'
119cpu = '${TARGET_ARCH}'
120endian = '${@meson_endian('TARGET', d)}'
121EOF
122}
123
124CONFIGURE_FILES = "meson.build"
125
126meson_do_configure() {
127 # Meson requires this to be 'bfd, 'lld' or 'gold' from 0.53 onwards
128 # https://github.com/mesonbuild/meson/commit/ef9aeb188ea2bc7353e59916c18901cde90fa2b3
129 unset LD
130
131 # Work around "Meson fails if /tmp is mounted with noexec #2972"
132 mkdir -p "${B}/meson-private/tmp"
133 export TMPDIR="${B}/meson-private/tmp"
134 bbnote Executing meson ${EXTRA_OEMESON}...
135 if ! meson ${MESONOPTS} "${MESON_SOURCEPATH}" "${B}" ${MESON_CROSS_FILE} ${EXTRA_OEMESON}; then
136 bbfatal_log meson failed
137 fi
138}
139
140override_native_tools() {
141 # Set these so that meson uses the native tools for its build sanity tests,
142 # which require executables to be runnable. The cross file will still
143 # override these for the target build.
144 export CC="${BUILD_CC}"
145 export CXX="${BUILD_CXX}"
146 export LD="${BUILD_LD}"
147 export AR="${BUILD_AR}"
148 export STRIP="${BUILD_STRIP}"
149 # These contain *target* flags but will be used as *native* flags. The
150 # correct native flags will be passed via -Dc_args and so on, unset them so
151 # they don't interfere with tools invoked by Meson (such as g-ir-scanner)
152 unset CPPFLAGS CFLAGS CXXFLAGS LDFLAGS
153}
154
155meson_do_configure_prepend_class-target() {
156 override_native_tools
157}
158
159meson_do_configure_prepend_class-nativesdk() {
160 override_native_tools
161}
162
163meson_do_configure_prepend_class-native() {
164 export PKG_CONFIG="pkg-config-native"
165}
166
167python meson_do_qa_configure() {
168 import re
169 warn_re = re.compile(r"^WARNING: Cross property (.+) is using default value (.+)$", re.MULTILINE)
170 with open(d.expand("${B}/meson-logs/meson-log.txt")) as logfile:
171 log = logfile.read()
172 for (prop, value) in warn_re.findall(log):
173 bb.warn("Meson cross property %s used without explicit assignment, defaulting to %s" % (prop, value))
174}
175do_configure[postfuncs] += "meson_do_qa_configure"
176
177do_compile[progress] = "outof:^\[(\d+)/(\d+)\]\s+"
178meson_do_compile() {
179 ninja -v ${PARALLEL_MAKE}
180}
181
182meson_do_install() {
183 DESTDIR='${D}' ninja -v ${PARALLEL_MAKEINST} install
184}
185
186EXPORT_FUNCTIONS do_configure do_compile do_install