blob: bf9b02e06ecf012e11fd708a0bf12816338ac4dc [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001inherit siteinfo python3native
Brad Bishop316dfdd2018-06-25 12:45:53 -04002
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
Andrew Geissler82c905d2020-04-13 13:39:40 -050015MESON_BUILDTYPE ?= "plain"
Brad Bishop316dfdd2018-06-25 12:45:53 -040016MESONOPTS = " --prefix ${prefix} \
Andrew Geissler82c905d2020-04-13 13:39:40 -050017 --buildtype ${MESON_BUILDTYPE} \
Brad Bishop316dfdd2018-06-25 12:45:53 -040018 --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} \
Andrew Geissler82c905d2020-04-13 13:39:40 -050028 --sharedstatedir ${sharedstatedir} \
Andrew Geissler95ac1b82021-03-31 14:34:31 -050029 --wrap-mode nodownload \
30 --native-file ${WORKDIR}/meson.native"
Brad Bishop316dfdd2018-06-25 12:45:53 -040031
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080032EXTRA_OEMESON_append = " ${PACKAGECONFIG_CONFARGS}"
Brad Bishop316dfdd2018-06-25 12:45:53 -040033
34MESON_CROSS_FILE = ""
35MESON_CROSS_FILE_class-target = "--cross-file ${WORKDIR}/meson.cross"
36MESON_CROSS_FILE_class-nativesdk = "--cross-file ${WORKDIR}/meson.cross"
37
38def meson_array(var, d):
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080039 items = d.getVar(var).split()
40 return repr(items[0] if len(items) == 1 else items)
41
42# Map our ARCH values to what Meson expects:
43# http://mesonbuild.com/Reference-tables.html#cpu-families
44def meson_cpu_family(var, d):
45 import re
46 arch = d.getVar(var)
47 if arch == 'powerpc':
48 return 'ppc'
Andrew Geissler82c905d2020-04-13 13:39:40 -050049 elif arch == 'powerpc64' or arch == 'powerpc64le':
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080050 return 'ppc64'
Brad Bishop19323692019-04-05 15:28:33 -040051 elif arch == 'armeb':
52 return 'arm'
Brad Bishop15ae2502019-06-18 21:44:24 -040053 elif arch == 'aarch64_be':
54 return 'aarch64'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080055 elif arch == 'mipsel':
56 return 'mips'
Brad Bishop19323692019-04-05 15:28:33 -040057 elif arch == 'mips64el':
58 return 'mips64'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080059 elif re.match(r"i[3-6]86", arch):
60 return "x86"
Andrew Geissler82c905d2020-04-13 13:39:40 -050061 elif arch == "microblazeel":
Brad Bishopa34c0302019-09-23 22:34:48 -040062 return "microblaze"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080063 else:
64 return arch
65
Andrew Geissler82c905d2020-04-13 13:39:40 -050066# Map our OS values to what Meson expects:
67# https://mesonbuild.com/Reference-tables.html#operating-system-names
68def meson_operating_system(var, d):
69 os = d.getVar(var)
70 if "mingw" in os:
71 return "windows"
Andrew Geisslerd25ed322020-06-27 00:28:28 -050072 # avoid e.g 'linux-gnueabi'
73 elif "linux" in os:
74 return "linux"
Andrew Geissler82c905d2020-04-13 13:39:40 -050075 else:
76 return os
77
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080078def meson_endian(prefix, d):
79 arch, os = d.getVar(prefix + "_ARCH"), d.getVar(prefix + "_OS")
80 sitedata = siteinfo_data_for_machine(arch, os, d)
81 if "endian-little" in sitedata:
82 return "little"
83 elif "endian-big" in sitedata:
84 return "big"
85 else:
86 bb.fatal("Cannot determine endianism for %s-%s" % (arch, os))
Brad Bishop316dfdd2018-06-25 12:45:53 -040087
88addtask write_config before do_configure
Brad Bishop96ff1982019-08-19 13:50:42 -040089do_write_config[vardeps] += "CC CXX LD AR NM STRIP READELF CFLAGS CXXFLAGS LDFLAGS"
Brad Bishop316dfdd2018-06-25 12:45:53 -040090do_write_config() {
91 # This needs to be Py to split the args into single-element lists
92 cat >${WORKDIR}/meson.cross <<EOF
93[binaries]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080094c = ${@meson_array('CC', d)}
95cpp = ${@meson_array('CXX', d)}
96ar = ${@meson_array('AR', d)}
97nm = ${@meson_array('NM', d)}
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080098strip = ${@meson_array('STRIP', d)}
99readelf = ${@meson_array('READELF', d)}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400100pkgconfig = 'pkg-config'
Brad Bishop08902b02019-08-20 09:16:51 -0400101llvm-config = 'llvm-config${LLVMVERSION}'
Andrew Geissler635e0e42020-08-21 15:58:33 -0500102cups-config = 'cups-config'
Andrew Geissler90fd73c2021-03-05 15:25:55 -0600103g-ir-scanner = '${STAGING_BINDIR}/g-ir-scanner-wrapper'
104g-ir-compiler = '${STAGING_BINDIR}/g-ir-compiler-wrapper'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400105
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500106[built-in options]
Brad Bishop96ff1982019-08-19 13:50:42 -0400107c_args = ${@meson_array('CFLAGS', d)}
108c_link_args = ${@meson_array('LDFLAGS', d)}
109cpp_args = ${@meson_array('CXXFLAGS', d)}
110cpp_link_args = ${@meson_array('LDFLAGS', d)}
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500111
112[properties]
113needs_exe_wrapper = true
Brad Bishop316dfdd2018-06-25 12:45:53 -0400114gtkdoc_exe_wrapper = '${B}/gtkdoc-qemuwrapper'
115
116[host_machine]
Andrew Geissler82c905d2020-04-13 13:39:40 -0500117system = '${@meson_operating_system('HOST_OS', d)}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800118cpu_family = '${@meson_cpu_family('HOST_ARCH', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400119cpu = '${HOST_ARCH}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800120endian = '${@meson_endian('HOST', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400121
122[target_machine]
Andrew Geissler82c905d2020-04-13 13:39:40 -0500123system = '${@meson_operating_system('TARGET_OS', d)}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800124cpu_family = '${@meson_cpu_family('TARGET_ARCH', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400125cpu = '${TARGET_ARCH}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800126endian = '${@meson_endian('TARGET', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400127EOF
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500128
129 cat >${WORKDIR}/meson.native <<EOF
130[binaries]
131c = ${@meson_array('BUILD_CC', d)}
132cpp = ${@meson_array('BUILD_CXX', d)}
133ar = ${@meson_array('BUILD_AR', d)}
134nm = ${@meson_array('BUILD_NM', d)}
135strip = ${@meson_array('BUILD_STRIP', d)}
136readelf = ${@meson_array('BUILD_READELF', d)}
137pkgconfig = 'pkg-config-native'
138
139[built-in options]
140c_args = ${@meson_array('BUILD_CFLAGS', d)}
141c_link_args = ${@meson_array('BUILD_LDFLAGS', d)}
142cpp_args = ${@meson_array('BUILD_CXXFLAGS', d)}
143cpp_link_args = ${@meson_array('BUILD_LDFLAGS', d)}
144EOF
Brad Bishop316dfdd2018-06-25 12:45:53 -0400145}
146
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500147# Tell externalsrc that changes to this file require a reconfigure
Brad Bishop316dfdd2018-06-25 12:45:53 -0400148CONFIGURE_FILES = "meson.build"
149
150meson_do_configure() {
Andrew Geissler82c905d2020-04-13 13:39:40 -0500151 # Meson requires this to be 'bfd, 'lld' or 'gold' from 0.53 onwards
152 # https://github.com/mesonbuild/meson/commit/ef9aeb188ea2bc7353e59916c18901cde90fa2b3
153 unset LD
154
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800155 # Work around "Meson fails if /tmp is mounted with noexec #2972"
156 mkdir -p "${B}/meson-private/tmp"
157 export TMPDIR="${B}/meson-private/tmp"
158 bbnote Executing meson ${EXTRA_OEMESON}...
Brad Bishop316dfdd2018-06-25 12:45:53 -0400159 if ! meson ${MESONOPTS} "${MESON_SOURCEPATH}" "${B}" ${MESON_CROSS_FILE} ${EXTRA_OEMESON}; then
Brad Bishop316dfdd2018-06-25 12:45:53 -0400160 bbfatal_log meson failed
161 fi
162}
163
Andrew Geissler82c905d2020-04-13 13:39:40 -0500164python meson_do_qa_configure() {
165 import re
166 warn_re = re.compile(r"^WARNING: Cross property (.+) is using default value (.+)$", re.MULTILINE)
Andrew Geisslerc182c622020-05-15 14:13:32 -0500167 with open(d.expand("${B}/meson-logs/meson-log.txt")) as logfile:
168 log = logfile.read()
Andrew Geissler82c905d2020-04-13 13:39:40 -0500169 for (prop, value) in warn_re.findall(log):
170 bb.warn("Meson cross property %s used without explicit assignment, defaulting to %s" % (prop, value))
171}
172do_configure[postfuncs] += "meson_do_qa_configure"
173
Brad Bishop316dfdd2018-06-25 12:45:53 -0400174do_compile[progress] = "outof:^\[(\d+)/(\d+)\]\s+"
175meson_do_compile() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800176 ninja -v ${PARALLEL_MAKE}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400177}
178
179meson_do_install() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800180 DESTDIR='${D}' ninja -v ${PARALLEL_MAKEINST} install
Brad Bishop316dfdd2018-06-25 12:45:53 -0400181}
182
183EXPORT_FUNCTIONS do_configure do_compile do_install