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