summaryrefslogtreecommitdiffstats
path: root/meta-oe/classes
diff options
context:
space:
mode:
authorLinus Svensson <linussn@axis.com>2017-02-16 12:53:59 +0100
committerMartin Jansa <Martin.Jansa@gmail.com>2017-02-20 11:50:12 +0100
commitc4445538f86929f2cb90f1c2fb42be1aa97911fc (patch)
tree617cd8ecf70227a7ee03980323edbded4dd5c94e /meta-oe/classes
parentb8f6712bd98569df432d4e8eeb34a4182902a5b5 (diff)
downloadmeta-openembedded-c4445538f86929f2cb90f1c2fb42be1aa97911fc.tar.gz
meson.bbclass: Add meson.bbclass
Add a class for packages that uses the meson build system. Meson uses a cross-file that contain needed tools and information about the host and target system. Such a file will be created in {WORKDIR}. Meson only allows installation directories to be specified as relative to prefix, except for sysconfdir, which can be absolute. This patch is based on a prototype patch by Ross Burton <ross.burton@intel.com>. Signed-off-by: Linus Svensson <linussn@axis.com> Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
Diffstat (limited to 'meta-oe/classes')
-rw-r--r--meta-oe/classes/meson.bbclass86
1 files changed, 86 insertions, 0 deletions
diff --git a/meta-oe/classes/meson.bbclass b/meta-oe/classes/meson.bbclass
new file mode 100644
index 000000000..5a04134f0
--- /dev/null
+++ b/meta-oe/classes/meson.bbclass
@@ -0,0 +1,86 @@
1inherit 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,
13# so they need to be unexported.
14CC[unexport] = "1"
15
16def noprefix(var, d):
17 return d.getVar(var, True).replace(d.getVar('prefix', True) + '/', '', 1)
18
19MESONOPTS = " --prefix ${prefix} \
20 --bindir ${@noprefix('bindir', d)} \
21 --datadir ${@noprefix('datadir', d)} \
22 --libdir ${@noprefix('libdir', d)} \
23 --libexecdir ${@noprefix('libexecdir', d)} \
24 --includedir ${@noprefix('includedir', d)} \
25 --mandir ${@noprefix('mandir', d)} \
26 --localedir ${@noprefix('localedir', d)} \
27 --sysconfdir ${sysconfdir}"
28
29MESON_C_ARGS = "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}"
30
31MESON_HOST_ENDIAN = "${@bb.utils.contains('SITEINFO_ENDIANNESS', 'be', 'big', 'little', d)}"
32MESON_TARGET_ENDIAN = "${@bb.utils.contains('TUNE_FEATURES', 'bigendian', 'big', 'little', d)}"
33
34EXTRA_OEMESON += "${PACKAGECONFIG_CONFARGS}"
35
36def meson_array(var, d):
37 return "', '".join(d.getVar(var, True).split()).join(("'", "'"))
38
39addtask write_config before do_configure
40do_write_config[vardeps] += "MESON_C_ARGS TOOLCHAIN_OPTIONS"
41do_write_config() {
42 # This needs to be Py to split the args into single-element lists
43 cat >${WORKDIR}/meson.cross <<EOF
44[binaries]
45c = '${HOST_PREFIX}gcc'
46cpp = '${HOST_PREFIX}gcc'
47ar = '${HOST_PREFIX}ar'
48ld = '${HOST_PREFIX}ld'
49strip = '${HOST_PREFIX}strip'
50readelf = '${HOST_PREFIX}readelf'
51pkgconfig = 'pkg-config'
52
53[properties]
54c_args = [${@meson_array('MESON_C_ARGS', d)}]
55c_link_args = [${@meson_array('TOOLCHAIN_OPTIONS', d)}]
56
57[host_machine]
58system = '${HOST_OS}'
59cpu_family = '${HOST_ARCH}'
60cpu = '${HOST_ARCH}'
61endian = '${MESON_HOST_ENDIAN}'
62
63[target_machine]
64system = '${TARGET_OS}'
65cpu_family = '${TARGET_ARCH}'
66cpu = '${TARGET_ARCH}'
67endian = '${MESON_TARGET_ENDIAN}'
68EOF
69}
70
71meson_do_configure() {
72 if ! meson ${MESONOPTS} "${MESON_SOURCEPATH}" "${B}" --cross-file ${WORKDIR}/meson.cross ${EXTRA_OEMESON}; then
73 cat ${B}/meson-logs/meson-log.txt
74 bbfatal_log meson failed
75 fi
76}
77
78meson_do_compile() {
79 ninja ${PARALLEL_MAKE}
80}
81
82meson_do_install() {
83 DESTDIR='${D}' ninja ${PARALLEL_MAKEINST} install
84}
85
86EXPORT_FUNCTIONS do_configure do_compile do_install