| Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1 | inherit siteinfo python3native | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 2 |  | 
|  | 3 | DEPENDS_append = " meson-native ninja-native" | 
|  | 4 |  | 
|  | 5 | # As Meson enforces out-of-tree builds we can just use cleandirs | 
|  | 6 | B = "${WORKDIR}/build" | 
|  | 7 | do_configure[cleandirs] = "${B}" | 
|  | 8 |  | 
|  | 9 | # Where the meson.build build configuration is | 
|  | 10 | MESON_SOURCEPATH = "${S}" | 
|  | 11 |  | 
|  | 12 | def noprefix(var, d): | 
|  | 13 | return d.getVar(var).replace(d.getVar('prefix') + '/', '', 1) | 
|  | 14 |  | 
|  | 15 | MESONOPTS = " --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 Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 27 | --sharedstatedir ${sharedstatedir} " | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 28 |  | 
| Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 29 | EXTRA_OEMESON_append = " ${PACKAGECONFIG_CONFARGS}" | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 30 |  | 
|  | 31 | MESON_CROSS_FILE = "" | 
|  | 32 | MESON_CROSS_FILE_class-target = "--cross-file ${WORKDIR}/meson.cross" | 
|  | 33 | MESON_CROSS_FILE_class-nativesdk = "--cross-file ${WORKDIR}/meson.cross" | 
|  | 34 |  | 
|  | 35 | def meson_array(var, d): | 
| Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 36 | 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 | 
|  | 41 | def 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 Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 48 | elif arch == 'armeb': | 
|  | 49 | return 'arm' | 
| Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 50 | elif arch == 'aarch64_be': | 
|  | 51 | return 'aarch64' | 
| Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 52 | elif arch == 'mipsel': | 
|  | 53 | return 'mips' | 
| Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 54 | elif arch == 'mips64el': | 
|  | 55 | return 'mips64' | 
| Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 56 | elif re.match(r"i[3-6]86", arch): | 
|  | 57 | return "x86" | 
|  | 58 | else: | 
|  | 59 | return arch | 
|  | 60 |  | 
|  | 61 | def meson_endian(prefix, d): | 
|  | 62 | arch, os = d.getVar(prefix + "_ARCH"), d.getVar(prefix + "_OS") | 
|  | 63 | sitedata = siteinfo_data_for_machine(arch, os, d) | 
|  | 64 | if "endian-little" in sitedata: | 
|  | 65 | return "little" | 
|  | 66 | elif "endian-big" in sitedata: | 
|  | 67 | return "big" | 
|  | 68 | else: | 
|  | 69 | bb.fatal("Cannot determine endianism for %s-%s" % (arch, os)) | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 70 |  | 
|  | 71 | addtask write_config before do_configure | 
| Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 72 | do_write_config[vardeps] += "CC CXX LD AR NM STRIP READELF CFLAGS CXXFLAGS LDFLAGS" | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 73 | do_write_config() { | 
|  | 74 | # This needs to be Py to split the args into single-element lists | 
|  | 75 | cat >${WORKDIR}/meson.cross <<EOF | 
|  | 76 | [binaries] | 
| Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 77 | c = ${@meson_array('CC', d)} | 
|  | 78 | cpp = ${@meson_array('CXX', d)} | 
|  | 79 | ar = ${@meson_array('AR', d)} | 
|  | 80 | nm = ${@meson_array('NM', d)} | 
|  | 81 | ld = ${@meson_array('LD', d)} | 
|  | 82 | strip = ${@meson_array('STRIP', d)} | 
|  | 83 | readelf = ${@meson_array('READELF', d)} | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 84 | pkgconfig = 'pkg-config' | 
| Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 85 | llvm-config = 'llvm-config${LLVMVERSION}' | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 86 |  | 
|  | 87 | [properties] | 
|  | 88 | needs_exe_wrapper = true | 
| Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 89 | c_args = ${@meson_array('CFLAGS', d)} | 
|  | 90 | c_link_args = ${@meson_array('LDFLAGS', d)} | 
|  | 91 | cpp_args = ${@meson_array('CXXFLAGS', d)} | 
|  | 92 | cpp_link_args = ${@meson_array('LDFLAGS', d)} | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 93 | gtkdoc_exe_wrapper = '${B}/gtkdoc-qemuwrapper' | 
|  | 94 |  | 
|  | 95 | [host_machine] | 
|  | 96 | system = '${HOST_OS}' | 
| Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 97 | cpu_family = '${@meson_cpu_family('HOST_ARCH', d)}' | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 98 | cpu = '${HOST_ARCH}' | 
| Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 99 | endian = '${@meson_endian('HOST', d)}' | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 100 |  | 
|  | 101 | [target_machine] | 
|  | 102 | system = '${TARGET_OS}' | 
| Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 103 | cpu_family = '${@meson_cpu_family('TARGET_ARCH', d)}' | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 104 | cpu = '${TARGET_ARCH}' | 
| Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 105 | endian = '${@meson_endian('TARGET', d)}' | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 106 | EOF | 
|  | 107 | } | 
|  | 108 |  | 
|  | 109 | CONFIGURE_FILES = "meson.build" | 
|  | 110 |  | 
|  | 111 | meson_do_configure() { | 
| Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 112 | # Work around "Meson fails if /tmp is mounted with noexec #2972" | 
|  | 113 | mkdir -p "${B}/meson-private/tmp" | 
|  | 114 | export TMPDIR="${B}/meson-private/tmp" | 
|  | 115 | bbnote Executing meson ${EXTRA_OEMESON}... | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 116 | if ! meson ${MESONOPTS} "${MESON_SOURCEPATH}" "${B}" ${MESON_CROSS_FILE} ${EXTRA_OEMESON}; then | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 117 | bbfatal_log meson failed | 
|  | 118 | fi | 
|  | 119 | } | 
|  | 120 |  | 
| Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 121 | override_native_tools() { | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 122 | # Set these so that meson uses the native tools for its build sanity tests, | 
|  | 123 | # which require executables to be runnable. The cross file will still | 
| Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 124 | # override these for the target build. | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 125 | export CC="${BUILD_CC}" | 
|  | 126 | export CXX="${BUILD_CXX}" | 
|  | 127 | export LD="${BUILD_LD}" | 
|  | 128 | export AR="${BUILD_AR}" | 
| Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 129 | export STRIP="${BUILD_STRIP}" | 
| Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 130 | # These contain *target* flags but will be used as *native* flags.  The | 
|  | 131 | # correct native flags will be passed via -Dc_args and so on, unset them so | 
|  | 132 | # they don't interfere with tools invoked by Meson (such as g-ir-scanner) | 
|  | 133 | unset CPPFLAGS CFLAGS CXXFLAGS LDFLAGS | 
|  | 134 | } | 
|  | 135 |  | 
|  | 136 | meson_do_configure_prepend_class-target() { | 
|  | 137 | override_native_tools | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 138 | } | 
|  | 139 |  | 
|  | 140 | meson_do_configure_prepend_class-nativesdk() { | 
| Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 141 | override_native_tools | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 142 | } | 
|  | 143 |  | 
|  | 144 | meson_do_configure_prepend_class-native() { | 
|  | 145 | export PKG_CONFIG="pkg-config-native" | 
|  | 146 | } | 
|  | 147 |  | 
|  | 148 | do_compile[progress] = "outof:^\[(\d+)/(\d+)\]\s+" | 
|  | 149 | meson_do_compile() { | 
| Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 150 | ninja -v ${PARALLEL_MAKE} | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 151 | } | 
|  | 152 |  | 
|  | 153 | meson_do_install() { | 
| Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 154 | DESTDIR='${D}' ninja -v ${PARALLEL_MAKEINST} install | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 155 | } | 
|  | 156 |  | 
|  | 157 | EXPORT_FUNCTIONS do_configure do_compile do_install |