blob: 83aa854b7e9d5119c29f4a48e303bd113674516d [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} \
29 --wrap-mode nodownload"
Brad Bishop316dfdd2018-06-25 12:45:53 -040030
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080031EXTRA_OEMESON_append = " ${PACKAGECONFIG_CONFARGS}"
Brad Bishop316dfdd2018-06-25 12:45:53 -040032
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):
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080038 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'
Andrew Geissler82c905d2020-04-13 13:39:40 -050048 elif arch == 'powerpc64' or arch == 'powerpc64le':
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080049 return 'ppc64'
Brad Bishop19323692019-04-05 15:28:33 -040050 elif arch == 'armeb':
51 return 'arm'
Brad Bishop15ae2502019-06-18 21:44:24 -040052 elif arch == 'aarch64_be':
53 return 'aarch64'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080054 elif arch == 'mipsel':
55 return 'mips'
Brad Bishop19323692019-04-05 15:28:33 -040056 elif arch == 'mips64el':
57 return 'mips64'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080058 elif re.match(r"i[3-6]86", arch):
59 return "x86"
Andrew Geissler82c905d2020-04-13 13:39:40 -050060 elif arch == "microblazeel":
Brad Bishopa34c0302019-09-23 22:34:48 -040061 return "microblaze"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080062 else:
63 return arch
64
Andrew Geissler82c905d2020-04-13 13:39:40 -050065# 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"
Andrew Geisslerd25ed322020-06-27 00:28:28 -050071 # avoid e.g 'linux-gnueabi'
72 elif "linux" in os:
73 return "linux"
Andrew Geissler82c905d2020-04-13 13:39:40 -050074 else:
75 return os
76
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080077def 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))
Brad Bishop316dfdd2018-06-25 12:45:53 -040086
87addtask write_config before do_configure
Brad Bishop96ff1982019-08-19 13:50:42 -040088do_write_config[vardeps] += "CC CXX LD AR NM STRIP READELF CFLAGS CXXFLAGS LDFLAGS"
Brad Bishop316dfdd2018-06-25 12:45:53 -040089do_write_config() {
90 # This needs to be Py to split the args into single-element lists
91 cat >${WORKDIR}/meson.cross <<EOF
92[binaries]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080093c = ${@meson_array('CC', d)}
94cpp = ${@meson_array('CXX', d)}
95ar = ${@meson_array('AR', d)}
96nm = ${@meson_array('NM', d)}
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080097strip = ${@meson_array('STRIP', d)}
98readelf = ${@meson_array('READELF', d)}
Brad Bishop316dfdd2018-06-25 12:45:53 -040099pkgconfig = 'pkg-config'
Brad Bishop08902b02019-08-20 09:16:51 -0400100llvm-config = 'llvm-config${LLVMVERSION}'
Andrew Geissler635e0e42020-08-21 15:58:33 -0500101cups-config = 'cups-config'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400102
103[properties]
104needs_exe_wrapper = true
Brad Bishop96ff1982019-08-19 13:50:42 -0400105c_args = ${@meson_array('CFLAGS', d)}
106c_link_args = ${@meson_array('LDFLAGS', d)}
107cpp_args = ${@meson_array('CXXFLAGS', d)}
108cpp_link_args = ${@meson_array('LDFLAGS', d)}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400109gtkdoc_exe_wrapper = '${B}/gtkdoc-qemuwrapper'
110
111[host_machine]
Andrew Geissler82c905d2020-04-13 13:39:40 -0500112system = '${@meson_operating_system('HOST_OS', d)}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800113cpu_family = '${@meson_cpu_family('HOST_ARCH', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400114cpu = '${HOST_ARCH}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800115endian = '${@meson_endian('HOST', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400116
117[target_machine]
Andrew Geissler82c905d2020-04-13 13:39:40 -0500118system = '${@meson_operating_system('TARGET_OS', d)}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800119cpu_family = '${@meson_cpu_family('TARGET_ARCH', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400120cpu = '${TARGET_ARCH}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800121endian = '${@meson_endian('TARGET', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400122EOF
123}
124
125CONFIGURE_FILES = "meson.build"
126
127meson_do_configure() {
Andrew Geissler82c905d2020-04-13 13:39:40 -0500128 # Meson requires this to be 'bfd, 'lld' or 'gold' from 0.53 onwards
129 # https://github.com/mesonbuild/meson/commit/ef9aeb188ea2bc7353e59916c18901cde90fa2b3
130 unset LD
131
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800132 # Work around "Meson fails if /tmp is mounted with noexec #2972"
133 mkdir -p "${B}/meson-private/tmp"
134 export TMPDIR="${B}/meson-private/tmp"
135 bbnote Executing meson ${EXTRA_OEMESON}...
Brad Bishop316dfdd2018-06-25 12:45:53 -0400136 if ! meson ${MESONOPTS} "${MESON_SOURCEPATH}" "${B}" ${MESON_CROSS_FILE} ${EXTRA_OEMESON}; then
Brad Bishop316dfdd2018-06-25 12:45:53 -0400137 bbfatal_log meson failed
138 fi
139}
140
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800141override_native_tools() {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400142 # Set these so that meson uses the native tools for its build sanity tests,
143 # which require executables to be runnable. The cross file will still
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800144 # override these for the target build.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400145 export CC="${BUILD_CC}"
146 export CXX="${BUILD_CXX}"
147 export LD="${BUILD_LD}"
148 export AR="${BUILD_AR}"
Brad Bishop96ff1982019-08-19 13:50:42 -0400149 export STRIP="${BUILD_STRIP}"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800150 # These contain *target* flags but will be used as *native* flags. The
151 # correct native flags will be passed via -Dc_args and so on, unset them so
152 # they don't interfere with tools invoked by Meson (such as g-ir-scanner)
153 unset CPPFLAGS CFLAGS CXXFLAGS LDFLAGS
154}
155
156meson_do_configure_prepend_class-target() {
157 override_native_tools
Brad Bishop316dfdd2018-06-25 12:45:53 -0400158}
159
160meson_do_configure_prepend_class-nativesdk() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800161 override_native_tools
Brad Bishop316dfdd2018-06-25 12:45:53 -0400162}
163
164meson_do_configure_prepend_class-native() {
165 export PKG_CONFIG="pkg-config-native"
166}
167
Andrew Geissler82c905d2020-04-13 13:39:40 -0500168python meson_do_qa_configure() {
169 import re
170 warn_re = re.compile(r"^WARNING: Cross property (.+) is using default value (.+)$", re.MULTILINE)
Andrew Geisslerc182c622020-05-15 14:13:32 -0500171 with open(d.expand("${B}/meson-logs/meson-log.txt")) as logfile:
172 log = logfile.read()
Andrew Geissler82c905d2020-04-13 13:39:40 -0500173 for (prop, value) in warn_re.findall(log):
174 bb.warn("Meson cross property %s used without explicit assignment, defaulting to %s" % (prop, value))
175}
176do_configure[postfuncs] += "meson_do_qa_configure"
177
Brad Bishop316dfdd2018-06-25 12:45:53 -0400178do_compile[progress] = "outof:^\[(\d+)/(\d+)\]\s+"
179meson_do_compile() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800180 ninja -v ${PARALLEL_MAKE}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400181}
182
183meson_do_install() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800184 DESTDIR='${D}' ninja -v ${PARALLEL_MAKEINST} install
Brad Bishop316dfdd2018-06-25 12:45:53 -0400185}
186
187EXPORT_FUNCTIONS do_configure do_compile do_install