Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1 | inherit python3native |
| 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} \ |
| 27 | --sharedstatedir ${sharedstatedir}" |
| 28 | |
| 29 | MESON_TOOLCHAIN_ARGS = "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}" |
| 30 | MESON_C_ARGS = "${MESON_TOOLCHAIN_ARGS} ${CFLAGS}" |
| 31 | MESON_CPP_ARGS = "${MESON_TOOLCHAIN_ARGS} ${CXXFLAGS}" |
| 32 | MESON_LINK_ARGS = "${MESON_TOOLCHAIN_ARGS} ${LDFLAGS}" |
| 33 | |
| 34 | # both are required but not used by meson |
| 35 | MESON_HOST_ENDIAN = "bogus-endian" |
| 36 | MESON_TARGET_ENDIAN = "bogus-endian" |
| 37 | |
| 38 | EXTRA_OEMESON += "${PACKAGECONFIG_CONFARGS}" |
| 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): |
| 45 | return "', '".join(d.getVar(var).split()).join(("'", "'")) |
| 46 | |
| 47 | addtask write_config before do_configure |
| 48 | do_write_config[vardeps] += "MESON_C_ARGS MESON_CPP_ARGS MESON_LINK_ARGS CC CXX LD AR NM STRIP READELF" |
| 49 | do_write_config() { |
| 50 | # This needs to be Py to split the args into single-element lists |
| 51 | cat >${WORKDIR}/meson.cross <<EOF |
| 52 | [binaries] |
| 53 | c = [${@meson_array('CC', d)}] |
| 54 | cpp = [${@meson_array('CXX', d)}] |
| 55 | ar = [${@meson_array('AR', d)}] |
| 56 | nm = [${@meson_array('NM', d)}] |
| 57 | ld = [${@meson_array('LD', d)}] |
| 58 | strip = [${@meson_array('STRIP', d)}] |
| 59 | readelf = [${@meson_array('READELF', d)}] |
| 60 | pkgconfig = 'pkg-config' |
| 61 | |
| 62 | [properties] |
| 63 | needs_exe_wrapper = true |
| 64 | c_args = [${@meson_array('MESON_C_ARGS', d)}] |
| 65 | c_link_args = [${@meson_array('MESON_LINK_ARGS', d)}] |
| 66 | cpp_args = [${@meson_array('MESON_CPP_ARGS', d)}] |
| 67 | cpp_link_args = [${@meson_array('MESON_LINK_ARGS', d)}] |
| 68 | gtkdoc_exe_wrapper = '${B}/gtkdoc-qemuwrapper' |
| 69 | |
| 70 | [host_machine] |
| 71 | system = '${HOST_OS}' |
| 72 | cpu_family = '${HOST_ARCH}' |
| 73 | cpu = '${HOST_ARCH}' |
| 74 | endian = '${MESON_HOST_ENDIAN}' |
| 75 | |
| 76 | [target_machine] |
| 77 | system = '${TARGET_OS}' |
| 78 | cpu_family = '${TARGET_ARCH}' |
| 79 | cpu = '${TARGET_ARCH}' |
| 80 | endian = '${MESON_TARGET_ENDIAN}' |
| 81 | EOF |
| 82 | } |
| 83 | |
| 84 | CONFIGURE_FILES = "meson.build" |
| 85 | |
| 86 | meson_do_configure() { |
| 87 | if ! meson ${MESONOPTS} "${MESON_SOURCEPATH}" "${B}" ${MESON_CROSS_FILE} ${EXTRA_OEMESON}; then |
| 88 | cat ${B}/meson-logs/meson-log.txt |
| 89 | bbfatal_log meson failed |
| 90 | fi |
| 91 | } |
| 92 | |
| 93 | meson_do_configure_prepend_class-target() { |
| 94 | # Set these so that meson uses the native tools for its build sanity tests, |
| 95 | # which require executables to be runnable. The cross file will still |
| 96 | # override these for the target build. Note that we do *not* set CFLAGS, |
| 97 | # LDFLAGS, etc. as they will be slurped in by meson and applied to the |
| 98 | # target build, causing errors. |
| 99 | export CC="${BUILD_CC}" |
| 100 | export CXX="${BUILD_CXX}" |
| 101 | export LD="${BUILD_LD}" |
| 102 | export AR="${BUILD_AR}" |
| 103 | } |
| 104 | |
| 105 | meson_do_configure_prepend_class-nativesdk() { |
| 106 | # Set these so that meson uses the native tools for its build sanity tests, |
| 107 | # which require executables to be runnable. The cross file will still |
| 108 | # override these for the nativesdk build. Note that we do *not* set CFLAGS, |
| 109 | # LDFLAGS, etc. as they will be slurped in by meson and applied to the |
| 110 | # nativesdk build, causing errors. |
| 111 | export CC="${BUILD_CC}" |
| 112 | export CXX="${BUILD_CXX}" |
| 113 | export LD="${BUILD_LD}" |
| 114 | export AR="${BUILD_AR}" |
| 115 | } |
| 116 | |
| 117 | meson_do_configure_prepend_class-native() { |
| 118 | export PKG_CONFIG="pkg-config-native" |
| 119 | } |
| 120 | |
| 121 | do_compile[progress] = "outof:^\[(\d+)/(\d+)\]\s+" |
| 122 | meson_do_compile() { |
| 123 | ninja ${PARALLEL_MAKE} |
| 124 | } |
| 125 | |
| 126 | meson_do_install() { |
| 127 | DESTDIR='${D}' ninja ${PARALLEL_MAKEINST} install |
| 128 | } |
| 129 | |
| 130 | EXPORT_FUNCTIONS do_configure do_compile do_install |