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