Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [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 | # These variables in the environment override the *native* tools, not the cross. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame^] | 13 | export CPPFLAGS = "${BUILD_CPPFLAGS}" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 14 | export CC = "${BUILD_CC}" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame^] | 15 | export CFLAGS = "${BUILD_CFLAGS}" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 16 | export CXX = "${BUILD_CXX}" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame^] | 17 | export CXXFLAGS = "${BUILD_CXXFLAGS}" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 18 | export LD = "${BUILD_LD}" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame^] | 19 | export LDFLAGS = "${BUILD_LDFLAGS}" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 20 | export AR = "${BUILD_AR}" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame^] | 21 | export PKG_CONFIG = "pkg-config-native" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 22 | |
| 23 | def noprefix(var, d): |
| 24 | return d.getVar(var, True).replace(d.getVar('prefix', True) + '/', '', 1) |
| 25 | |
| 26 | MESONOPTS = " --prefix ${prefix} \ |
| 27 | --bindir ${@noprefix('bindir', d)} \ |
| 28 | --sbindir ${@noprefix('sbindir', d)} \ |
| 29 | --datadir ${@noprefix('datadir', d)} \ |
| 30 | --libdir ${@noprefix('libdir', d)} \ |
| 31 | --libexecdir ${@noprefix('libexecdir', d)} \ |
| 32 | --includedir ${@noprefix('includedir', d)} \ |
| 33 | --mandir ${@noprefix('mandir', d)} \ |
| 34 | --infodir ${@noprefix('infodir', d)} \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 35 | --sysconfdir ${sysconfdir} \ |
| 36 | --localstatedir ${localstatedir} \ |
| 37 | --sharedstatedir ${sharedstatedir}" |
| 38 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame^] | 39 | MESON_C_ARGS = "${TARGET_CC_ARCH}${TOOLCHAIN_OPTIONS}" |
| 40 | MESON_LINK_ARGS = "${MESON_C_ARGS} ${LDFLAGS}" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 41 | |
| 42 | MESON_HOST_ENDIAN = "${@bb.utils.contains('SITEINFO_ENDIANNESS', 'be', 'big', 'little', d)}" |
| 43 | MESON_TARGET_ENDIAN = "${@bb.utils.contains('TUNE_FEATURES', 'bigendian', 'big', 'little', d)}" |
| 44 | |
| 45 | EXTRA_OEMESON += "${PACKAGECONFIG_CONFARGS}" |
| 46 | |
| 47 | MESON_CROSS_FILE = "" |
| 48 | MESON_CROSS_FILE_class-target = "--cross-file ${WORKDIR}/meson.cross" |
| 49 | |
| 50 | def meson_array(var, d): |
| 51 | return "', '".join(d.getVar(var, True).split()).join(("'", "'")) |
| 52 | |
| 53 | addtask write_config before do_configure |
| 54 | do_write_config[vardeps] += "MESON_C_ARGS TOOLCHAIN_OPTIONS" |
| 55 | do_write_config() { |
| 56 | # This needs to be Py to split the args into single-element lists |
| 57 | cat >${WORKDIR}/meson.cross <<EOF |
| 58 | [binaries] |
| 59 | c = '${HOST_PREFIX}gcc' |
| 60 | cpp = '${HOST_PREFIX}g++' |
| 61 | ar = '${HOST_PREFIX}ar' |
| 62 | ld = '${HOST_PREFIX}ld' |
| 63 | strip = '${HOST_PREFIX}strip' |
| 64 | readelf = '${HOST_PREFIX}readelf' |
| 65 | pkgconfig = 'pkg-config' |
| 66 | |
| 67 | [properties] |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame^] | 68 | needs_exe_wrapper = true |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 69 | c_args = [${@meson_array('MESON_C_ARGS', d)}] |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame^] | 70 | c_link_args = [${@meson_array('MESON_LINK_ARGS', d)}] |
| 71 | cpp_args = [${@meson_array('MESON_C_ARGS', d)}] |
| 72 | cpp_link_args = [${@meson_array('MESON_LINK_ARGS', d)}] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 73 | |
| 74 | [host_machine] |
| 75 | system = '${HOST_OS}' |
| 76 | cpu_family = '${HOST_ARCH}' |
| 77 | cpu = '${HOST_ARCH}' |
| 78 | endian = '${MESON_HOST_ENDIAN}' |
| 79 | |
| 80 | [target_machine] |
| 81 | system = '${TARGET_OS}' |
| 82 | cpu_family = '${TARGET_ARCH}' |
| 83 | cpu = '${TARGET_ARCH}' |
| 84 | endian = '${MESON_TARGET_ENDIAN}' |
| 85 | EOF |
| 86 | } |
| 87 | |
| 88 | CONFIGURE_FILES = "meson.build" |
| 89 | |
| 90 | meson_do_configure() { |
| 91 | if ! meson ${MESONOPTS} "${MESON_SOURCEPATH}" "${B}" ${MESON_CROSS_FILE} ${EXTRA_OEMESON}; then |
| 92 | cat ${B}/meson-logs/meson-log.txt |
| 93 | bbfatal_log meson failed |
| 94 | fi |
| 95 | } |
| 96 | |
| 97 | do_compile[progress] = "outof:^\[(\d+)/(\d+)\]\s+" |
| 98 | meson_do_compile() { |
| 99 | ninja ${PARALLEL_MAKE} |
| 100 | } |
| 101 | |
| 102 | meson_do_install() { |
| 103 | DESTDIR='${D}' ninja ${PARALLEL_MAKEINST} install |
| 104 | } |
| 105 | |
| 106 | EXPORT_FUNCTIONS do_configure do_compile do_install |