blob: 2d7ee4fffc0490b96c77607859866ab3d7c46dbc [file] [log] [blame]
Brad Bishop316dfdd2018-06-25 12:45:53 -04001inherit 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
12def noprefix(var, d):
13 return d.getVar(var).replace(d.getVar('prefix') + '/', '', 1)
14
15MESONOPTS = " --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
29MESON_TOOLCHAIN_ARGS = "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}"
30MESON_C_ARGS = "${MESON_TOOLCHAIN_ARGS} ${CFLAGS}"
31MESON_CPP_ARGS = "${MESON_TOOLCHAIN_ARGS} ${CXXFLAGS}"
32MESON_LINK_ARGS = "${MESON_TOOLCHAIN_ARGS} ${LDFLAGS}"
33
34# both are required but not used by meson
35MESON_HOST_ENDIAN = "bogus-endian"
36MESON_TARGET_ENDIAN = "bogus-endian"
37
38EXTRA_OEMESON += "${PACKAGECONFIG_CONFARGS}"
39
40MESON_CROSS_FILE = ""
41MESON_CROSS_FILE_class-target = "--cross-file ${WORKDIR}/meson.cross"
42MESON_CROSS_FILE_class-nativesdk = "--cross-file ${WORKDIR}/meson.cross"
43
44def meson_array(var, d):
45 return "', '".join(d.getVar(var).split()).join(("'", "'"))
46
47addtask write_config before do_configure
48do_write_config[vardeps] += "MESON_C_ARGS MESON_CPP_ARGS MESON_LINK_ARGS CC CXX LD AR NM STRIP READELF"
49do_write_config() {
50 # This needs to be Py to split the args into single-element lists
51 cat >${WORKDIR}/meson.cross <<EOF
52[binaries]
53c = [${@meson_array('CC', d)}]
54cpp = [${@meson_array('CXX', d)}]
55ar = [${@meson_array('AR', d)}]
56nm = [${@meson_array('NM', d)}]
57ld = [${@meson_array('LD', d)}]
58strip = [${@meson_array('STRIP', d)}]
59readelf = [${@meson_array('READELF', d)}]
60pkgconfig = 'pkg-config'
61
62[properties]
63needs_exe_wrapper = true
64c_args = [${@meson_array('MESON_C_ARGS', d)}]
65c_link_args = [${@meson_array('MESON_LINK_ARGS', d)}]
66cpp_args = [${@meson_array('MESON_CPP_ARGS', d)}]
67cpp_link_args = [${@meson_array('MESON_LINK_ARGS', d)}]
68gtkdoc_exe_wrapper = '${B}/gtkdoc-qemuwrapper'
69
70[host_machine]
71system = '${HOST_OS}'
72cpu_family = '${HOST_ARCH}'
73cpu = '${HOST_ARCH}'
74endian = '${MESON_HOST_ENDIAN}'
75
76[target_machine]
77system = '${TARGET_OS}'
78cpu_family = '${TARGET_ARCH}'
79cpu = '${TARGET_ARCH}'
80endian = '${MESON_TARGET_ENDIAN}'
81EOF
82}
83
84CONFIGURE_FILES = "meson.build"
85
86meson_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
93meson_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
105meson_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
117meson_do_configure_prepend_class-native() {
118 export PKG_CONFIG="pkg-config-native"
119}
120
121do_compile[progress] = "outof:^\[(\d+)/(\d+)\]\s+"
122meson_do_compile() {
123 ninja ${PARALLEL_MAKE}
124}
125
126meson_do_install() {
127 DESTDIR='${D}' ninja ${PARALLEL_MAKEINST} install
128}
129
130EXPORT_FUNCTIONS do_configure do_compile do_install