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 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 15 | MESON_BUILDTYPE ?= "plain" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 16 | MESONOPTS = " --prefix ${prefix} \ |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 17 | --buildtype ${MESON_BUILDTYPE} \ |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 18 | --bindir ${@noprefix('bindir', d)} \ |
| 19 | --sbindir ${@noprefix('sbindir', d)} \ |
| 20 | --datadir ${@noprefix('datadir', d)} \ |
| 21 | --libdir ${@noprefix('libdir', d)} \ |
| 22 | --libexecdir ${@noprefix('libexecdir', d)} \ |
| 23 | --includedir ${@noprefix('includedir', d)} \ |
| 24 | --mandir ${@noprefix('mandir', d)} \ |
| 25 | --infodir ${@noprefix('infodir', d)} \ |
| 26 | --sysconfdir ${sysconfdir} \ |
| 27 | --localstatedir ${localstatedir} \ |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 28 | --sharedstatedir ${sharedstatedir} \ |
| 29 | --wrap-mode nodownload" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 30 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 31 | EXTRA_OEMESON_append = " ${PACKAGECONFIG_CONFARGS}" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 32 | |
| 33 | MESON_CROSS_FILE = "" |
| 34 | MESON_CROSS_FILE_class-target = "--cross-file ${WORKDIR}/meson.cross" |
| 35 | MESON_CROSS_FILE_class-nativesdk = "--cross-file ${WORKDIR}/meson.cross" |
| 36 | |
| 37 | def meson_array(var, d): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 38 | items = d.getVar(var).split() |
| 39 | return repr(items[0] if len(items) == 1 else items) |
| 40 | |
| 41 | # Map our ARCH values to what Meson expects: |
| 42 | # http://mesonbuild.com/Reference-tables.html#cpu-families |
| 43 | def meson_cpu_family(var, d): |
| 44 | import re |
| 45 | arch = d.getVar(var) |
| 46 | if arch == 'powerpc': |
| 47 | return 'ppc' |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 48 | elif arch == 'powerpc64' or arch == 'powerpc64le': |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 49 | return 'ppc64' |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 50 | elif arch == 'armeb': |
| 51 | return 'arm' |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 52 | elif arch == 'aarch64_be': |
| 53 | return 'aarch64' |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 54 | elif arch == 'mipsel': |
| 55 | return 'mips' |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 56 | elif arch == 'mips64el': |
| 57 | return 'mips64' |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 58 | elif re.match(r"i[3-6]86", arch): |
| 59 | return "x86" |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 60 | elif arch == "microblazeel": |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 61 | return "microblaze" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 62 | else: |
| 63 | return arch |
| 64 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 65 | # Map our OS values to what Meson expects: |
| 66 | # https://mesonbuild.com/Reference-tables.html#operating-system-names |
| 67 | def meson_operating_system(var, d): |
| 68 | os = d.getVar(var) |
| 69 | if "mingw" in os: |
| 70 | return "windows" |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 71 | # avoid e.g 'linux-gnueabi' |
| 72 | elif "linux" in os: |
| 73 | return "linux" |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 74 | else: |
| 75 | return os |
| 76 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 77 | def meson_endian(prefix, d): |
| 78 | arch, os = d.getVar(prefix + "_ARCH"), d.getVar(prefix + "_OS") |
| 79 | sitedata = siteinfo_data_for_machine(arch, os, d) |
| 80 | if "endian-little" in sitedata: |
| 81 | return "little" |
| 82 | elif "endian-big" in sitedata: |
| 83 | return "big" |
| 84 | else: |
| 85 | bb.fatal("Cannot determine endianism for %s-%s" % (arch, os)) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 86 | |
| 87 | addtask write_config before do_configure |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 88 | 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] | 89 | do_write_config() { |
| 90 | # This needs to be Py to split the args into single-element lists |
| 91 | cat >${WORKDIR}/meson.cross <<EOF |
| 92 | [binaries] |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 93 | c = ${@meson_array('CC', d)} |
| 94 | cpp = ${@meson_array('CXX', d)} |
| 95 | ar = ${@meson_array('AR', d)} |
| 96 | nm = ${@meson_array('NM', d)} |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 97 | strip = ${@meson_array('STRIP', d)} |
| 98 | readelf = ${@meson_array('READELF', d)} |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 99 | pkgconfig = 'pkg-config' |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 100 | llvm-config = 'llvm-config${LLVMVERSION}' |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 101 | cups-config = 'cups-config' |
Andrew Geissler | 90fd73c | 2021-03-05 15:25:55 -0600 | [diff] [blame^] | 102 | g-ir-scanner = '${STAGING_BINDIR}/g-ir-scanner-wrapper' |
| 103 | g-ir-compiler = '${STAGING_BINDIR}/g-ir-compiler-wrapper' |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 104 | |
| 105 | [properties] |
| 106 | needs_exe_wrapper = true |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 107 | c_args = ${@meson_array('CFLAGS', d)} |
| 108 | c_link_args = ${@meson_array('LDFLAGS', d)} |
| 109 | cpp_args = ${@meson_array('CXXFLAGS', d)} |
| 110 | cpp_link_args = ${@meson_array('LDFLAGS', d)} |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 111 | gtkdoc_exe_wrapper = '${B}/gtkdoc-qemuwrapper' |
| 112 | |
| 113 | [host_machine] |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 114 | system = '${@meson_operating_system('HOST_OS', d)}' |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 115 | cpu_family = '${@meson_cpu_family('HOST_ARCH', d)}' |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 116 | cpu = '${HOST_ARCH}' |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 117 | endian = '${@meson_endian('HOST', d)}' |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 118 | |
| 119 | [target_machine] |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 120 | system = '${@meson_operating_system('TARGET_OS', d)}' |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 121 | cpu_family = '${@meson_cpu_family('TARGET_ARCH', d)}' |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 122 | cpu = '${TARGET_ARCH}' |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 123 | endian = '${@meson_endian('TARGET', d)}' |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 124 | EOF |
| 125 | } |
| 126 | |
| 127 | CONFIGURE_FILES = "meson.build" |
| 128 | |
| 129 | meson_do_configure() { |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 130 | # Meson requires this to be 'bfd, 'lld' or 'gold' from 0.53 onwards |
| 131 | # https://github.com/mesonbuild/meson/commit/ef9aeb188ea2bc7353e59916c18901cde90fa2b3 |
| 132 | unset LD |
| 133 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 134 | # Work around "Meson fails if /tmp is mounted with noexec #2972" |
| 135 | mkdir -p "${B}/meson-private/tmp" |
| 136 | export TMPDIR="${B}/meson-private/tmp" |
| 137 | bbnote Executing meson ${EXTRA_OEMESON}... |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 138 | if ! meson ${MESONOPTS} "${MESON_SOURCEPATH}" "${B}" ${MESON_CROSS_FILE} ${EXTRA_OEMESON}; then |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 139 | bbfatal_log meson failed |
| 140 | fi |
| 141 | } |
| 142 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 143 | override_native_tools() { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 144 | # Set these so that meson uses the native tools for its build sanity tests, |
| 145 | # which require executables to be runnable. The cross file will still |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 146 | # override these for the target build. |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 147 | export CC="${BUILD_CC}" |
| 148 | export CXX="${BUILD_CXX}" |
| 149 | export LD="${BUILD_LD}" |
| 150 | export AR="${BUILD_AR}" |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 151 | export STRIP="${BUILD_STRIP}" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 152 | # These contain *target* flags but will be used as *native* flags. The |
| 153 | # correct native flags will be passed via -Dc_args and so on, unset them so |
| 154 | # they don't interfere with tools invoked by Meson (such as g-ir-scanner) |
| 155 | unset CPPFLAGS CFLAGS CXXFLAGS LDFLAGS |
| 156 | } |
| 157 | |
| 158 | meson_do_configure_prepend_class-target() { |
| 159 | override_native_tools |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | meson_do_configure_prepend_class-nativesdk() { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 163 | override_native_tools |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | meson_do_configure_prepend_class-native() { |
| 167 | export PKG_CONFIG="pkg-config-native" |
| 168 | } |
| 169 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 170 | python meson_do_qa_configure() { |
| 171 | import re |
| 172 | warn_re = re.compile(r"^WARNING: Cross property (.+) is using default value (.+)$", re.MULTILINE) |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 173 | with open(d.expand("${B}/meson-logs/meson-log.txt")) as logfile: |
| 174 | log = logfile.read() |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 175 | for (prop, value) in warn_re.findall(log): |
| 176 | bb.warn("Meson cross property %s used without explicit assignment, defaulting to %s" % (prop, value)) |
| 177 | } |
| 178 | do_configure[postfuncs] += "meson_do_qa_configure" |
| 179 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 180 | do_compile[progress] = "outof:^\[(\d+)/(\d+)\]\s+" |
| 181 | meson_do_compile() { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 182 | ninja -v ${PARALLEL_MAKE} |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | meson_do_install() { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 186 | DESTDIR='${D}' ninja -v ${PARALLEL_MAKEINST} install |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | EXPORT_FUNCTIONS do_configure do_compile do_install |