blob: efa623407840e04391af801dc0792e864de53b9a [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 Bishop08902b02019-08-20 09:16:51 -040027 --sharedstatedir ${sharedstatedir} "
Brad Bishop316dfdd2018-06-25 12:45:53 -040028
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080029EXTRA_OEMESON_append = " ${PACKAGECONFIG_CONFARGS}"
Brad Bishop316dfdd2018-06-25 12:45:53 -040030
31MESON_CROSS_FILE = ""
32MESON_CROSS_FILE_class-target = "--cross-file ${WORKDIR}/meson.cross"
33MESON_CROSS_FILE_class-nativesdk = "--cross-file ${WORKDIR}/meson.cross"
34
35def meson_array(var, d):
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080036 items = d.getVar(var).split()
37 return repr(items[0] if len(items) == 1 else items)
38
39# Map our ARCH values to what Meson expects:
40# http://mesonbuild.com/Reference-tables.html#cpu-families
41def meson_cpu_family(var, d):
42 import re
43 arch = d.getVar(var)
44 if arch == 'powerpc':
45 return 'ppc'
46 elif arch == 'powerpc64':
47 return 'ppc64'
Brad Bishop19323692019-04-05 15:28:33 -040048 elif arch == 'armeb':
49 return 'arm'
Brad Bishop15ae2502019-06-18 21:44:24 -040050 elif arch == 'aarch64_be':
51 return 'aarch64'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080052 elif arch == 'mipsel':
53 return 'mips'
Brad Bishop19323692019-04-05 15:28:33 -040054 elif arch == 'mips64el':
55 return 'mips64'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080056 elif re.match(r"i[3-6]86", arch):
57 return "x86"
Brad Bishopa34c0302019-09-23 22:34:48 -040058 elif arch == "microblazeel" or arch == "microblazeeb":
59 return "microblaze"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080060 else:
61 return arch
62
63def meson_endian(prefix, d):
64 arch, os = d.getVar(prefix + "_ARCH"), d.getVar(prefix + "_OS")
65 sitedata = siteinfo_data_for_machine(arch, os, d)
66 if "endian-little" in sitedata:
67 return "little"
68 elif "endian-big" in sitedata:
69 return "big"
70 else:
71 bb.fatal("Cannot determine endianism for %s-%s" % (arch, os))
Brad Bishop316dfdd2018-06-25 12:45:53 -040072
73addtask write_config before do_configure
Brad Bishop96ff1982019-08-19 13:50:42 -040074do_write_config[vardeps] += "CC CXX LD AR NM STRIP READELF CFLAGS CXXFLAGS LDFLAGS"
Brad Bishop316dfdd2018-06-25 12:45:53 -040075do_write_config() {
76 # This needs to be Py to split the args into single-element lists
77 cat >${WORKDIR}/meson.cross <<EOF
78[binaries]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080079c = ${@meson_array('CC', d)}
80cpp = ${@meson_array('CXX', d)}
81ar = ${@meson_array('AR', d)}
82nm = ${@meson_array('NM', d)}
83ld = ${@meson_array('LD', d)}
84strip = ${@meson_array('STRIP', d)}
85readelf = ${@meson_array('READELF', d)}
Brad Bishop316dfdd2018-06-25 12:45:53 -040086pkgconfig = 'pkg-config'
Brad Bishop08902b02019-08-20 09:16:51 -040087llvm-config = 'llvm-config${LLVMVERSION}'
Brad Bishop316dfdd2018-06-25 12:45:53 -040088
89[properties]
90needs_exe_wrapper = true
Brad Bishop96ff1982019-08-19 13:50:42 -040091c_args = ${@meson_array('CFLAGS', d)}
92c_link_args = ${@meson_array('LDFLAGS', d)}
93cpp_args = ${@meson_array('CXXFLAGS', d)}
94cpp_link_args = ${@meson_array('LDFLAGS', d)}
Brad Bishop316dfdd2018-06-25 12:45:53 -040095gtkdoc_exe_wrapper = '${B}/gtkdoc-qemuwrapper'
96
97[host_machine]
98system = '${HOST_OS}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080099cpu_family = '${@meson_cpu_family('HOST_ARCH', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400100cpu = '${HOST_ARCH}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800101endian = '${@meson_endian('HOST', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400102
103[target_machine]
104system = '${TARGET_OS}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800105cpu_family = '${@meson_cpu_family('TARGET_ARCH', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400106cpu = '${TARGET_ARCH}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800107endian = '${@meson_endian('TARGET', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400108EOF
109}
110
111CONFIGURE_FILES = "meson.build"
112
113meson_do_configure() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800114 # Work around "Meson fails if /tmp is mounted with noexec #2972"
115 mkdir -p "${B}/meson-private/tmp"
116 export TMPDIR="${B}/meson-private/tmp"
117 bbnote Executing meson ${EXTRA_OEMESON}...
Brad Bishop316dfdd2018-06-25 12:45:53 -0400118 if ! meson ${MESONOPTS} "${MESON_SOURCEPATH}" "${B}" ${MESON_CROSS_FILE} ${EXTRA_OEMESON}; then
Brad Bishop316dfdd2018-06-25 12:45:53 -0400119 bbfatal_log meson failed
120 fi
121}
122
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800123override_native_tools() {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400124 # Set these so that meson uses the native tools for its build sanity tests,
125 # which require executables to be runnable. The cross file will still
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800126 # override these for the target build.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400127 export CC="${BUILD_CC}"
128 export CXX="${BUILD_CXX}"
129 export LD="${BUILD_LD}"
130 export AR="${BUILD_AR}"
Brad Bishop96ff1982019-08-19 13:50:42 -0400131 export STRIP="${BUILD_STRIP}"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800132 # These contain *target* flags but will be used as *native* flags. The
133 # correct native flags will be passed via -Dc_args and so on, unset them so
134 # they don't interfere with tools invoked by Meson (such as g-ir-scanner)
135 unset CPPFLAGS CFLAGS CXXFLAGS LDFLAGS
136}
137
138meson_do_configure_prepend_class-target() {
139 override_native_tools
Brad Bishop316dfdd2018-06-25 12:45:53 -0400140}
141
142meson_do_configure_prepend_class-nativesdk() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800143 override_native_tools
Brad Bishop316dfdd2018-06-25 12:45:53 -0400144}
145
146meson_do_configure_prepend_class-native() {
147 export PKG_CONFIG="pkg-config-native"
148}
149
150do_compile[progress] = "outof:^\[(\d+)/(\d+)\]\s+"
151meson_do_compile() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800152 ninja -v ${PARALLEL_MAKE}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400153}
154
155meson_do_install() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800156 DESTDIR='${D}' ninja -v ${PARALLEL_MAKEINST} install
Brad Bishop316dfdd2018-06-25 12:45:53 -0400157}
158
159EXPORT_FUNCTIONS do_configure do_compile do_install