blob: 7b77041c7e04a5df07f459246b7006821a09cdbf [file] [log] [blame]
Andrew Geisslereff27472021-10-29 15:35:00 -05001include meson.inc
2
3inherit meson-routines
4inherit nativesdk
5
6SRC_URI += "file://meson-setup.py \
7 file://meson-wrapper"
8
9# The cross file logic is similar but not identical to that in meson.bbclass,
10# since it's generating for an SDK rather than a cross-compile. Important
11# differences are:
12# - We can't set vars like CC, CXX, etc. yet because they will be filled in with
13# real paths by meson-setup.sh when the SDK is extracted.
14# - Some overrides aren't needed, since the SDK injects paths that take care of
15# them.
16def var_list2str(var, d):
17 items = d.getVar(var).split()
18 return items[0] if len(items) == 1 else ', '.join(repr(s) for s in items)
19
20def generate_native_link_template(d):
21 val = ['-L@{OECORE_NATIVE_SYSROOT}${libdir_native}',
22 '-L@{OECORE_NATIVE_SYSROOT}${base_libdir_native}',
23 '-Wl,-rpath-link,@{OECORE_NATIVE_SYSROOT}${libdir_native}',
24 '-Wl,-rpath-link,@{OECORE_NATIVE_SYSROOT}${base_libdir_native}',
25 '-Wl,--allow-shlib-undefined'
26 ]
27 build_arch = d.getVar('BUILD_ARCH')
28 if 'x86_64' in build_arch:
29 loader = 'ld-linux-x86-64.so.2'
30 elif 'i686' in build_arch:
31 loader = 'ld-linux.so.2'
32 elif 'aarch64' in build_arch:
33 loader = 'ld-linux-aarch64.so.1'
34 elif 'ppc64le' in build_arch:
35 loader = 'ld64.so.2'
36
37 if loader:
38 val += ['-Wl,--dynamic-linker=@{OECORE_NATIVE_SYSROOT}${base_libdir_native}/' + loader]
39
40 return repr(val)
41
42do_install:append() {
43 install -d ${D}${datadir}/meson
44
45 cat >${D}${datadir}/meson/meson.native.template <<EOF
46[binaries]
47c = ${@meson_array('BUILD_CC', d)}
48cpp = ${@meson_array('BUILD_CXX', d)}
49ar = ${@meson_array('BUILD_AR', d)}
50nm = ${@meson_array('BUILD_NM', d)}
51strip = ${@meson_array('BUILD_STRIP', d)}
52readelf = ${@meson_array('BUILD_READELF', d)}
53pkgconfig = 'pkg-config-native'
54
55[built-in options]
56c_args = ['-isystem@{OECORE_NATIVE_SYSROOT}${includedir_native}' , ${@var_list2str('BUILD_OPTIMIZATION', d)}]
57c_link_args = ${@generate_native_link_template(d)}
58cpp_args = ['-isystem@{OECORE_NATIVE_SYSROOT}${includedir_native}' , ${@var_list2str('BUILD_OPTIMIZATION', d)}]
59cpp_link_args = ${@generate_native_link_template(d)}
60[properties]
61sys_root = '@OECORE_NATIVE_SYSROOT'
62EOF
63
64 cat >${D}${datadir}/meson/meson.cross.template <<EOF
65[binaries]
66c = @CC
67cpp = @CXX
68ar = @AR
69nm = @NM
70strip = @STRIP
71pkgconfig = 'pkg-config'
72
73[built-in options]
74c_args = @CFLAGS
75c_link_args = @LDFLAGS
76cpp_args = @CPPFLAGS
77cpp_link_args = @LDFLAGS
78
79[properties]
80needs_exe_wrapper = true
81sys_root = @OECORE_TARGET_SYSROOT
82
83[host_machine]
84system = '${SDK_OS}'
85cpu_family = '${@meson_cpu_family("SDK_ARCH", d)}'
86cpu = '${SDK_ARCH}'
87endian = '${@meson_endian("SDK", d)}'
88EOF
89
90 install -d ${D}${SDKPATHNATIVE}/post-relocate-setup.d
91 install -m 0755 ${WORKDIR}/meson-setup.py ${D}${SDKPATHNATIVE}/post-relocate-setup.d/
92
93 # We need to wrap the real meson with a thin env setup wrapper.
94 mv ${D}${bindir}/meson ${D}${bindir}/meson.real
95 install -m 0755 ${WORKDIR}/meson-wrapper ${D}${bindir}/meson
96}
97
98RDEPENDS:${PN} += "\
99 nativesdk-ninja \
100 nativesdk-python3 \
101 nativesdk-python3-setuptools \
102 "
103
104FILES:${PN} += "${datadir}/meson ${SDKPATHNATIVE}"