blob: 626b0e789b469a4301d6ffc3300011efe381ad99 [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
15MESONOPTS = " --prefix ${prefix} \
16 --buildtype plain \
17 --bindir ${@noprefix('bindir', d)} \
18 --sbindir ${@noprefix('sbindir', d)} \
19 --datadir ${@noprefix('datadir', d)} \
20 --libdir ${@noprefix('libdir', d)} \
21 --libexecdir ${@noprefix('libexecdir', d)} \
22 --includedir ${@noprefix('includedir', d)} \
23 --mandir ${@noprefix('mandir', d)} \
24 --infodir ${@noprefix('infodir', d)} \
25 --sysconfdir ${sysconfdir} \
26 --localstatedir ${localstatedir} \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080027 --sharedstatedir ${sharedstatedir} \
28 -Dc_args='${BUILD_CPPFLAGS} ${BUILD_CFLAGS}' \
29 -Dc_link_args='${BUILD_LDFLAGS}' \
30 -Dcpp_args='${BUILD_CPPFLAGS} ${BUILD_CXXFLAGS}' \
31 -Dcpp_link_args='${BUILD_LDFLAGS}'"
Brad Bishop316dfdd2018-06-25 12:45:53 -040032
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080033EXTRA_OEMESON_append = " ${PACKAGECONFIG_CONFARGS}"
Brad Bishop316dfdd2018-06-25 12:45:53 -040034
35MESON_CROSS_FILE = ""
36MESON_CROSS_FILE_class-target = "--cross-file ${WORKDIR}/meson.cross"
37MESON_CROSS_FILE_class-nativesdk = "--cross-file ${WORKDIR}/meson.cross"
38
39def meson_array(var, d):
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080040 items = d.getVar(var).split()
41 return repr(items[0] if len(items) == 1 else items)
42
43# Map our ARCH values to what Meson expects:
44# http://mesonbuild.com/Reference-tables.html#cpu-families
45def meson_cpu_family(var, d):
46 import re
47 arch = d.getVar(var)
48 if arch == 'powerpc':
49 return 'ppc'
50 elif arch == 'powerpc64':
51 return 'ppc64'
Brad Bishop19323692019-04-05 15:28:33 -040052 elif arch == 'armeb':
53 return 'arm'
Brad Bishop15ae2502019-06-18 21:44:24 -040054 elif arch == 'aarch64_be':
55 return 'aarch64'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080056 elif arch == 'mipsel':
57 return 'mips'
Brad Bishop19323692019-04-05 15:28:33 -040058 elif arch == 'mips64el':
59 return 'mips64'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080060 elif re.match(r"i[3-6]86", arch):
61 return "x86"
62 else:
63 return arch
64
65def meson_endian(prefix, d):
66 arch, os = d.getVar(prefix + "_ARCH"), d.getVar(prefix + "_OS")
67 sitedata = siteinfo_data_for_machine(arch, os, d)
68 if "endian-little" in sitedata:
69 return "little"
70 elif "endian-big" in sitedata:
71 return "big"
72 else:
73 bb.fatal("Cannot determine endianism for %s-%s" % (arch, os))
Brad Bishop316dfdd2018-06-25 12:45:53 -040074
75addtask write_config before do_configure
Brad Bishop96ff1982019-08-19 13:50:42 -040076do_write_config[vardeps] += "CC CXX LD AR NM STRIP READELF CFLAGS CXXFLAGS LDFLAGS"
Brad Bishop316dfdd2018-06-25 12:45:53 -040077do_write_config() {
78 # This needs to be Py to split the args into single-element lists
79 cat >${WORKDIR}/meson.cross <<EOF
80[binaries]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080081c = ${@meson_array('CC', d)}
82cpp = ${@meson_array('CXX', d)}
83ar = ${@meson_array('AR', d)}
84nm = ${@meson_array('NM', d)}
85ld = ${@meson_array('LD', d)}
86strip = ${@meson_array('STRIP', d)}
87readelf = ${@meson_array('READELF', d)}
Brad Bishop316dfdd2018-06-25 12:45:53 -040088pkgconfig = 'pkg-config'
Brad Bishop19323692019-04-05 15:28:33 -040089llvm-config = 'llvm-config8.0.0'
Brad Bishop316dfdd2018-06-25 12:45:53 -040090
91[properties]
92needs_exe_wrapper = true
Brad Bishop96ff1982019-08-19 13:50:42 -040093c_args = ${@meson_array('CFLAGS', d)}
94c_link_args = ${@meson_array('LDFLAGS', d)}
95cpp_args = ${@meson_array('CXXFLAGS', d)}
96cpp_link_args = ${@meson_array('LDFLAGS', d)}
Brad Bishop316dfdd2018-06-25 12:45:53 -040097gtkdoc_exe_wrapper = '${B}/gtkdoc-qemuwrapper'
98
99[host_machine]
100system = '${HOST_OS}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800101cpu_family = '${@meson_cpu_family('HOST_ARCH', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400102cpu = '${HOST_ARCH}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800103endian = '${@meson_endian('HOST', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400104
105[target_machine]
106system = '${TARGET_OS}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800107cpu_family = '${@meson_cpu_family('TARGET_ARCH', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400108cpu = '${TARGET_ARCH}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800109endian = '${@meson_endian('TARGET', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400110EOF
111}
112
113CONFIGURE_FILES = "meson.build"
114
115meson_do_configure() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800116 # Work around "Meson fails if /tmp is mounted with noexec #2972"
117 mkdir -p "${B}/meson-private/tmp"
118 export TMPDIR="${B}/meson-private/tmp"
119 bbnote Executing meson ${EXTRA_OEMESON}...
Brad Bishop316dfdd2018-06-25 12:45:53 -0400120 if ! meson ${MESONOPTS} "${MESON_SOURCEPATH}" "${B}" ${MESON_CROSS_FILE} ${EXTRA_OEMESON}; then
Brad Bishop316dfdd2018-06-25 12:45:53 -0400121 bbfatal_log meson failed
122 fi
123}
124
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800125override_native_tools() {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400126 # Set these so that meson uses the native tools for its build sanity tests,
127 # which require executables to be runnable. The cross file will still
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800128 # override these for the target build.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400129 export CC="${BUILD_CC}"
130 export CXX="${BUILD_CXX}"
131 export LD="${BUILD_LD}"
132 export AR="${BUILD_AR}"
Brad Bishop96ff1982019-08-19 13:50:42 -0400133 export STRIP="${BUILD_STRIP}"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800134 # These contain *target* flags but will be used as *native* flags. The
135 # correct native flags will be passed via -Dc_args and so on, unset them so
136 # they don't interfere with tools invoked by Meson (such as g-ir-scanner)
137 unset CPPFLAGS CFLAGS CXXFLAGS LDFLAGS
138}
139
140meson_do_configure_prepend_class-target() {
141 override_native_tools
Brad Bishop316dfdd2018-06-25 12:45:53 -0400142}
143
144meson_do_configure_prepend_class-nativesdk() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800145 override_native_tools
Brad Bishop316dfdd2018-06-25 12:45:53 -0400146}
147
148meson_do_configure_prepend_class-native() {
149 export PKG_CONFIG="pkg-config-native"
150}
151
152do_compile[progress] = "outof:^\[(\d+)/(\d+)\]\s+"
153meson_do_compile() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800154 ninja -v ${PARALLEL_MAKE}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400155}
156
157meson_do_install() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800158 DESTDIR='${D}' ninja -v ${PARALLEL_MAKEINST} install
Brad Bishop316dfdd2018-06-25 12:45:53 -0400159}
160
161EXPORT_FUNCTIONS do_configure do_compile do_install