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