blob: 115d1aedcb1c638a5799db1facd3394a9e84486e [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
33MESON_TOOLCHAIN_ARGS = "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}"
34MESON_C_ARGS = "${MESON_TOOLCHAIN_ARGS} ${CFLAGS}"
35MESON_CPP_ARGS = "${MESON_TOOLCHAIN_ARGS} ${CXXFLAGS}"
36MESON_LINK_ARGS = "${MESON_TOOLCHAIN_ARGS} ${LDFLAGS}"
37
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080038EXTRA_OEMESON_append = " ${PACKAGECONFIG_CONFARGS}"
Brad Bishop316dfdd2018-06-25 12:45:53 -040039
40MESON_CROSS_FILE = ""
41MESON_CROSS_FILE_class-target = "--cross-file ${WORKDIR}/meson.cross"
42MESON_CROSS_FILE_class-nativesdk = "--cross-file ${WORKDIR}/meson.cross"
43
44def meson_array(var, d):
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080045 items = d.getVar(var).split()
46 return repr(items[0] if len(items) == 1 else items)
47
48# Map our ARCH values to what Meson expects:
49# http://mesonbuild.com/Reference-tables.html#cpu-families
50def meson_cpu_family(var, d):
51 import re
52 arch = d.getVar(var)
53 if arch == 'powerpc':
54 return 'ppc'
55 elif arch == 'powerpc64':
56 return 'ppc64'
Brad Bishop19323692019-04-05 15:28:33 -040057 elif arch == 'armeb':
58 return 'arm'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080059 elif arch == 'mipsel':
60 return 'mips'
Brad Bishop19323692019-04-05 15:28:33 -040061 elif arch == 'mips64el':
62 return 'mips64'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080063 elif re.match(r"i[3-6]86", arch):
64 return "x86"
65 else:
66 return arch
67
68def meson_endian(prefix, d):
69 arch, os = d.getVar(prefix + "_ARCH"), d.getVar(prefix + "_OS")
70 sitedata = siteinfo_data_for_machine(arch, os, d)
71 if "endian-little" in sitedata:
72 return "little"
73 elif "endian-big" in sitedata:
74 return "big"
75 else:
76 bb.fatal("Cannot determine endianism for %s-%s" % (arch, os))
Brad Bishop316dfdd2018-06-25 12:45:53 -040077
78addtask write_config before do_configure
79do_write_config[vardeps] += "MESON_C_ARGS MESON_CPP_ARGS MESON_LINK_ARGS CC CXX LD AR NM STRIP READELF"
80do_write_config() {
81 # This needs to be Py to split the args into single-element lists
82 cat >${WORKDIR}/meson.cross <<EOF
83[binaries]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080084c = ${@meson_array('CC', d)}
85cpp = ${@meson_array('CXX', d)}
86ar = ${@meson_array('AR', d)}
87nm = ${@meson_array('NM', d)}
88ld = ${@meson_array('LD', d)}
89strip = ${@meson_array('STRIP', d)}
90readelf = ${@meson_array('READELF', d)}
Brad Bishop316dfdd2018-06-25 12:45:53 -040091pkgconfig = 'pkg-config'
Brad Bishop19323692019-04-05 15:28:33 -040092llvm-config = 'llvm-config8.0.0'
Brad Bishop316dfdd2018-06-25 12:45:53 -040093
94[properties]
95needs_exe_wrapper = true
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080096c_args = ${@meson_array('MESON_C_ARGS', d)}
97c_link_args = ${@meson_array('MESON_LINK_ARGS', d)}
98cpp_args = ${@meson_array('MESON_CPP_ARGS', d)}
99cpp_link_args = ${@meson_array('MESON_LINK_ARGS', d)}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400100gtkdoc_exe_wrapper = '${B}/gtkdoc-qemuwrapper'
101
102[host_machine]
103system = '${HOST_OS}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800104cpu_family = '${@meson_cpu_family('HOST_ARCH', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400105cpu = '${HOST_ARCH}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800106endian = '${@meson_endian('HOST', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400107
108[target_machine]
109system = '${TARGET_OS}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800110cpu_family = '${@meson_cpu_family('TARGET_ARCH', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400111cpu = '${TARGET_ARCH}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800112endian = '${@meson_endian('TARGET', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400113EOF
114}
115
116CONFIGURE_FILES = "meson.build"
117
118meson_do_configure() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800119 # Work around "Meson fails if /tmp is mounted with noexec #2972"
120 mkdir -p "${B}/meson-private/tmp"
121 export TMPDIR="${B}/meson-private/tmp"
122 bbnote Executing meson ${EXTRA_OEMESON}...
Brad Bishop316dfdd2018-06-25 12:45:53 -0400123 if ! meson ${MESONOPTS} "${MESON_SOURCEPATH}" "${B}" ${MESON_CROSS_FILE} ${EXTRA_OEMESON}; then
Brad Bishop316dfdd2018-06-25 12:45:53 -0400124 bbfatal_log meson failed
125 fi
126}
127
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800128override_native_tools() {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400129 # Set these so that meson uses the native tools for its build sanity tests,
130 # which require executables to be runnable. The cross file will still
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800131 # override these for the target build.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400132 export CC="${BUILD_CC}"
133 export CXX="${BUILD_CXX}"
134 export LD="${BUILD_LD}"
135 export AR="${BUILD_AR}"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800136 # These contain *target* flags but will be used as *native* flags. The
137 # correct native flags will be passed via -Dc_args and so on, unset them so
138 # they don't interfere with tools invoked by Meson (such as g-ir-scanner)
139 unset CPPFLAGS CFLAGS CXXFLAGS LDFLAGS
140}
141
142meson_do_configure_prepend_class-target() {
143 override_native_tools
Brad Bishop316dfdd2018-06-25 12:45:53 -0400144}
145
146meson_do_configure_prepend_class-nativesdk() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800147 override_native_tools
Brad Bishop316dfdd2018-06-25 12:45:53 -0400148}
149
150meson_do_configure_prepend_class-native() {
151 export PKG_CONFIG="pkg-config-native"
152}
153
154do_compile[progress] = "outof:^\[(\d+)/(\d+)\]\s+"
155meson_do_compile() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800156 ninja -v ${PARALLEL_MAKE}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400157}
158
159meson_do_install() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800160 DESTDIR='${D}' ninja -v ${PARALLEL_MAKEINST} install
Brad Bishop316dfdd2018-06-25 12:45:53 -0400161}
162
163EXPORT_FUNCTIONS do_configure do_compile do_install